Collection of patterns and other constructs in Java for educational purposes. (See Contributing section if you would like to contribute).
- Install a Java 21 implementation (like openjdk21)
- Clone and run the spring-boot maven goal:
git clone https://github.com/lpenap/java-patterns-and-constructs
cd java-patterns-and-constructs
./mvnw spring-boot:run- Abstract Factory
- Adapter
- Chain of Responsibility
- Decorator
- Factory
- Factory Method
- Observer
- Singleton
- Strategy
- Template Method
- Producer/Consumer, a multi-process synchronization problem.
Change the log level to TRACE in application.properties if you would like to see the output from examples:
logging.level.com.penapereira.example.*=TRACEIf you have an interesting idea but don't know how to implement it, feel free to open an issue to request a new feature.
If you would like to contribute additional constructs or patterns follow this steps to add an additional package with the additional example:
- Create an additional nested package (i.e.
newexample) ascom.penapereira.example.constructs.newexample - Place the interfaces and classes you need there.
- Implement an example runner by giving it a name ending in
ExampleRunner, implementing theExampleRunnerInterfaceand adding the@Componentannotation:
@Component
public class FooBarExampleRunner implements ExampleRunnerInterface {
@Override
public void runExample() {
// place your code here
}
}Additional notes:
- Keep it simple, the idea is to implement the minimum from an educational point of view.
- Try to keep your runtime in less than 1000 milliseconds.
- If you need to output text to the console, try not to print more than 5 lines, you can add a slf4j logger this way and use
trace:
@Component
public class FooBarExampleRunner implements ExampleRunnerInterface {
private static final Logger log = LoggerFactory.getLogger(FooBarExampleRunner.class);
@Override
public void runExample() {
log.trace("Executing FooBar example:");
}
}