-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (32 loc) · 1.1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"fmt"
"solid/domain/document"
"solid/domain/user"
)
func main() {
// SRP Example
userRepository := &user.MongoDBRepository{}
userService := user.UserRegistrationService{Repo: userRepository}
err := userService.Register("john_doe", "john@example.com")
if err != nil {
fmt.Println("Error:", err)
}
// OCP Example
emailNotifier := user.EmailNotifier{EmailRecipient: "admin@example.com"}
smsNotifier := user.SMSNotifier{PhoneNumber: "+1234567890"}
// LSP Example
notifyingUserServiceEmail := user.NotifyingUserService{
UserRegistrationService: userService,
Notifier: emailNotifier,
}
notifyingUserServiceSMS := user.NotifyingUserService{
UserRegistrationService: userService,
Notifier: smsNotifier,
}
notifyingUserServiceEmail.RegisterAndNotify("alice_doe", "alice@example.com", "Welcome, Alice!")
notifyingUserServiceSMS.RegisterAndNotify("bob_doe", "bob@example.com", "Welcome, Bob!")
reader := document.TextDocument{}
// Client interacts with specific interfaces, avoiding unnecessary methods.
document.ClientViewEvidence(reader)
}