diff --git a/Finished/Creational/Builder/builder.go b/Finished/Creational/Builder/builder.go index ff0278e..bdaefab 100644 --- a/Finished/Creational/Builder/builder.go +++ b/Finished/Creational/Builder/builder.go @@ -1,4 +1,5 @@ package main +import "fmt" // The NotificationBuilder has fields exported as well as a few methods // to demonstrate @@ -40,6 +41,13 @@ func (nb *NotificationBuilder) SetType(notType string) { } func (nb *NotificationBuilder) Build() (Notification, error) { + if nb.Icon != "" && nb.SubTitle == "" { + return nil, fmt.Errorf("You need to specify a subtitle when using an icon") + } + if nb.Priority > 5 { + return nil, fmt.Errorf("Priority must be 0 to 5") + } + return Notification{ title: nb.Title, message: nb.Message, diff --git a/Finished/Creational/Builder/example.go b/Finished/Creational/Builder/example.go index 8410af5..5f47dd4 100644 --- a/Finished/Creational/Builder/example.go +++ b/Finished/Creational/Builder/example.go @@ -5,9 +5,17 @@ import "fmt" func main() { var bldr = newNotificationBuilder() bldr.SetTitle("New Notification") - bldr.SetIcon("icon 1") + bldr.SetIcon("icon.png") + bldr.SetSubTitle("This is a subtitle") + bldr.SetImage("image.jpg") + bldr.SetPriority(5) bldr.SetMessage("This is a basic notification") + bldr.SetType("alert") notif, _ := bldr.Build() - fmt.Printf("Notification: %+v\n", notif) + if err != nil { + fmt.Println("Error creating the notification:", err) + } else { + fmt.Printf("Notification: %+v\n", notif) + } } diff --git a/Start/Structural/Adapter/sammysangAdapter.go b/Start/Structural/Adapter/sammysangAdapter.go index afa91b9..ae9b11a 100644 --- a/Start/Structural/Adapter/sammysangAdapter.go +++ b/Start/Structural/Adapter/sammysangAdapter.go @@ -2,48 +2,32 @@ package main type sammysangAdapter struct { // TODO: add a field for the SammysangTV reference - sstv *SammysangTV } func (ss *sammysangAdapter) turnOn() { // TODO - ss.sstv.setOnState(true) } func (ss *sammysangAdapter) turnOff() { // TODO - ss.sstv.setOnState(false) } func (ss *sammysangAdapter) volumeUp() int { // TODO - vol := ss.sstv.getVolume() + 1 - ss.sstv.setVolume(vol) - return vol } func (ss *sammysangAdapter) volumeDown() int { // TODO - vol := ss.sstv.getVolume() - 1 - ss.sstv.setVolume(vol) - return vol } func (ss *sammysangAdapter) channelUp() int { // TODO - ch := ss.sstv.getChannel() + 1 - ss.sstv.setChannel(ch) - return ch } func (ss *sammysangAdapter) channelDown() int { // TODO - ch := ss.sstv.getChannel() - 1 - ss.sstv.setChannel(ch) - return ch } func (ss *sammysangAdapter) goToChannel(ch int) { // TODO - ss.sstv.setChannel(ch) }