Welcome to my Composite Design Pattern Tutorial! The Composite design pattern is used to structure data into its individual parts as well as represent the inner workings of every part of a larger object.
The composite pattern also allows you to treat both groups of parts in the same way as you treat the parts polymorphically. This allows your objects to maximize complexity while also remaining dynamic.
All of the code follows the video to help you learn. It is heavily commented.
If you think others would benefit from this video, it helps to tell Google with a click [googleplusone]
Share if you no others may like this [nttfblike]
Code from the Video
SONGCOMPONENT.JAVA
SONGGROUP.JAVA
SONG.JAVA
DISCJOCKEY.JAVA
SONGLISTGENERATOR.JAVA
This website rocks! There is so much good information here. Thanks for making JAVA easy to understand!
You’re very welcome π I do my best. Thank you for taking the time to tell me you liked it
thank you very much!
line 29 of SongListGenerator: industrialMusic.add(dubstepMusic);
should this read everySong.add(dubstepMusic);?
these are awesome – i dont know what i’d do without your videos
Thank you π No, industrialMusic.add(dubstepMusic) is correct. I may have confused you because I considered DubStep to be a version of industrial. That may not be true. I don’t know because I’m definitely not a music expert
Hi Derek
And thanks for the great tutorials
I have a Q: How come a βthrowsβ statement, is not required from methods of the abstract class SongComponent ?
You’re welcome π Yes, I should have caught that error. Sorry about that
Dude, I’m from Chile. You’re helping the entire world with your vids. How awesome is that?
Take care bro and thanks
Thank you very much π It is extremely gratifying to help and speak with people all over the world!
awsume tutorial man!! u rock thnk u very mch
Thank you π
Great stuff!
Thank you very much for these videos. I learn a lot.
Thank you very much π You’re welcome
This is awesome, great work you did with these tutorials π
Keep it on !
Thank you very much π
Great work !. Thank you very much for the tutorials π
learning a lot !.
You’re very welcome π I’m happy that you are enjoying them.
Great work! Thank you!
I know it can be many leaf classes, as long as they implement the same interface. What is not clear to me is if can it be many composite classes. It’s ok to have different ways of grouping composite/leaf objects? Can you think of an example? (I can’t π )
Hi Derek,
Really nice tutorial. This explains the Pattern and code so well. Thanks a lot!
Thanks & Regards,
Varun
Thank you π I’m happy I could help
I’m from Brasil and your video help me a lot in my work school. Thank you.
Thank you very much π I’m glad I could help
Hey Derek, first of all, thank you so much.
But, i’m a little bit confused with this pattern.
Can you create a UML Class Diagram with this example and with an UML Object Diagram? Cause I don’t know how to represents “Heavey Metal” “Industrial” and “Dubstep” in the diagram.
Thanks one more time!
π