From the course: Design Patterns in Go for Object Oriented Programming
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Implement a Composite pattern - Go Tutorial
From the course: Design Patterns in Go for Object Oriented Programming
Implement a Composite pattern
- [Instructor] Now we're going to implement the composite interface in Go using a sports team example. I've pre-written our component interface leaf and composite classes, which we'll talk. I've pre-written our component interface leaf and composite classes, which we'll talk through. And together we're going to write our client in our main function. First we have our component interface, which in this example is named Member, and it contains the function printMemberInfo. Then we have our leaf object, which implements the Member interface with the name TeamMember and position as parameters. And then we have our printMemberInfo method, which is a print statement that writes all of the details of a team member. Now we have our composite, which is our roster in this example, which passes in an array of members as well as the name of the roster, which is a string. And we'll also implement the printMemberInfo method that is…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
What are structural patterns?54s
-
(Locked)
Adapter pattern2m 6s
-
(Locked)
Implement an Adapter pattern2m 50s
-
(Locked)
Composite pattern1m 51s
-
(Locked)
Implement a Composite pattern4m 10s
-
(Locked)
Decorator pattern2m 12s
-
(Locked)
Implement a Decorator pattern3m 32s
-
(Locked)
Facade pattern1m 49s
-
(Locked)
Implement a Facade pattern4m 25s
-
-
-