No meu aprendizado de Golang, estou aproveitando estes desafios de Java para praticar os conceitos da linguagem Go que estou vendo. Assim ficou o codigo feito em Golang:
Go
Package notify
package notify
import "fmt"
type Notification interface {
Send()
}
type NotificationService struct {
Recipient string
Message string
}
type Email struct {
Subject string
NotificationService
}
func (e Email) Send() {
fmt.Printf("\nEnviando Email para: %s\nAssunto: %s\nCorpo: %s\n", e.Recipient, e.Subject, e.Message)
}
type SMS struct {
NotificationService
}
func (s SMS) Send() {
fmt.Printf("\nEnviando SMS para: %s\nMensagem: %s\n", s.Recipient, s.Message)
}
type Push struct {
Title string
NotificationService
}
func (p Push) Send() {
fmt.Printf("\nEnviando Push para: %s\nTítulo: %s\nConteúdo: %s\n", p.Recipient, p.Title, p.Message)
}
package main
package main
import (
"go-init/notify"
)
func main() {
email := notify.Email{Subject: "Video Game", NotificationService: notify.NotificationService{
Recipient: "Lucas Sousa",
Message: "Seus presente de aniversario",
}}
sms := notify.SMS{NotificationService: notify.NotificationService{
Recipient: "Lucas Sousa",
Message: "Recarregue agora mesmo o seu celular e concorra a premios exclusivos",
}}
push := notify.Push{Title: "Saidera", NotificationService: notify.NotificationService{
Recipient: "Lucas Sousa",
Message: "Bora jogar umas partidas de futebol",
}}
email.Send()
sms.Send()
push.Send()
}
como ficou: