Skip to content
Example usage of the various design patterns in Java.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Example usage of the various GoF design patterns in Java

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?

Design Patterns: Elements of Reusable Object-Oriented Software

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.
Executing mvn or 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

Creational design patterns abstract the instantiation process. They help make a system independent of how its objects are created, composed, and represented.

Design Patterns: Elements of Reusable Object-Oriented Software

There are five creational design patterns:

Structural 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.

Design Patterns: Elements of Reusable Object-Oriented Software

There are seven structural design patterns:

Behavioural patterns

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.

Design Patterns: Elements of Reusable Object-Oriented Software

There are eleven behavioral design patterns:

You can’t perform that action at this time.