LEFT | RIGHT |
(Both sides are equal) |
1 // Package runner provides a Runner type that is used to define both RunCounter | 1 // Package runner provides a Runner type that is used to define both RunCounter |
2 // and EmbeddedRunCounter to show examples of how to use composition in Go. | 2 // and EmbeddedRunCounter to show examples of how to use composition in Go. |
3 package runner | 3 package runner |
4 | 4 |
5 import "fmt" | 5 import "fmt" |
6 | 6 |
7 // A Task is a simple task that prints a message when run. | 7 // A Task is a simple task that prints a message when run. |
8 type Task struct{ Msg string } | 8 type Task struct{ Msg string } |
9 | 9 |
10 func (t Task) Run() { | 10 func (t Task) Run() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 | 47 |
48 func (r *RunCounter) RunAll(ts []Task) { | 48 func (r *RunCounter) RunAll(ts []Task) { |
49 r.count += len(ts) | 49 r.count += len(ts) |
50 r.runner.RunAll(ts) // HL | 50 r.runner.RunAll(ts) // HL |
51 } | 51 } |
52 | 52 |
53 func (r *RunCounter) Count() int { return r.count } | 53 func (r *RunCounter) Count() int { return r.count } |
54 | 54 |
55 func (r *RunCounter) Name() string { return r.runner.Name() } | 55 func (r *RunCounter) Name() string { return r.runner.Name() } |
LEFT | RIGHT |