From the course: Complete Guide to Java Design Patterns: Creational, Behavioral, and Structural
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Challenge: the Composite pattern - Java Tutorial
From the course: Complete Guide to Java Design Patterns: Creational, Behavioral, and Structural
Challenge: the Composite pattern
In this challenge, you'll need to implement the composite pattern for an app for playing the notes of a song. The songs are composites made up of musical note objects. So to explain how this app works, first there's a class called Notes, which takes a char as an argument in the constructor, and this is the value of the notes. Then there's also a method called play, which prints out the value of that note. And then there's a class called Song, which contains a list of notes. And there's a method called addNote, which adds a note to the list. And then there's a method called getNotes, which returns the list of notes. Finally, there's the App class, and this has a main method in it. So at the top of this method, all the possible notes are added from A to G. And then there's a new song variable, which is a song called doReMe. Then all the notes for the song are added using the addNote method. Then to play the song, at the moment, we have to get each note individually and call the play…
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
(Locked)
Understand abstract factories3m 7s
-
(Locked)
Recognize where to use abstract factories3m 53s
-
(Locked)
Create factories for families of objects6m 4s
-
(Locked)
Implement the complete Abstract Factory pattern6m 1s
-
(Locked)
Challenge: The Abstract Factory pattern1m 36s
-
(Locked)
Solution: The Abstract Factory pattern2m 34s
-
(Locked)
-
-
(Locked)
Understand the Chain of Responsibility pattern1m 23s
-
(Locked)
Recognize where to use the Chain of Responsibility pattern2m 35s
-
(Locked)
Implement a successor chain4m 49s
-
(Locked)
Challenge: The Chain of Responsibility pattern1m 48s
-
(Locked)
Solution: The Chain of Responsibility pattern3m 59s
-
(Locked)