From the course: Java Design Patterns: Structural

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understand the Composite pattern

Understand the Composite pattern - Java Tutorial

From the course: Java Design Patterns: Structural

Start my 1-month free trial

Understand the Composite pattern

- [Instructor] Imagine a quiz night where people can choose to enter the quiz on their own. The person running the quiz has a list of all the people answering the quiz, but then some groups of people might want to enter as teams. The person running the quiz will treat the group of people as one entry, the same as the people entering on their own. In the context of the composite pattern, the group of people would be a composite that can be treated in the same way as an individual person answering. In Java, you've probably come across the concepts of Varargs. These are methods that take an argument, and the type of argument is followed by three dots. This notation means that when you call this method, you can pass in one variable, two variables, or however many variables you like. So in a typical Java app, a good place to use the composite pattern is where you want to treat single objects and groups of objects in the…

Contents