This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type decreaseVolumeCommand struct { | |
device device | |
} | |
func (c *decreaseVolumeCommand) execute() { | |
c.device.decreaseVolume() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type tv struct { | |
isOn bool | |
volume int | |
} | |
func (t *tv) on() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main() { | |
tv := &tv { | |
isOn: false, | |
volume: 10, | |
} | |
// Instantiate commands | |
onCommand := &onCommand{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Observer interface { | |
Update(value int) | |
} | |
func createWeatherStation(name string) *WeatherStation{ | |
return &WeatherStation{Name:name} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
) | |
const ( | |
maxTemperature = 120 | |
minTemperature = -30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func main(){ | |
// Initialise our sensors and stations | |
coSensor := createWeatherSensor() | |
wySensor:= createWeatherSensor() | |
denverStation := createWeatherStation("Denver Weather Station") | |
vailStation := createWeatherStation("Vail Weather Station") | |
cheyenneStation := createWeatherStation("Cheyenne Weather Station") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type pizza interface { | |
getPrice() float64 | |
getCalories() int | |
} | |
type cheesePizza struct { | |
calories int | |
price float64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
const ( | |
pepperoniPrice = 1.75 | |
artichokePrice = 2.00 | |
anchoviePrice = 2.50 | |
tomatoePrice = 0.75 | |
pepperoniCalories = 200 | |
artichokeCalories = 150 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
theBombPizza := &anchovieTopping{ | |
pizza: &artichokeTopping{ | |
pizza: &tomatoeTopping{ | |
pizza: newCheesePizza(), |