Prototype Design Pattern Tutorial

Prototype Design Pattern TutorialWelcome to my Prototype Design Pattern Tutorial. The Prototype design pattern is used for creating new objects (instances) by cloning (copying) other objects.

It allows for the adding of any subclass instance of a known super class at run time. It is used when there are numerous potential classes that you want to only use if needed at runtime. The major benefit of using the Prototype pattern is that it reduces the need for creating potentially unneeded subclasses.

All of the code follows the video to help you learn.

If you like videos like this, please tell Google [googleplusone]

Sharing is super great [nttfblike]

Code from the Video

ANIMAL.JAVA

SHEEP.JAVA

CLONEFACTORY.JAVA

TESTCLONING.JAVA

20 thoughts on “Prototype Design Pattern Tutorial”

  1. I just came across your design pattern tutorials.You have explained the concepts in a simple manner and its amazing..!!!

    Looking forward to view and learn all your videos….

    Great JOB..

    1. Thank you very much 🙂 I did my best to make them easy to understand. I’ll dive into using them and recognizing when they can help in my next tutorial on refactoring. Thank you for taking the time to tell me you liked them

  2. I really appreciate the way you have explained the java design pattern. It clears all my doubts.

    Thank you again for your awesome description..:)

  3. Very good, clean and clear tutorial. Best part is the availability of the code to be practiced by the learner.
    If possible, if you include class diagram then it would be perfect.

  4. Hi, Derek!

    Your tutorials are awesome! Keep the good work.
    I’ve a suggestion…
    In the classes Dog and Sheep you can return Dog and Sheep types (respectively) in makeCopy method, because they’re subtypes of Animal:

    //Dog.java file
    @Override
    public Dog makeCopy() {
    (…)
    }

    //Sheep.java file
    @Override
    public Sheep makeCopy() {
    (…)
    }

    So, you’ll avoid cast to this types later, but you won’t able to use CloneFactory without do the cast. It’ll seems like that:

    Sheep clonedSheep = sally.makeCopy();

    []’s
    Helton

  5. Hi Derek,
    I never thought in my life that design pattern could be learned in such an easy way. I would really thanks from my bottom of my heart. The way you are explaining the stuff is exceptional. I became your great friend… One small request please upload few core java related stuff such as: collections, Java memory management , Multi Threads , Syncronization. Thanks again and god bless you…

    1. Thank you 🙂 I’m very happy that they have helped. I plan on going back and covering all of the topics you have mentioned and much more. I’m sorry it is taking so long. May God bless you and your family as well

  6. I would like to ask an other question , What about making our object’s constructors private to prevent direct instantiation ?

  7. Not only the explanations are great, but also the quality of the videos. Congrats and thanks for such a hard and great work!

  8. I appreciate the videos as they seem to be gentle introductions to design patterns, but a little bit of explanation on how they improves quality would be very nice. For instance, with this video, why go through the trouble of creating a factory, when one could very easily have done this:

    Sheep clonedSheep=(Sheep)sally.makeCopy();

    I realize that there is some underlying reason as to why the above design is better, and it maybe that the benefits of applying the design patterns do not manifest in small programs , but a gentle reminder of why they ultimately are better would complement these tutorial videos very nicely. Or else, these tutorials would just be a ‘hey, so this is this and that is that…’, and not ‘Hey, but this is why this is so and that is such!’

  9. thank you ever so much mate! i consider you one of these few rare individuals that really try to make the world a better place, i wish i could shake your hand and buy you a beer 🙂

  10. Hi Derek,
    I have watched many videos on Design Patterns but the way you have explained is very nice and your examples are so practical and real that it is easy to remember because it related with real world problems.

    Please keep up the good work. I would suggest you to pick up such complex concept and keep explaining them in your way…

Leave a Reply

Your email address will not be published. Required fields are marked *