-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hamed
committed
Jul 23, 2022
1 parent
b3d9ea5
commit fbdafe4
Showing
25 changed files
with
579 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
public interface IPerson | ||
{ | ||
string Name { get; set; } | ||
int Age { get; set; } | ||
void Print() | ||
{ | ||
Console.WriteLine($"{Name} {Age}"); | ||
} | ||
} | ||
|
||
public class Person : IPerson | ||
{ | ||
public string Name { get; set; } | ||
public int Age { get; set; } | ||
public void Print() | ||
{ | ||
Console.WriteLine("{0} - {1}", Name, Age); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type IPerson interface { | ||
print() | ||
} | ||
|
||
type Person struct { | ||
} | ||
|
||
func main() { | ||
var p IPerson | ||
p = Person{} | ||
p.print() | ||
print2(p) | ||
print2(12) | ||
print2("ali") | ||
} | ||
|
||
func (person Person) print() { | ||
println("Hello") | ||
} | ||
|
||
func print2(item interface{}) { | ||
fmt.Printf("%v\n",item) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
interface IPerson { | ||
name: string; | ||
age: number; | ||
print(); | ||
|
||
} | ||
|
||
class Person implements IPerson { | ||
name: string; | ||
age: number; | ||
print() { | ||
console.log(this.name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type Runner interface { | ||
Run() | ||
} | ||
|
||
type Walker interface { | ||
Walk() | ||
} | ||
|
||
type Shooter interface { | ||
Shoot() | ||
} | ||
|
||
type ShooterRunner interface { | ||
Runner | ||
Shooter | ||
} | ||
|
||
type Player struct { | ||
Name string | ||
Age int | ||
Height int | ||
Weight int | ||
Position string | ||
} | ||
|
||
func main() { | ||
|
||
player1 := &Player{ | ||
Name: "Alireza", | ||
Age: 30, | ||
Height: 180, | ||
Weight: 70, | ||
Position: "Forward", | ||
} | ||
|
||
var runner ShooterRunner = player1 | ||
|
||
var shooter ShooterRunner = player1 | ||
|
||
runner.Run() | ||
|
||
shooter.Shoot() | ||
} | ||
|
||
func (player *Player) Run() { | ||
fmt.Printf("name: %s, position: %s , Player is running\n",player.Name,player.Position) | ||
} | ||
func (player *Player) Shoot() { | ||
fmt.Printf("name: %s, position: %s , Player is shooting",player.Name,player.Position) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type Animal interface { | ||
Eat() | ||
Sleep() | ||
Walk() | ||
} | ||
|
||
type Human interface { | ||
Animal | ||
Speak() | ||
Think() | ||
} | ||
|
||
type Employee struct { | ||
Human | ||
Name string | ||
Age int | ||
} | ||
|
||
type Cat struct { | ||
Name string | ||
} | ||
|
||
func main() { | ||
employee := &Employee{Name: "Ali", Age: 30} | ||
cat := &Cat{Name: "Cat"} | ||
|
||
var human Human = employee | ||
var animal Animal = cat | ||
|
||
human.Eat() | ||
human.Sleep() | ||
human.Walk() | ||
human.Speak() | ||
human.Think() | ||
|
||
animal.Eat() | ||
animal.Sleep() | ||
animal.Walk() | ||
} | ||
|
||
func (cat *Cat) Eat() { | ||
fmt.Println("Cat is eating") | ||
} | ||
|
||
func (cat *Cat) Sleep() { | ||
fmt.Println("Cat is sleeping") | ||
} | ||
|
||
func (cat *Cat) Walk() { | ||
fmt.Println("Cat is walking") | ||
} | ||
|
||
func (employee *Employee) Speak() { | ||
fmt.Println("Employee is speaking") | ||
} | ||
|
||
func (employee *Employee) Think() { | ||
fmt.Println("Employee is thinking") | ||
} | ||
|
||
func (employee *Employee) Eat() { | ||
fmt.Println("Employee is eating") | ||
} | ||
|
||
func (employee *Employee) Sleep() { | ||
fmt.Println("Employee is sleeping") | ||
} | ||
|
||
func (employee *Employee) Walk() { | ||
fmt.Println("Employee is walking") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type Person struct { | ||
Name string | ||
} | ||
func main() { | ||
Print("Hello") | ||
Print(123) | ||
Print(true) | ||
Print([]int{1, 2, 3}) | ||
Print(map[string]int{"a": 1, "b": 2}) | ||
Print(Person{"Ali"}) | ||
} | ||
|
||
func AddOrder(order interface{}) interface{}{ | ||
|
||
if 1 == 2{ | ||
return 1 | ||
} | ||
|
||
if 1 == 3{ | ||
return "Cancel" | ||
} | ||
|
||
if 1 == 4{ | ||
return true | ||
} | ||
|
||
if 1 == 4{ | ||
return false | ||
} | ||
|
||
return "OK" | ||
} | ||
|
||
func Print(input interface{}) { | ||
switch input.(type) { | ||
case string: | ||
fmt.Println("String:", input) | ||
case int: | ||
fmt.Println("Integer:", input) | ||
case bool: | ||
fmt.Println("Boolean:", input) | ||
case []int: | ||
fmt.Println("Slice:", input) | ||
case map[string]int: | ||
fmt.Println("Map:", input) | ||
case Person: | ||
fmt.Println("Person:", input) | ||
} | ||
} | ||
|
||
|
||
// object |
8 changes: 8 additions & 0 deletions
8
10-Interfaces/06-MiniProject/01-Notification/entities/notificationType.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package entities | ||
|
||
type NotificationType string | ||
|
||
const ( | ||
Email NotificationType = "Email" | ||
Sms NotificationType = "Sms" | ||
) |
10 changes: 10 additions & 0 deletions
10
10-Interfaces/06-MiniProject/01-Notification/entities/order.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package entities | ||
|
||
type Order struct { | ||
ID int64 | ||
UserFullName string | ||
UserId string | ||
Price float64 | ||
Status bool | ||
NotificationType NotificationType | ||
} |
21 changes: 21 additions & 0 deletions
21
10-Interfaces/06-MiniProject/01-Notification/externalServices/emailService.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package externalServices | ||
|
||
import ( | ||
"fmt" | ||
"notification/entities" | ||
) | ||
|
||
type EmailService struct { | ||
} | ||
|
||
func (e *EmailService) SendMessage(order *entities.Order) { | ||
fmt.Printf("Email sent: %v\n", order) | ||
} | ||
|
||
func (e *EmailService) SendNotify(receiver string, message string) { | ||
fmt.Printf("Email sent: receiver: %s, message: %s\n", receiver, message) | ||
} | ||
|
||
func NewEmailService() *EmailService { | ||
return &EmailService{} | ||
} |
14 changes: 14 additions & 0 deletions
14
10-Interfaces/06-MiniProject/01-Notification/externalServices/nilNotifyService.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package externalServices | ||
|
||
import "fmt" | ||
|
||
type NilNotifyService struct { | ||
} | ||
|
||
func (e *NilNotifyService) SendNotify(receiver string, message string) { | ||
fmt.Printf("nilNotifyService: receiver: %s, message: %s\n", receiver, message) | ||
} | ||
|
||
func NewNilNotifyService() *NilNotifyService { | ||
return &NilNotifyService{} | ||
} |
18 changes: 18 additions & 0 deletions
18
10-Interfaces/06-MiniProject/01-Notification/externalServices/notifier.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package externalServices | ||
|
||
import "notification/entities" | ||
|
||
type Notifier interface { | ||
SendNotify(receiver string, message string) | ||
} | ||
|
||
func NewNotifier(notificationType entities.NotificationType) Notifier { | ||
switch notificationType { | ||
case entities.Sms: | ||
return NewSmsService() | ||
case entities.Email: | ||
return NewEmailService() | ||
default: | ||
return NewNilNotifyService() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
10-Interfaces/06-MiniProject/01-Notification/externalServices/smsService.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package externalServices | ||
|
||
import ( | ||
"fmt" | ||
"notification/entities" | ||
) | ||
|
||
type SmsService struct { | ||
} | ||
|
||
func (e *SmsService) SendMessage(order *entities.Order) { | ||
fmt.Printf("sms sent: %v\n", order) | ||
} | ||
|
||
func (e *SmsService) SendNotify(receiver string, message string) { | ||
fmt.Printf("sms sent: receiver: %s, message: %s\n", receiver, message) | ||
} | ||
|
||
func NewSmsService() *SmsService { | ||
return &SmsService{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module notification | ||
|
||
go 1.18 | ||
|
||
require github.com/naeemaei/golangTestMod v0.0.2 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/naeemaei/golangTestMod v0.0.2 h1:92cnJZKdQGaQeNdxbl1z73tTY2lunCqFMQLTKrv5eDk= | ||
github.com/naeemaei/golangTestMod v0.0.2/go.mod h1:nJJTUYiriqnqyOiC89eiyllcNpQ8pWf8dCiNeJQ4IUM= |
Oops, something went wrong.