This repository contains educational implementations of key object-oriented design patterns in Java. Each pattern is organized into its own package and includes:
- Singleton Pattern: Demonstrates both thread-safe and unsafe variants;
- Builder Pattern: Explores burger-building scenarios with abstraction and directors;
- Abstract Factory Pattern: Uses client contracts to generate cars with shared interfaces;
- Factory Method Pattern: Provides a car production model where each subclass defines its own product creation logic;
- Facade Pattern: Simplifies subsystem interactions with an apartment registration example;
- Observer Pattern: Implements event subscription using TV, Newspaper, and Journalist classes;
- Template Method Pattern: Defines worker daily routines with concrete subclasses overriding specific behaviors;
- Dependency Injection: Demonstrates Spring-based DI with services and notification senders;
- Adapter Pattern: Adapts DropBox API to a common file handler interface for unified file operations.
The repository is structured for both learning and practical reference. JavaDocs and inline comments have been added for all files to improve clarity and support self-study.
singleton
: Lazy initialization, thread-safe variations, and property-based Singleton examples;builder
: Abstract builders, concrete implementations, and a manager class as a director;abstractfactory
: Factory hierarchies for cars and clients with/without contracts;factorymethod
: Abstract creators define car factories, and concrete factories build specific models like Corolla, Jetta, and Model S;facade
: Apartment registration example with simplified interface to complex subsystems;observer
: Implements observer pattern with subjects and observers like TV, Newspaper, and Journalist;templatemethod
: Abstract worker routines with concrete worker types like Cop, Firefighter, and Manager;dependencyinjection
: Spring framework based DI examples with services and notification senders;adapter
: Adapter pattern example integrating DropBox with a generic file handler interface.
- Added JavaDocs and comments to all files in the
dependencyinjection
package; - Added detailed explanation of Dependency Injection concepts in the Demo file;
- Created
NotificationSender
and refined interfaces with prefixed 'I'; - Demonstrated Dependency Injection using Spring framework.
- Implemented Adapter pattern to integrate DropBox with a common file handling interface (
IHandleFiles
); - Created
DropBoxAdapter
to adapt DropBox API for uniform file operations; - Added mock classes
DropBox
,DropBoxFile
, andGoogleDrive
for demonstration; - Included demo showcasing file recording and reading through the adapter interface.
- Created Facade pattern example with apartment registration system;
- Implemented interfaces and concrete classes to simplify subsystem interactions;
- Added demo to illustrate facade usage.
- Created Observer pattern example with
Observer
andSubject
interfaces; - Implemented observers like TV and Newspaper and subject Journalist to manage notifications;
- Added demo showing observer registration and notification flow.
- Renamed
factory
package toabstractfactory
for clarity; - Created new
factorymethod
package to demonstrate the Factory Method pattern; - Implemented
Car
abstract product with basic behaviors likestartEngine
andfuelCar
; - Created factories for specific cars:
CorollaCarFactory
,JettaCarFactory
, andModelSCarFactory
; - Enhanced JavaDocs to better explain the Factory Method concept and demo flow.
- Added JavaDocs to all classes and methods;
- Implemented client-type factories with matching car variations;
- Enhanced demo logic with dynamic class-based print output.
- Completed Builder pattern with burgers, manager, and variation builders;
- Reorganized files and added supporting comments.
- Added thread-safe and unsafe Singleton demos with detailed documentation;
- Wrote JavaDocs and inline comments to explain multithreading issues.
- Implemented classic Singleton pattern with lazy initialization;
- Added property-based Singleton variant for enhanced control.