Repository navigation
Add Simple Factory Pattern implementation - #1516
Conversation
Java source code demonstrate simple factory design pattern
- Change the name to factory is done - Local variable type inference is used
|
@iluwatar I don't know why urm-maven-plugin generates factory.urm.puml but does not generates factory.urm.png? |
|
One suggestion which I can say is to use Lambda expressions instead of using switch cases to generate Cars. |
It doesn't, the image needs to be created by hand. See https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute |
| ## Applicability | ||
|
|
||
| Use the Simple Factory pattern when you only care about the creation of a object, not how to create and manage it. | ||
|
|
||
| ## Disadvantages: | ||
|
|
||
| The code becomes more complicated than it should be. |
There was a problem hiding this comment.
We could rephrase this part a bit so that there is ##Applicability section and under it Pros and Cons.
There was a problem hiding this comment.
Additionally please add a class diagram.
- Adding class diagram - Adding Pros and Cons - replace "" with ''
|
|
||
| **Programmatic Example** | ||
|
|
||
| We have an interface 'Car' and tow implementations 'Ford' and 'Ferrari'. |
There was a problem hiding this comment.
| We have an interface 'Car' and tow implementations 'Ford' and 'Ferrari'. | |
| We have an interface `Car` and tow implementations `Ford` and `Ferrari`. |
| ## Applicability | ||
| Use the Simple Factory pattern when you only care about the creation of a object, not how to create and manage it. | ||
|
|
||
| ## Pros |
| * Allows keeping all objects creation in one place and avoid of spreading 'new' key value across codebase. | ||
| * Allows to writs loosely coupled code. Some of its main advantages include better testability, easy-to-understand code, swappable components, scalability and isolated features. | ||
|
|
||
| ## Cons |
|
Found just minor issues so I'll merge it and push a change after it. |
|
Many thanks for the new pattern! @all-contributors please add @samilAyoub for code |
|
I've put up a pull request to add @samilAyoub! 🎉 |
|
@all-contributors please add @ravening for review |
|
I've put up a pull request to add @ravening! 🎉 |
Java source code demonstrate simple factory design pattern.
relates to : #1477