GoF design patterns in Java
Example usage of the various
Once you understand the design patterns and have had an "Aha!" (and not just a"Huh?") experience with them, you won't ever think about object-oriented design in the same way. You'll have insights that can make your own designs more flexible, modular, reusable, and understandable—which is why you're interested in object-oriented technology in the first place, right?
Twenty-three design patterns are introduced in this amazing book,
This repository contains example usage for them written in
Java with the basic layout:
- The markdown folder stores an .md file per design pattern. Each file starts with a quote describing pattern on hand, followed by a small description, a list of classes combined with their description and finally a description of the test case that exemplifies the pattern. All the files described are linked to the src folder.
- The src is of course the project code folder, it stores the program the testing classes.
The project is packaged with Maven, and utilize the JUnit 5 testing framework and AssertJ assertions library.
mvn test will run 23 test cases (test case per design pattern) and will fill your screen with log records written
by the product code to help exemplify the flow of the pattern on hand.
- Creational patterns
- Structural patterns
- Behavioural patterns
Creational design patterns abstract the instantiation process. They help make a system independent of how its objects are created, composed, and represented.
There are five creational design patterns:
Structural patterns are concerned with how classes and objects are composed to form larger structures. Structural class patterns use inheritance to compose interfaces or implementations.
There are seven structural design patterns:
- Adapter pattern
- Bridge pattern
- Composite pattern
- Decorator pattern
- Facade pattern
- Flyweight pattern
- Proxy pattern
Behavioral patterns are concerned with algorithms and assignment of responsibilities between objects. Behavioral patterns describe not just patterns of objects or classes but also the patterns of communication between them.
There are eleven behavioral design patterns: