Skip to content

Commit

Permalink
Fix start and end state examples
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarini committed Jul 27, 2021
1 parent 9992c58 commit 6df65bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
8 changes: 8 additions & 0 deletions Finished/Creational/Builder/builder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package main
import "fmt"

// The NotificationBuilder has fields exported as well as a few methods
// to demonstrate
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions Finished/Creational/Builder/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
16 changes: 0 additions & 16 deletions Start/Structural/Adapter/sammysangAdapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 6df65bf

Please sign in to comment.