What are the differences between Abstract Factory and Factory design patterns?

后端 未结 17 1184
醉话见心
醉话见心 2020-11-22 01:57

I know there are many posts out there about the differences between these two patterns, but there are a few things that I cannot find.

From what I have been reading,

17条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 02:53

    Real Life Example. (Easy to remember)

    Factory

    Imagine you are constructing a house and you approach a carpenter for a door. You give the measurement for the door and your requirements, and he will construct a door for you. In this case, the carpenter is a factory of doors. Your specifications are inputs for the factory, and the door is the output or product from the factory.

    Abstract Factory

    Now, consider the same example of the door. You can go to a carpenter, or you can go to a plastic door shop or a PVC shop. All of them are door factories. Based on the situation, you decide what kind of factory you need to approach. This is like an Abstract Factory.

    I have explained here both Factory method pattern and abstract factory pattern beginning with not using them explaining issues and then solving issues by using the above patterns https://github.com/vikramnagineni/Design-Patterns/tree/master

提交回复
热议问题