|
1 | 1 | package behavioral |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | +) |
| 6 | + |
| 7 | +// WorkerInterface defines an interface for a worker. |
| 8 | +type WorkerInterface interface { |
| 9 | + GetUp() |
| 10 | + EatBreakfast() |
| 11 | + GoToWork() |
| 12 | + Work() |
| 13 | + ReturnHome() |
| 14 | + Relax() |
| 15 | + Sleep() |
| 16 | +} |
| 17 | + |
| 18 | +// Worker defines the worker. |
| 19 | +type Worker struct { |
| 20 | + WorkerInterface |
| 21 | +} |
| 22 | + |
| 23 | +// NewWorker returns a new Worker. |
| 24 | +func NewWorker(w WorkerInterface) *Worker { |
| 25 | + return &Worker{w} |
| 26 | +} |
| 27 | + |
| 28 | +// DailyRoutine is the template method for printing the workers daily routine. |
| 29 | +func (w *Worker) DailyRoutine() { |
| 30 | + w.GetUp() |
| 31 | + w.EatBreakfast() |
| 32 | + w.GoToWork() |
| 33 | + w.Work() |
| 34 | + w.ReturnHome() |
| 35 | + w.Relax() |
| 36 | + w.Sleep() |
| 37 | +} |
| 38 | + |
| 39 | +// PostMan is a worker. |
| 40 | +type PostMan struct { |
| 41 | +} |
| 42 | + |
| 43 | +// GetUp prints what the postman does to get up. |
| 44 | +func (w *PostMan) GetUp() { |
| 45 | + fmt.Fprintf(outputWriter, "Getting up\n") |
| 46 | +} |
| 47 | + |
| 48 | +// EatBreakfast prints what the postman does to eat breakfast. |
| 49 | +func (w *PostMan) EatBreakfast() { |
| 50 | + fmt.Fprintf(outputWriter, "Eating pop tarts\n") |
| 51 | +} |
| 52 | + |
| 53 | +// GoToWork prints what the postman does to get to work. |
| 54 | +func (w *PostMan) GoToWork() { |
| 55 | + fmt.Fprintf(outputWriter, "Cycle to work\n") |
| 56 | +} |
| 57 | + |
| 58 | +// Work prints what the postman does to work. |
| 59 | +func (w *PostMan) Work() { |
| 60 | + fmt.Fprintf(outputWriter, "Post letters\n") |
| 61 | +} |
| 62 | + |
| 63 | +// ReturnHome prints what the postman does to get home. |
| 64 | +func (w *PostMan) ReturnHome() { |
| 65 | + fmt.Fprintf(outputWriter, "Cycle home\n") |
| 66 | +} |
| 67 | + |
| 68 | +// Relax prints what the postman does to relax. |
| 69 | +func (w *PostMan) Relax() { |
| 70 | + fmt.Fprintf(outputWriter, "Collect stamps\n") |
| 71 | +} |
| 72 | + |
| 73 | +// Sleep prints what the postman does to sleep. |
| 74 | +func (w *PostMan) Sleep() { |
| 75 | + fmt.Fprintf(outputWriter, "Zzzzzzz\n") |
| 76 | +} |
0 commit comments