-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorymethod.go
More file actions
40 lines (30 loc) · 796 Bytes
/
Copy pathfactorymethod.go
File metadata and controls
40 lines (30 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package factorymethod
import (
"fmt"
"log"
"github.com/IvanProg00/go-patterns/factory_method/computer"
)
func Run() {
laptop, err := computer.Get(computer.LaptopType)
if err != nil {
log.Fatalf("new laptop: %v", err)
}
printComputer(laptop)
server, err := computer.Get(computer.ServerType)
if err != nil {
log.Fatalf("new server: %v", err)
}
printComputer(server)
pc, err := computer.Get(computer.PersonalComputerType)
if err != nil {
log.Fatalf("new personal computer: %v", err)
}
printComputer(pc)
_, err = computer.Get("undefined computer")
if err != nil {
fmt.Printf("ERROR: new undefined computer: %v\n", err)
}
}
func printComputer(comp computer.Computer) {
fmt.Printf("type: [%s]; cpu: [%d]; os: [%s]\n", comp.GetType(), comp.GetCPU(), comp.GetOS())
}