Composite Design Pattern

Поділитися
Вставка
  • Опубліковано 20 гру 2024

КОМЕНТАРІ • 244

  • @Krazness
    @Krazness 5 років тому +25

    Been watching your videos since I was a student, and years later as an engineer they're still relevant and excellent resource material. Thank you for all the work you've done, the community is forever grateful

    • @derekbanas
      @derekbanas  5 років тому +5

      It is great to know I've been able to help for so long :) I wish you all the best

  • @derekbanas
    @derekbanas  11 років тому +2

    Thank you :) I'm mainly teaching topics that I guess are so complex that very few people are interested in them. I'm extremely happy with my community. So many people that I meet online are great friends that I wish I could meet in the real world. It is very gratifying for me to be able to help so many nice people!

  • @mohmaaya8312
    @mohmaaya8312 Рік тому +1

    Watching in 2023. Immortal content on design patterns.

  • @majksu
    @majksu 2 роки тому

    From your tutorials on python and java to developing candy crush as an intern and later when I'll manage good with my tasks I'm going to get a junior software engineer position. I just want to say thank you!

    • @derekbanas
      @derekbanas  2 роки тому

      That's Awesome!!! Congratulations on all you accomplished!!!

  • @Robinhopok
    @Robinhopok 11 років тому +3

    I really love your tutorials, really helps me out with my Desin Pattern exams.
    Sooo much better than all the useless PowerPoints my school is giving me.
    Keep up the good work!!

  • @danielmelchior
    @danielmelchior 10 років тому +1

    If you aren't a CS instructor, you should be! I learn more from a few hours watching your videos than my professors can teach in weeks! Your explanations are top notch, keep up the great work.

    • @derekbanas
      @derekbanas  10 років тому +1

      Thank you very much for the compliment :) I'm not an instructor aside from what I do on UA-cam though.

  • @derekbanas
    @derekbanas  11 років тому +1

    You can use method overloading with any method. Just make sure that you use arguments with data types in different orders to get it to work

  • @mywetaresocks_8959
    @mywetaresocks_8959 5 років тому

    Dude, you're maybe never gonna see this, but thanks a lot for all your design patterns video, I was struggling to understand in college, and my finals are near, this is a big help, much appreciation.

    • @derekbanas
      @derekbanas  5 років тому

      Thank you for taking the time to tell me I helped :) Best of luck on your finals

  • @derekbanas
    @derekbanas  12 років тому +1

    You guys determine what I do for the most part. I created Asteroids in parts 50 thru 60 in my Java video tutorial. It covers so many things like collision detection, a lot of physics based stuff like lifelike shooting, flying, etc. Have you seen that? When I start making games I'll start with a simple platformer and move up from there. What type of game do you want to see?

  • @derekbanas
    @derekbanas  12 років тому

    Yes Java, C++ and C# are OOP languages. It won't take that long to learn if you do a little every day and make fun projects. I've known people to learn just about everything in 2 months. They still have to use copy and paste code all of the time, but they know how to use Java pretty well

  • @yukimushu
    @yukimushu 10 років тому

    Another great video! Your videos have been a massive help to me over the past few months so I've donated a few quid via your website just to show my appreciation.

    • @derekbanas
      @derekbanas  10 років тому

      Thank you very much :) I'm happy that I was able to help and please don't feel the need to donate.

  • @LariviereChris
    @LariviereChris 9 років тому

    Mind has been blown with the simpleness you provide. Thank you

    • @derekbanas
      @derekbanas  9 років тому

      Christopher Lariviere Thank you :) I'm happy I could help

  • @derekbanas
    @derekbanas  12 років тому

    Yes I've seen it. I'll eventually cover frameworks and social networks when I get back into PHP. I know I need to improve on that tutorial. Thanks for the request

  • @AndrewPalmerJazz
    @AndrewPalmerJazz 9 років тому +34

    This version of the pattern is NOT CORRECT. Every method for all classes is crammed into one abstract class where the default implementation is to throw exceptions. This is a very obvious violation of the Interface Segregation Principle, and a good demonstration of an ANTI-PATTERN.
    Just define methods where they are supposed to go. SongGroup should have add() and remove(). Song should have getSongName() and getBandName(). An interface or abstract class is needed for the pattern to work, but it should only have the methods that are common to composite objects (SongGroups) and leaf objects (Songs). In this case, that would be one method: displaySongInfo(). Other sources on UA-cam and the internet will demonstrate the pattern correctly.

    • @stefanosperos353
      @stefanosperos353 9 років тому +2

      +Andrew Palmer It is clearly stated in the Design Patterns book that implementing the child management operations in the component instead of in the composite (like Derek did here) is favoring transparency over safety. By default you have the child management operations fail, so that you can catch exceptions when they are called on leaves, (usually indicates a bug anyway), and you override them in the component to actually do what they should do. That way they both composite and leaves appear to have the same interface to the client. If you want to go for safety, sure, do what you said, but don't say that this implementation is actually an ANTI-PATTERN because it's really one of the default ways of implementing this pattern.
      For more info, see www.google.be/imgres?imgurl=t0.gstatic.com/images%3Fq%3Dtbn:ANd9GcQYYgj_qlNHWQecLsaHLSQxzb4Cgkh1JjsJAAGlFyh1gtkVnK0J&imgrefurl=books.google.com/books/about/Design_Patterns.html?id%3D6oHuKQe3TjQC%26source%3Dkp_cover&h=800&w=600&tbnid=uGBuMT7EpSNMtM:&tbnh=160&tbnw=119&docid=I8O6u1SkhQlJ1M&itg=1&usg=__XhfV5M9JAwk1Efwq-JH04_BGshY=

    • @AndrewPalmerJazz
      @AndrewPalmerJazz 9 років тому +1

      +Steve Peros I've heard this argument before, but this so-called "transparency" is not a virtue. "Transparency," in this context, means the same thing as "breaking the type system to no benefit." Clients should not look at two objects the same way if they do not support the same operations. Run-time exception handling is not preferable to compile-time checking, which is why I call this implementation an anti-pattern. If you use the pattern correctly (i.e. the SOLID version of the pattern), your code will just fail to compile if you try to call an invalid method, and run-time exception handling is unnecessary.
      This is one of the key advantages of using languages with static type systems. There is no reason not to let the type system do its job. If you feel like Java's type system just gets in your way, you can go look for a video on Python or Ruby (great languages)!

    • @stefanosperos353
      @stefanosperos353 9 років тому

      +Andrew Palmer According to you, using this pattern correctly is only implementing the child management operations in the composite then? And you consider type casting to be a better alternative then when a client is working with a component object and wants to access child management methods?
      I'm familiar with other languages, but considering this video is a JAVA implementation, I keep my point restricted to JAVA.

    • @AndrewPalmerJazz
      @AndrewPalmerJazz 9 років тому +1

      +Steve Peros Steve, you have to type-check anyway. Type-checking is preferable to throwing and catching exceptions.

    • @NachiketJoshiTheBloodMage
      @NachiketJoshiTheBloodMage 8 років тому +3

      this is a nice thread...I saw this video just now and debated this same topic with my friend...

  • @memoocv
    @memoocv 11 років тому

    Dude, you are awesome, I have an exam tomorrow and this thing is just blowing my brain. BTW, Centipede song is awesome.
    Thanks!

  • @mohamedguebli2522
    @mohamedguebli2522 8 років тому +1

    I was little bit confused when i saw other implementations of this pattern, but with your implementation about the GROUPs and SONGs it was so easy to understand!! Thank you so much :)

    • @derekbanas
      @derekbanas  8 років тому

      I'm happy I could help :)

  • @derekbanas
    @derekbanas  11 років тому

    Thank you very much :) I'm very happy that you enjoy them. Always feel free to ask questions. I'm not that popular so I always answer all my comments

  • @youpwnt
    @youpwnt 11 років тому +1

    You really deserve a lot more views and subscribers! Most design patterns are very hard for me to understand - not how they are created, but for what kind of problems they can be used - and you are explaining these things really easily using simple examples. Very nice! Please go on with that great work! Suscribed.

  • @Bubico000
    @Bubico000 10 років тому

    Best Java tutorials on the internet . Thank you !!!

  • @reachtrevor
    @reachtrevor 5 років тому

    Brilliant humor, I was laughing most of the video because I talk to my code almost identically. Tutorial was great, looking forward to trying it out,

    • @derekbanas
      @derekbanas  5 років тому

      I'm very happy that you enjoyed it :)

  • @pradeepyogesh4481
    @pradeepyogesh4481 8 років тому +5

    U r Awesome dude. It just takes 20 minutes to understand each of ur videos :-).
    That really made easy for me :-). Thank u very much.

    • @derekbanas
      @derekbanas  8 років тому +3

      Thank you :) I'm very happy that you like them.

  • @P4uL0x
    @P4uL0x 12 років тому

    wow man, thanks! it's really nice to see ppl like you that take the time to do this kind of stuff. (sorry for the bad english)

  • @derekbanas
    @derekbanas  11 років тому +2

    Thank you very much :) I'm very happy that I was able to help. Good luck on your exam!

  • @derekbanas
    @derekbanas  12 років тому

    Working with design patterns is all about cool tricks :)

  • @derekbanas
    @derekbanas  12 років тому

    PHP isn't an oop language. What I'm covering now is about as complicated as programming gets. C is a low level language that is pretty easy once you understand memory management. C++ is easy after you understand oop. PHP is just a toy in comparison. Start to learn Java and OOD and you'll quickly see the difference

  • @shokuninkatsuya9627
    @shokuninkatsuya9627 8 років тому +2

    I think modeling files and directories as a composite pattern example of might be more clear than songs and song groups.
    Also, should use generics to eliminate casting.

  • @SercanSavranOfficial
    @SercanSavranOfficial 5 років тому

    Duude... BREATH! :D
    I'd watched a couple of your tutorials the last days. Explanation is good but the emphasizing... It feels like listening to an auctioneer :D

  • @derekbanas
    @derekbanas  11 років тому +1

    You're very welcome :) I'm glad you enjoyed it

  • @derekbanas
    @derekbanas  12 років тому

    You're very welcome :) I'm glad it helped explain a topic that many find complicated

  • @derekbanas
    @derekbanas  11 років тому

    SongComponent songList is an example of composition for the DiskJockey class. Is that what you mean? I explain a great deal of the jargon in my object oriented design tutorials.

  • @derekbanas
    @derekbanas  12 років тому

    Sorry, but I don't know anything about runescape. I mainly make complicated simulations. That is what I'll base any games I make on. So you can expect to see tutorials on creating everything with OpenGL here instead of what is common on other channels which is to use tools like Unity 3D. I made that decision because there is zero cost involved and the possibilities are endless in regards to the games you can design.

  • @wasgibtsnet
    @wasgibtsnet 10 років тому +4

    sorry if that questions have already been asked:
    1. why don't you use generics instead of casting the components? (e.g. ArrayList songComponents = new ArrayList();
    2. why do you need, for example, getBandName or getReleaseYear, which are only needed in the Leaf-class, in your abstract component class? Can't you just omit them?

    • @derekbanas
      @derekbanas  10 років тому +5

      wasgibtsnet Only because I tried to keep the code as simple as possible. Generics confuse some people so I decided to avoid them here. Yes they should have been omitted. I largely wrote this out of my head which allows me to better cover the thinking process, but doesn't always lead to perfectly optimized code.

    • @wasgibtsnet
      @wasgibtsnet 10 років тому

      Derek Banas okay thanks, I just thought I didn't get some points :)

    • @ryklin1
      @ryklin1 7 років тому +1

      1. You're right, without declaring ArrayList it won't compile anyway. Derek's point below of keeping things simple makes sense.
      2. You're right, see discussion above!

  • @derekbanas
    @derekbanas  12 років тому

    To make games you need to learn a good oop language and a low level language. I use java and c. I have a massive java tutorial and tons of videos on object oriented design. If you learn that you'll be able to make anything

  • @pierredahmani4101
    @pierredahmani4101 4 роки тому +2

    Hey Derek first of, thanks for your videos!
    The only really disturbing sequence is your UML diagram. You declare SongComponent as an interface and implement it as an abstract class, which is "FINE". But in the UML Song doesnt extend or implement SongComponent. Which personally made it hard for me to understand in the first place, but after seeing your implementation not accordingly to your uml pattern and with additional help from wikipedia, I finally got it.
    keep up the good work, it has been years since this video was made anyway :D

  • @ling3188
    @ling3188 4 роки тому

    Clearly explained and easy to follow! Thanks a lot, ur design pattern tutorials turly helped me a lot.

  • @derekbanas
    @derekbanas  11 років тому

    Thank you :) Yes I'm learning the importance of keeping the code as brief as possible

  • @wjrasmussen666
    @wjrasmussen666 10 років тому

    I like the composite pattern. Useful for menus with menu items as well as sub-menus!! Good video!!

    • @derekbanas
      @derekbanas  10 років тому +1

      Thank you :) When you find the perfect place to use them the patterns are amazing.

  • @derekbanas
    @derekbanas  12 років тому

    I always eventually fulfill all requests. It helps me a lot to know what you guys want me to cover. Thanks

  • @derekbanas
    @derekbanas  12 років тому

    Thank you for the request. I'll add that to the list. I have many more videos on design patterns, oop design and code refactoring coming up. That way you'll be able to write better code. I hope to cover all of the common topics taught to software engineers. Thanks for watching :)

  • @raghebadel5689
    @raghebadel5689 12 років тому

    really thank you, i was very helpful
    I have too many problems with English language but i understood you well :) Thanks

  • @derekbanas
    @derekbanas  12 років тому

    Your english is great. You are very welcome :) Thank you for taking a look at my videos

  • @derekbanas
    @derekbanas  11 років тому +1

    You're very welcome :) Good luck on the test.

  • @CoalCandyX
    @CoalCandyX 7 років тому

    In hte overview in the beginning SongComponent is defined as an interface, but when you write the code you write it as an abstract class. Why?

    • @derekbanas
      @derekbanas  7 років тому

      I used abstract class because I decided I wanted to throw UnsupportedOperationException()

  • @derekbanas
    @derekbanas  11 років тому

    Thank you very much :) I enjoyed making this series

  • @LordLarzuk
    @LordLarzuk 10 років тому

    Hey, this playlist is great!
    I have a question.
    What do you mean with "Leaf" (At 1:30), I didn't get it.

    • @derekbanas
      @derekbanas  10 років тому

      Diego Aguiar Thank you :) Each Song object is a leaf, or node that makes up the SongGroup. It is a metaphor for a leaf on a tree

    • @LordLarzuk
      @LordLarzuk 10 років тому

      Ohh, I get it now. Thank you bro

  • @yeahiknow996
    @yeahiknow996 4 роки тому +1

    Thank God you have a good accent. Thanks mate. 🥴♥️

  • @tang2701
    @tang2701 10 років тому

    thank you your video. i have a question. my java is not good. In the abstract class songcomponent, why do we need use the abstract class? i see there has not any abstract method.

    • @derekbanas
      @derekbanas  10 років тому

      That was just a slip up on my part. I was writing out of my head. i should have made it an interface.

  • @derekbanas
    @derekbanas  11 років тому

    Thank you :) I must have written that in an odd way? I meant that the song was a leaf. Here is my comment: This acts as an interface for every Song (Leaf) and SongGroup (Composite) we create. Maybe I should describe it differently?

  • @anoopjoy501
    @anoopjoy501 4 роки тому

    The composite class "SongGroup" inherits the abstract methods getSongName, getBandName, etc. from the "SongComponent" interface which does not make sense for a SongGroup.
    Is this ok?

    • @sshawarma
      @sshawarma 4 роки тому

      I also have this question. Something about making all available methods pooled at the abstract class sounds fishy. Especially since we handle incorrect behavior with exceptions. I think only the shared methods should be in the SongComponent class, but then we have to know beforehand if the object is composite or leaf.

  • @Tonysunyueran
    @Tonysunyueran 8 років тому

    Thanks a lot. This term i have learned prolog php and software design courses, your video is extremely helpful.

    • @derekbanas
      @derekbanas  8 років тому

      +Tony Sun You're very welcome :)

  • @derekbanas
    @derekbanas  11 років тому

    Thank you very much :) I'm happy to help. It's funny how bad those power points are. I have seen the ones they use even in the Ivy league schools. They basically copy and paste information directly from books. I really wonder if the professors understand the information or not?

  • @derekbanas
    @derekbanas  12 років тому +1

    I'll definitely make a 3D game. I want to keep it small though so it will work on tablets as well. We'll see what happens

  • @nicksy4926
    @nicksy4926 4 роки тому

    I love the way you pronounce “data”

  • @praggo2841
    @praggo2841 2 місяці тому

    Hi Derek, why is SongComponent not an interface?

  • @wjrasmussen666
    @wjrasmussen666 10 років тому +3

    To get rid of the yellow type warning in Eclipse I had to change 3 things on 2 lines in SongGroup.java
    ArrayList songComponents = new ArrayList();
    and
    Iterator songIterator = songComponents.iterator();

    • @Brax1982
      @Brax1982 9 років тому +2

      +wjrasmussen666 You implemented generics. This will make the cast of songIterator.next() obsolete.

  • @Ranyelfull
    @Ranyelfull 8 років тому +1

    How can you remove Headhunter song from IndustrialMusic list of songs?

  • @Sedeerah
    @Sedeerah Рік тому

    This is great. Although I don't understand why we need the methods in the parent class, since we just end up making them throw an exception and then overwriting them. Why not only implement it in the subclass? What's the benefit here?

  • @gaiifafa1306
    @gaiifafa1306 10 років тому

    Great tutorial as always. This playlist is a great complement to Head First Design Patterns.
    My question is how does the iterator go through ALL the songs all at once when you call crazyLarry.getSongList()? Is it some sort of recursive function that prints out all the songs in a songGroup?
    My confusion is coming up when I look at the diagram at 2:11, you can see there are songGroups within songGroups with songs etc.

    • @derekbanas
      @derekbanas  10 років тому

      GaiiFAFA Thank you :) Everything is a SongComponent including Song and SongGroup. When DiskJockey is created it is passed a SongGroup which includes every Song. When displaySongInfo() is called for the DiskJockey it executes the SongGroups version which iterates through every song. Here is the source code www.newthinktank.com/2012/10/composite-design-pattern-tutorial/

    • @gaiifafa1306
      @gaiifafa1306 10 років тому

      Derek Banas
      Let me rephrase the question. If you take the songlist as you have it. And now you add a songComponent called Rock with some songs in it to dubstep songComponent. When you call the iterator in songGroup.java, how does the iterator print all the songs in heavyMetalMusic, IndustrialMusic, dubstep and then go Rock in dubstep. Rock is not on the same 'level' as the others. My inexperience is showing as my first encounter with the iterator was in the previous iterator pattern.

    • @derekbanas
      @derekbanas  10 років тому

      GaiiFAFA To have another addition auto iterate you'll need to have added it to the SongGroup

  • @638naveen
    @638naveen 9 років тому

    Very Good video .Thanks for Explanation. Hi Derek, can you please correct me whether Directory of files/folders follow the Composite pattern.

    • @derekbanas
      @derekbanas  9 років тому

      +naveen kumar Thank you :) Yes you could definitely structure data in that way using this pattern.

  • @taufiqr8797
    @taufiqr8797 8 років тому

    nice vidoe, but i still have a question
    on what kind scenario should i use this pattern?

  • @carolinamontecm
    @carolinamontecm 6 років тому

    What happens if you want to have just 3 individual songs, not being in any group at all. How do you display info for those 3 songs if they are not in any group and you can't iterate? Thanks!

  • @prassanak3601
    @prassanak3601 3 роки тому

    You have saved my life good sir

    • @derekbanas
      @derekbanas  3 роки тому

      I'm very happy you enjoyed the video

    • @prassanak3601
      @prassanak3601 3 роки тому

      @@derekbanas One question, aren't you supposed to declare the methods in the superclass as abstract? At least some of them anyway?

    • @rapidreaders7741
      @rapidreaders7741 2 роки тому +1

      @@prassanak3601 Not a necessity, but you could if you wanted to.

  • @derekbanas
    @derekbanas  12 років тому

    Usted es muy agradable

  • @deepakkumarjoshi
    @deepakkumarjoshi 8 років тому

    Hi,
    Thanks for the video :)
    Your website has code piece for composite pattern, I have one query on that.
    You wrote below class which extends SongComponent, and SongComponent has methods like getSongName, but you have not implemented it in your SongGroup class. Why?
    public class SongGroup extends SongComponent {...}

  • @Tempuslight
    @Tempuslight 10 років тому

    You need more views... very nice thanks!

    • @derekbanas
      @derekbanas  10 років тому

      Thank you :) You're very welcome.

    • @Tempuslight
      @Tempuslight 10 років тому

      Derek Banas You kind of saved my examen in a few hours, i'm going to bed now lol i had 7 design patterns to study... i think i'll dream in code now lol. Cheers.

    • @derekbanas
      @derekbanas  10 років тому +1

      Jepix X Best of luck on your exam :)

  • @hunterzxn
    @hunterzxn 11 років тому

    Thanks alot for these videos. Helps me alot preparing for my test!!

  • @Vendettaaaa666
    @Vendettaaaa666 11 років тому

    So, the UN-overridden methods, will just throw UnsupportedOperationException.
    For example : Collection method, it has binarysearch(), SortedCollections inherits Collection and overrides binarysearch(), in this case this operation is supported.
    When, UnSortedCollection inherits Collection, it should first of all, not override the binarysearch() (Since binary search is possible only on sorted collections), therefore throw the UnsupportedOperationException be default. Right??

  • @berklyniruthayam6687
    @berklyniruthayam6687 10 років тому

    very useful pattern, and nicely explained. Thanks!

  • @khaledosama3538
    @khaledosama3538 8 років тому

    can i have different types of leaf class besides song ?
    or it just either group or song

  • @21Coolieo
    @21Coolieo 11 років тому

    very informative. Thanks for the videos Derek!

    • @derekbanas
      @derekbanas  11 років тому +1

      You're very welcome :)

  • @GeorgePapageorgakis
    @GeorgePapageorgakis 6 років тому

    +Derek Banas I do not understand. How can a SongGroup contain a SongGroup or SongGroup and leafs?

  • @AbodeHimsy
    @AbodeHimsy 8 років тому

    is composite pattern like multiton pattern or not ?
    if not what the difference thnx

  • @davidakful
    @davidakful 7 років тому

    When will the exception be thrown? Who defines the condition? I did not get that. Will you please explain?

  • @derekbanas
    @derekbanas  11 років тому

    I did my best to make it easy to translate into most any OOP language. Sorry it didn't help

  • @teinvanderlugt1
    @teinvanderlugt1 10 років тому

    Hi Derek,
    Thanks! OOP and Design Patterns are the biggest reason programming is one of my favorite things to do.
    Just to understand the application of this design pattern a little bit more, do you think Views and ViewGroups in Android make use of the composite design pattern?
    Thanks!

    • @derekbanas
      @derekbanas  10 років тому

      Tein van der Lugt You're welcome :) Here is a good article on that scn.sap.com/community/developer-center/mobility-platform/blog/2014/01/11/implementation-of-composite-design-pattern-in-android-view-and-widgets

  • @Hairlikecottoncandyy
    @Hairlikecottoncandyy 12 років тому

    Ah, I see why you used displaySongInfo() for SongGroup and Song, pretty cool trick.

  • @mohseeeenjj
    @mohseeeenjj 11 років тому

    Thanks for the great job. I have a question regarding the "interface" . Why in your code, you comment it as a leaf? should't be the component and song class be the leaf?

  • @rollinOnCode
    @rollinOnCode 3 роки тому

    what is difference between composite and decorator pattern?

  • @natanpctech
    @natanpctech 10 років тому

    hey Derek. first thing - this tutorial is great. awsome!.
    i have a question about this line of code :
    while(songIterator.hasNext()) {
    SongComponent songInfo = (SongComponent) songIterator.next();
    songInfo.displaySongInfo();
    }
    i don't understand one thing.
    you made a songInfo an object of (SongComponent) by casting it.
    so how exactly songInfo.displaySongInfo() reach the displaySongInfo in the Song class?
    thanks

    • @Brax1982
      @Brax1982 9 років тому +1

      +‫נתן בראל‬‎ The gist of it is that the compiler does not know that songIterator.next() returns a SongComponent, so you need the cast. That's because the ArrayList wasn't parameterized aka Generics were not used. But the dynamic type of songInfo will still be either Song or SongGroup at runtime, which is when methods are resolved.

  • @MultiplyByZ3r0
    @MultiplyByZ3r0 11 років тому

    I have a question that is not completely related to this video but I couldn't find a video of yours on the matter:
    Suppose I want to create two methods, one of which requires an argument, and another, which does the same thing, but acts as a default, if there are no arguments supplied, that is the one called, like the Random.nextInt() and Random.nextInt(int MaxValue) methods. How would I do that? I saw you do that with constructors but not methods.

  • @MustaphaelmadiUniq
    @MustaphaelmadiUniq 9 років тому +2

    Excellent video just one note you said an interface and you used an abstract class is it the same ?

    • @derekbanas
      @derekbanas  9 років тому

      +Mustapha elmadi Thank you :) They are similar. An abstract class can contain concrete functions (non-abtract classes). An interface must contain only abstract classes.

    • @SwissExperiments
      @SwissExperiments 9 років тому

      +Derek Banas isn't this false in java 1.8? as far as i know you can write concrete functions in interfaces as well now.

    • @TheRockNinja1
      @TheRockNinja1 9 років тому

      +Swiss Experiments - Castagnola007 I don't know if this is still relavant but interfaces can ONLY have abstract methods that need to be implemented by classes that implement the interface, so no working funcions or attributes. Abstract classes can have attributes, working functions and abstract methods, however you can not use the NEW operater on an abstract class since you need to implement the abstract methods using inheritance.

    • @SwissExperiments
      @SwissExperiments 9 років тому

      Actually in Java 8 you can have interfaces with default implementations. you can look it up if you're interested.

  • @benzeltser9851
    @benzeltser9851 2 роки тому

    Clearly explained
    we played a drinking game where we play this video and take a shot every time you say song
    we are in the hospital

  • @pennenbakje1
    @pennenbakje1 12 років тому

    Hello Derek,
    I watched your php videos and java.
    I really want to know how to code RSPS', (Java biased game if you didn't know already). What do you think I should learn; Java or Javascript?
    I tried reading the code but without any knowledge it's just impossible.

  •  7 років тому +1

    Hi Derek Banas! Excellent material, congradulations!
    I have one question: is it a reason for you use iterator and not a normal loop?
    Thanks!

    • @rodrich182
      @rodrich182 7 років тому

      I think because when you use array of objects, a loop actually loops multiple times trough the array. Meanwhile the iterator goes trough the array once.

    • @shonny244
      @shonny244 6 років тому +1

      Thats not the reason. The reason is that you don't want the user to know how the songComponent is actually implemented behind-the-scenes, but still want to allow them to iterate through the songs you hold in some way.
      The client doesn't have an access to the array and shouldn't even know that it exists. So you have to implement an iterator within your class (and here you do the looping. Cause you know what data structure do you use) and provide it to the user.
      The benefits of it is of course safety and the fact that in the future you can replace your arrayList by any other structure (for example, a hash map) and the user won't even notice that.
      A year after the question was asked, but maybe it still may help someone.

  • @cslife7252
    @cslife7252 8 років тому +1

    You are amazing, Derek!

    • @derekbanas
      @derekbanas  8 років тому +1

      Thank you for the nice compliment :)

  • @roberteikeland3485
    @roberteikeland3485 8 років тому +2

    Very good video. Thank you for this.

  • @LPArabia
    @LPArabia 10 років тому

    Loved crazyLarry better than madMike. Great tutorial, thanks!!

    • @derekbanas
      @derekbanas  10 років тому +1

      That's funny :) Thank you

  • @paulsubha
    @paulsubha 11 років тому

    If,I have to ensure that a particular song can come only under one song group(only one parent), then my add logic would be,
    public void add(SongComponent comp){
    comp.parentNode = this;
    this.songComponents.add(comp);
    }
    My question is, If I have to implement this, then I have to define the "parentNode" variable in abstract class and override it in derived classes. is it the correct way ??
    Also, in that I cannot use interface, as I cannot override variables defined in interface.

  • @derekbanas
    @derekbanas  12 років тому

    Thanks for coming by SawMan :)

  • @cyberpunknexus
    @cyberpunknexus 10 років тому

    NIN and Front 242!!! they are really cool bands and I´m learning design Patterns too!! : D.

    • @derekbanas
      @derekbanas  10 років тому

      That's cool. I'm glad you are enjoying the videos :)

  • @derekbanas
    @derekbanas  11 років тому

    I'm happy I could help :)

  • @eugenepark
    @eugenepark 5 років тому

    how come songComponents are ArrayLIst instead of HashSet? shouldnt there be unique song?

  • @bascelik91
    @bascelik91 6 років тому

    could we use interface instead of abstract class?

  • @xaiga29
    @xaiga29 3 роки тому

    A good overview of the pattern in the beginning, but I was looking for C++ examples. Maybe change the title to "Composite Design Pattern (Examples in Java)" ?

  • @jorisbonson386
    @jorisbonson386 3 роки тому

    Can you explain why it's necessary at all to include either the collection-specific or song-specific methods in SongComponent? Surely the only method that should be in that interface is displaySongInfo? Say we add another type of SongComponent which adds more type-specific methods - these really shouldn't be in the SongComponent interface itself when they should only exist in derived classes. If a caller is attempting to call 'add', 'remove' or 'getComponent' on a Song object itself that would surely be indicative of bad design elsewhere...

  • @armaandhanji2112
    @armaandhanji2112 9 років тому +2

    Hey Derek. Just wanted to say your videos are amazing. Would you consider doing a video tutorial on Node.JS at any point in time? Thanks again for all your videos

    • @derekbanas
      @derekbanas  9 років тому +2

      Armaan Dhanji Thank you :) Yes NodeJS tutorials will start as soon as I finish up Rails.

  • @Jhanny27
    @Jhanny27 11 років тому

    This video is great. Helped me a lot!!! Thanks!!

    • @JonahNelson7
      @JonahNelson7 4 роки тому

      Are you a crazy successful software designer now?

  • @sarvagyagupta1744
    @sarvagyagupta1744 3 роки тому

    Thank you for covering this. I have a question though. Have you made a video on comparing different design patterns? It seems very similar to state design pattern. Let me know.

  • @NicolasSantosDev
    @NicolasSantosDev 10 років тому

    Great video Derek thank you!

    • @derekbanas
      @derekbanas  10 років тому

      Thank you :) I'm glad it helped

  • @suresh423
    @suresh423 11 років тому

    Hi Derek,
    First of all a big Thank You for all your tutorial. I follow them regularly. Regarding this, design pattern, I am planning to use this design pattern in my application, where we have Value Objects, which are responsible for the display of the presentation layer. The scenario is that, each Value object can contain other VOs, based on the functionality of the JSP page. For example, Employee JSP contains, Employee Income details, Employer Details and Expense details. All these three objects/VO construct a Employee JSP. At the same time, this whole employee page is a part of another JSP. I am not getting the whole picture of how to construct it. Is it possible for you to explain, how to use this pattern in case of presentation layer using JSP.