How msharma84/design-pattern works
Purpose and Runtime
This is a Java/Maven learning repository of independent design-pattern examples, not a cohesive application or service. The build boundary is pom.xml; sources are plain Java under src/main/java. There is no indicated web layer, database, messaging system, or external API integration.
Entry Points and Execution Model
Examples are run individually through demo/test-style main classes rather than a central bootstrap. Key entry points include src/main/java/factory/FactoryDemo.java, src/main/java/factory/notification/Main.java, src/main/java/pipeline/Main.java, and src/main/java/immutable/ImmutableDemo.java. Classes named *Test are also placed in main sources and appear to be executable demonstrations.
Factory-Based Object Selection
Two factory families isolate callers from concrete implementation selection:
• Animal creation: src/main/java/factory/AnimalFactory.java selects implementations of src/main/java/factory/Animal.java, including src/main/java/factory/Dog.java and src/main/java/factory/Cat.java.
• Notifications: src/main/java/factory/notification/NotificationServiceFactory.java maps src/main/java/factory/notification/NotificationType.java to the src/main/java/factory/notification/Notification contract and channel implementations such as src/main/java/factory/notification/EmailNotification.java.
The factory is the control boundary between a requested type and concrete behavior.
Pipeline and Strategy Composition
The pipeline package provides ordered processing orchestration. src/main/java/pipeline/Pipeline.java composes src/main/java/pipeline/Step.java implementations, with concrete stages src/main/java/pipeline/StepOne.java, src/main/java/pipeline/StepTwo.java, and src/main/java/pipeline/StepThree.java; src/main/java/pipeline/Main.java drives execution.
Payment behavior is selected through the Strategy contract in src/main/java/stratergy/PaymentStrategy.java. src/main/java/stratergy/PaymentContext.java delegates to selected payment implementations, while src/main/java/stratergy/PaymentClient.java acts as the consumer boundary. Implementations include src/main/java/stratergy/CreditCardStrategy.java and src/main/java/stratergy/UPIPaymentStrategy.java.
Structural Object Models
Adapter code translates a socket voltage source into requested voltage forms: src/main/java/adapter/SocketAdapter.java defines the target interface, src/main/java/adapter/SocketAdapterImpl.java adapts src/main/java/adapter/Socket.java, and src/main/java/adapter/Volt.java carries the adapted value.
Composite code represents a tree of drawable shapes. src/main/java/composite/Shape.java is the common leaf/composite contract; src/main/java/composite/Drawing.java aggregates child shapes such as src/main/java/composite/Square.java and src/main/java/composite/Triangle.java.
Object Lifecycle and State Patterns
Prototype examples distinguish shallow and deep copy models through src/main/java/prototype/ShallowCopy.java, src/main/java/prototype/DeepCopy.java, and cloneable domain data such as src/main/java/prototype/DeepCloneStudent.java.
Singleton and shared-state variants are isolated examples: src/main/java/singleton/SingletonBestApproach.java, src/main/java/singleton/BillPughSingleton.java, and src/main/java/monostate/Monostate.java. They demonstrate different ownership/initialization boundaries for globally accessible state.
Safety, Absence, and Persistence Boundaries
Immutable state is modeled in src/main/java/immutable/Immutable.java; collection exposure is constrained by src/main/java/unmodifiable/UnModifiableList.java. Null Object handling avoids caller null checks via src/main/java/nullObject/ShapeFactory.java, src/main/java/nullObject/Shape.java, and src/main/java/nullObject/NullShapeSingleton.java.
Serialization examples define persistence/transport behavior around src/main/java/serialization/SerializationUtil.java, with serialized models including src/main/java/serialization/Employee.java and proxy-focused demonstration in src/main/java/serialization/SerializationProxyTest.java.
Main entry points: NotificationServiceFactory.java Notification factory · AnimalFactory.java Animal factory · SocketAdapterImpl.java Socket adapter · Drawing.java Drawing composite
Components 30
Build & execution
Independent Java demonstrations built with Maven.
- Maven build
pom.xml - Individual demo mains · Examples run independently rather than through one application bootstrap.
Creation patterns
- Animal factory
src/main/java/factory/AnimalFactory.java - Animal contract
src/main/java/factory/Animal.java - Dog and cat
src/main/java/factory/Dog.java - Notification factory · Selects a channel from notification type.
src/main/java/factory/notification/NotificationServiceFactory.java - Notification type
src/main/java/factory/notification/NotificationType.java - Notification contract
src/main/java/factory/notification/Notification.java - Email notification
src/main/java/factory/notification/EmailNotification.java
Composition patterns
- Pipeline demo
src/main/java/pipeline/Main.java - Ordered pipeline · Composes and executes processing steps in order.
src/main/java/pipeline/Pipeline.java - Step contract
src/main/java/pipeline/Step.java - Three pipeline stages
src/main/java/pipeline/StepOne.java - Payment client
src/main/java/stratergy/PaymentClient.java - Payment context
src/main/java/stratergy/PaymentContext.java - Payment strategy
src/main/java/stratergy/PaymentStrategy.java - Card and UPI strategies
src/main/java/stratergy/CreditCardStrategy.java - Socket adapter · Converts socket voltage into requested voltage forms.
src/main/java/adapter/SocketAdapterImpl.java - Socket voltage source
src/main/java/adapter/Socket.java - Socket adapter contract
src/main/java/adapter/SocketAdapter.java - Drawing composite
src/main/java/composite/Drawing.java - Shape contract
src/main/java/composite/Shape.java - Square and triangle
src/main/java/composite/Square.java
State & safety patterns
- Shallow and deep copy
src/main/java/prototype/DeepCopy.java - Singleton variants
src/main/java/singleton/SingletonBestApproach.java - Immutable state
src/main/java/immutable/Immutable.java - Null shape factory · Returns a null-object shape to avoid caller null checks.
src/main/java/nullObject/ShapeFactory.java - Null shape singleton
src/main/java/nullObject/NullShapeSingleton.java - Serialization utility
src/main/java/serialization/SerializationUtil.java - Serializable employee
src/main/java/serialization/Employee.java
Connections 25
- Maven build → Individual demo mains: builds
- Individual demo mains → Animal factory: runs examples
- Individual demo mains → Notification factory: runs examples
- Individual demo mains → Pipeline demo: includes
- Individual demo mains → Payment client: includes
- Animal factory → Animal contract: returns
- Dog and cat → Animal contract: implements
- Animal factory → Dog and cat: selects
- Notification factory → Notification type: maps from
- Notification factory → Notification contract: returns
- Email notification → Notification contract: implements
- Notification factory → Email notification: selects
- Pipeline demo → Ordered pipeline: drives
- Ordered pipeline → Step contract: composes
- Three pipeline stages → Step contract: implements
- Payment client → Payment context: uses
- Payment context → Payment strategy: delegates to
- Card and UPI strategies → Payment strategy: implements
- Socket adapter → Socket adapter contract: implements
- Socket adapter → Socket voltage source: adapts
- Drawing composite → Shape contract: implements
- Drawing composite → Square and triangle: aggregates
- Square and triangle → Shape contract: implements
- Null shape factory → Null shape singleton: returns
- Serialization utility → Serializable employee: serializes