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

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…

Contents