Abstract Factory Design Pattern

Get the Code Here:

Best Design Patterns Book :

Here is my Abstract Factory design pattern tutorial. I also take a second look at the Factory design pattern here as well.

This is considered a hard pattern to understand, but I consider it to be a combination of all you have learned previously. You just need to understand that each step is separated by either a abstract class or an interface. This makes it possible to make extremely flexible objects.






29 responses to “Abstract Factory Design Pattern”

  1. Ran Perry Avatar

    Hi, ur videos help me a ton, so thanks for that!
    In regards of the difference between abstract factory to factory, I think it'd simple things out if u said the difference was that the abstract factory returns an abstract class, while the factory returns a concrete class – apart from that, they're the same!

  2. Tim Boland Avatar

    Is this from Head First Design Patterns?

  3. Diego Bermudez Avatar

    Mierda esta en ingles jeje

  4. Pengguna PHP Avatar

    Amazing Derek! Thanks…

  5. Voicir Avatar

    I would have rather you start from the weapons and worked your way up to the client so that everything felt like a plugin to the lower concept.

  6. King of the Jg Avatar

    I feel like I would have understood this more if you made the video longer and went through the code with us, rather than showing the end product you wrote up. been learning way better from your hands on strategy where you write the code and we follow along, but that's just me. Personally I had to go to the site to make the code into a project to understand the gist of whats happening. Still informative good job

  7. Ron Borneo Avatar

    This was the main one I struggled to understand in class.. Starting to understand it, but it's not there yet. Probably just takes time, definitely gonna dive in to the code. Thank you!

  8. vsirius77 Avatar

    I made an UML if someone needs: https://ibb.co/e7HQHk

  9. Rubens Martins Avatar

    Derek, thank you so much for your videos.

    Just a quick feedback, your usage of literally is wrong. See:

    A guy says something to his friends that doesn't make sense. His friend comments
    "He's tripping."

    A says something to his friends that doesn't make sense whilst on a plane going on vacation. His friend comments
    "He's tripping, literally".

  10. Mujtaba Avatar

    nonsensical example.. doesn't make any sense.. please focus on real world examples instead of aliens n UFo's..

  11. Thangam Arumugam Avatar

    amazing help you are doing but my request is please explain slowly  so that the people like me can understand much better 🙂 🙂

  12. David Van Isacker Avatar

    Hi Derek ! Great vid, i really understood the concept.
    However if I understood correctly the UFOEnemyShipBuilding.java recreates a new ship factory everytime a ship is created. Isn't that unefficient ? Is that how abstract factories work in real-world applications ?

  13. Ryan Evezard Avatar

    If you wanted to make either a RocketEnemyShip would you have another abstract method in "EnemyShipBuilding" for the rocket ie.

    protected abstract EnemyShip makeEnemyRocketShip(String typeOfShip);

    If not, how would you distinguish between building a Rocket or a UFO?

  14. Yurii Horwight Avatar

    pretty complicated
    I need to use it several times to understand better!

  15. Denzhe Sadiki Avatar

    I understand why a lot of people are complaining about the UML diagram but i found the analogy to be very helpful, thank you.

  16. MrLuke1618 Avatar

    Can you tell me the name of the software you use to demonstrate those awesome pictures and texts you made, please ? I want to teach my friend something but I don't know which one to use until I saw your video. Great videos, I love them, I'm a new fan. Thanks.

  17. Gank Patrol Avatar

    Is there anyway in the Abstract Factory Pattern do stop the developer from instantiating a class without using the factory pattern by using a private constructor?

  18. Tuna Çelik Avatar

    I understand clearly nothing!

  19. Renzo Coppola Avatar

    I've never used a factory in my 1 year of programming outside education. I know it isn't a lot of time, but this pattern is such an ugly beast.

  20. Samuel Slavkovský Avatar

    I have a question.
    Let's say I want to release this and allow users to define their own types of ships. Let's say, UberUFO, of miniUFO. And of course, I do not want users to change my code. So how should I do it, so that even the new ships will be created without one big ugly swith (or a lot if if else statements)?
    If you know what I mean.

    The reason why I an asking is, because in school, we have to implement something similar and I don't know how to do it.

  21. Ятвойдед Avatar

    Derek, I'm not sure, that it is the right vision of this pattern. You used a lot of different patterns, but this is not an abstract factory, because you creates instances of ships outside the factory. I'd say, you made a copy-past anty pattern.

  22. menzo wijmenga Avatar

    Hey Derek, not sure if you go into this later in your tutorial series but why don't you use public static ENUM's in your factories that define what type of ships are available? So You could use UFOEnemyShipBuilding.makeEnemyShip(UFOEnemyShipBuilding.SHIPS.UFO_BOSS) to create a UFO Boss ship. This will prevent typos in ship types, and also provide a nice list inside a developers IDE on which ship types are available.

  23. Mokhtar Al-Shubei Avatar

    «Abstract Factory is like an abstract class with fields that are Factory methods» – "me"
    Ach leave me guys I am having tomorrow an exam iSAQB-CPSA-F (Software Architecture) and hate giving things fancy names really. Even Derek is almost the best one who explains me most of concepts but still AF and FM patterns are messed up whereas they are simply: (haha yet another philosopher jumps into)

    Abstract Factory is like an abstract class with fields that are Factory methods. So, first study the FM bottom up, meaning how i create an object1 or object2 (shared interface) by calling a method with a parameter (because you are OOP, that method gotta be in a class you instantiate -> that class is the Factory Pattern).
    Imagine now that FM creates many objects (many concerns) so then how can I abstract/split this to more verbose shitty hierarchal structure using polymorphism.

  24. naits1rch Avatar

    Hello Derek I'm once again onto the breach, I think I finally figured out how this works (let's hope so because I have stared at this for waaay to long xD).
    Let's see if can explain it:
    So the commissioner wants a ship to be built, there are many types of ships to be build some which differ in slight detail, like the damage of the weapon and the speed, and others that have completely different weapons/races (is UFO a race? xD) so basically we use a factory for each group of ships that are similar, basically ending up with for example a factory for UFO and another for missile ships, to decide which kind of ship shall be built we call the EnemyShipBuilding.
    The EnemyShipBuilding creates an abstract enemy ship suing the right parts, done by choosing the right ShipFactory, that "creates" the right weapon and engine for the ship.
    Boy this was a difficult one, can you please tell me if I understood the concept? Thanks to you in advance and congratulations for the great video 😉

  25. Ashwini Jha Avatar

    what do you mean by "creating families of related objects"?

  26. Sam Tux Avatar

    Thank you for great tutorials. When watching them I recall this:

    Every programmer occasionally, when nobody's home, opens up a file on their computer. It's a different file for every programmer. Sometimes they wrote it, sometimes they found it and knew they had to save it. They read over the lines, and weep at their beauty, then the tears turn bitter as they remember the rest of the files and the inevitable collapse of all that is good and true in the world. This file is Good Code. It has sensible and consistent names for functions and variables. It's concise. It doesn't do anything obviously stupid. It has never had to live in the wild, or answer to a sales team. It does exactly one, mundane, specific thing, and it does it well. It was written by a single person, and never touched by another. It reads like poetry.

  27. K H Avatar

    you should have included uml diagram

  28. rahul pathak Avatar

    I really like the content quality and the way you explain the idea. How do you create the diagrams like at 2:32 or 8:02. These are really nice

  29. Yang Tianxiao Avatar

    Thank you for those detailed code and examples!

Leave a Reply

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