Updates README.md:
- Adding class diagram - Adding Pros and Cons - replace "" with ''
This commit is contained in:
parent
b3ef214cd6
commit
bf41b1d9c9
@ -29,7 +29,7 @@ Wikipedia says
|
|||||||
|
|
||||||
**Programmatic Example**
|
**Programmatic Example**
|
||||||
|
|
||||||
We have an interface "Car" and tow implementations "Ford" and "Ferrari".
|
We have an interface 'Car' and tow implementations 'Ford' and 'Ferrari'.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
/**
|
/**
|
||||||
@ -68,7 +68,7 @@ public class Ferrari implements Car {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Enumeration above represents types of cars that we support(Ford and Ferrari).
|
Enumeration above represents types of cars that we support (Ford and Ferrari).
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public enum CarType {
|
public enum CarType {
|
||||||
@ -90,7 +90,7 @@ public enum CarType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Then we have the static method "getCar" to create car objects encapsulated in the factory class "CarSimpleFactory".
|
Then we have the static method 'getCar' to create car objects encapsulated in the factory class 'CarSimpleFactory'.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
/**
|
/**
|
||||||
@ -122,13 +122,18 @@ Program output:
|
|||||||
This is Ford.
|
This is Ford.
|
||||||
This Ferrari.
|
This Ferrari.
|
||||||
```
|
```
|
||||||
## Applicability
|
## Class Diagram
|
||||||
|

|
||||||
|
|
||||||
|
## Applicability
|
||||||
Use the Simple Factory pattern when you only care about the creation of a object, not how to create and manage it.
|
Use the Simple Factory pattern when you only care about the creation of a object, not how to create and manage it.
|
||||||
|
|
||||||
## Disadvantages:
|
## 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.
|
||||||
|
|
||||||
The code becomes more complicated than it should be.
|
## Cons
|
||||||
|
* The code becomes more complicated than it should be.
|
||||||
|
|
||||||
## Related patterns
|
## Related patterns
|
||||||
|
|
||||||
|
BIN
factory/etc/factory.urm.png
Normal file
BIN
factory/etc/factory.urm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
Loading…
x
Reference in New Issue
Block a user