package main
import
"fmt"
type UserService
interface
{
Register(username string, password string) error
GetUser(username string) (string, error)
}
type PostService
interface
{
Publish(username string, content string) error
}
type NotificationService
interface
{
SendNotification(username string, message string) error
}
type UserServiceImpl struct{}
func (userService *UserServiceImpl) Register(username string, password string) error {
fmt.Println(
"User registered:"
, username)
return
nil
}
func (userService *UserServiceImpl) GetUser(username string) (string, error) {
fmt.Println(
"Getting user:"
, username)
return
"User Information"
, nil
}
type PostServiceImpl struct {
userService UserService
}
func (postService *PostServiceImpl) Publish(username string, content string) error {
_, err := postService.userService.GetUser(username)
if
err != nil {
return
err
}
fmt.Println(
"Publishing post for user:"
, username)
return
nil
}
type NotificationServiceImpl struct {
userService UserService
}
func (notificationService *NotificationServiceImpl) SendNotification(username string, message string) error {
_, err := notificationService.userService.GetUser(username)
if
err != nil {
return
err
}
fmt.Println(
"Sending notification to user:"
, username)
return
nil
}
type Facade
interface
{
RegisterUser(username string, password string) error
PublishPost(username string, content string) error
SendNotification(username string, message string) error
}
type FacadeImpl struct {
userService UserService
postService PostService
notificationService NotificationService
}
func (facade *FacadeImpl) RegisterUser(username string, password string) error {
return
facade.userService.Register(username, password)
}
func (facade *FacadeImpl) PublishPost(username string, content string) error {
return
facade.postService.Publish(username, content)
}
func (facade *FacadeImpl) SendNotification(username string, message string) error {
return
facade.notificationService.SendNotification(username, message)
}
func main() {
facade := &FacadeImpl{
userService: &UserServiceImpl{},
postService: &PostServiceImpl{userService: &UserServiceImpl{}},
notificationService: &NotificationServiceImpl{userService: &UserServiceImpl{}},
}
facade.RegisterUser(
"Alice"
,
"123456"
)
facade.PublishPost(
"Alice"
,
"Hello world"
)
facade.SendNotification(
"Alice"
,
"Welcome to our platform"
)
}