Design Patterns factory models, design patterns Factory
If you have a lot of money, your lifestyle is like this before you use the factory model:
If you want to go out, you must first find your own t-shirt, pants, and shoes. This is definitely troublesome, And everything needs to be done by yourself.
If you use the simple factory model, you will find a manager. However, the manager is rigid and has limited skills. If you tell him what you want, he will give it to you, he may not be able to give it to you. What if the butler only provides jackets, trousers, and shoes? What if you need a briefcase? Two options: let your Manager Add [modify source code], and then recruit another manager [Apply factory method mode ], both the recruiting manager and the former manager share a common behavior and provide me with what I need. [a common behavior can abstract an interface and define a behavior specification]
The factory method model can be simply understood as you have multiple butlers, each of which is responsible for the same business, the Butlers for your shirt, the Butlers for your pants, and the Butlers for your shoes, they all share a common action to provide you with what you need. If you need a new briefcase, for example, you can directly recruit a butler responsible for your briefcase, this Butler must provide you with the behavior of what you need [implementing a common interface], because they all serve you. It is not necessarily a manager. [products can be different. factory methods can allow different products. You only need to follow the common code of conduct.] You can find a girlfriend and a nanny.
The abstract factory model can be understood in this way. You have multiple girlfriends [Abstract Factory, common behavior, providing clothes, pants, and shoes for you ......] Multiple butlers [Abstract products, provide clothes, pants, or shoes], butlers provide clothes (clothes also contain various colors, and others are also divided into various colors and sizes) pants, shoes, briefcase, etc. Your girlfriend [specific factory] provides you with a set of clothes, such as clothes worn at work and banquet ...... A specific butler provides a specific product, such as clothes or trousers]
The above is my simple understanding.
>>>> Do everything by yourself
>>>> Find a manager with limited capabilities
>>>> There are multiple housekeepers, each of which is responsible for specific transactions.
>>>> With girlfriends and butlers, butlers are responsible for providing specific things, while girlfriends are responsible for helping you with combinations.