Skip to content

Commit b05cb45

Browse files
authored
Create README.md
1 parent d75428b commit b05cb45

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

factory/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Factory Design Pattern
2+
3+
## Java Implementation: The Shape Factory
4+
5+
6+
The Factory design pattern is used when we want to give an interface allowing us to create families of connected objects without exposing the concrete classes. This is most useful when we have a general pattern that our objects will follow, as we can ensure minimal repetition of code (high cohesion, low coupling).
7+
8+
### Code overview
9+
10+
This simple implementation of the Factory pattern has the following structure:
11+
12+
__Interface:__ `Shape` - contains a `draw()` method which will be overriden by each concrete class which implements this interface.
13+
14+
15+
__Concrete Classes:__
16+
17+
* `Circle` - implements `Shape`, prints a circle to the console.
18+
* `Square` - implements `Shape`, prints a square to the console.
19+
* `Rectangle` - implements `Shape`, prints a rectangle to the console.
20+
* `ShapeFactory` - generates objects of the above classes.
21+
* `FactoryEngine` - uses `ShapeFactory` to obtain objects of the shape classes by parsing information.
22+
23+
24+
When `FactoryEngine` is run, you should see a circle, square and rectangle printed to the console (in the style of ASCII-art, with asterisk '*' symbols).

0 commit comments

Comments
 (0)