A comprehensive repository dedicated to exploring, implementing, and visualizing classic software design patterns in modern JavaScript and C# environments.
Design patterns are documented solutions to common problems in software engineering. This project aims to provide:
- Clean Implementations: Minimalist and readable code across different languages.
- Interactive Demos: See the patterns in action with real-time UI (where applicable).
- Visual Learning: Mermaid diagrams and clear logical breakdowns.
The Chain of Responsibility allows a request to be passed along a chain of handlers. Each handler decides either to process the request or to pass it to the next handler.
graph TD
Start((Request)) --> Auth[Auth Handler]
Auth -- Success --> Cache[Cache Handler]
Auth -- Failure --> End((Blocked))
Cache -- Miss --> Logger[Logger Handler]
Cache -- Hit --> End
Logger --> Sender[Sender Handler]
Sender --> End
- Location:
chain/src/chain.js - Key Logic: Uses a base
Handlerclass. Concrete handlers includeAuthHandler,CacheHandler,LoggerHandler, andSenderHandler.
The Factory pattern is a creational pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.
graph LR
Client --> Factory[FoodFactory]
Factory --> Pizza[Pizza Object]
Factory --> Burger[Burger Object]
Factory --> Drink[Drink Object]
- Location:
factory/factory.js - Key Logic: A
FoodFactoryclass with a staticcreate(type)method that returns specialized food instances based on a mapping object.
The Prototype pattern is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects.
graph TD
Original[Original Object] --> Shallow[Shallow Copy]
Original --> Deep[Deep Copy]
subgraph References
Shallow -- Shares --> Engine[Same Engine Instance]
Deep -- New --> NewEngine[New Engine Instance]
end
- Location:
prototype/prototype.cs - Key Logic: A C# implementation in the
Carclass providingShallowCopy()andDeepCopy()to manage object duplication and reference handling.
The Proxy pattern provides a surrogate or placeholder for another object to control access to it.
graph TD
Client --> Proxy[DatabaseProxy]
Proxy -- Check Admin? --> RealDB[Real Database]
Proxy -- Denied --> Error[Access Denied]
- Location:
proxy/index.js - Key Logic: A
DatabaseProxythat intercepts calls to aDatabaseobject, performing role-based access control and lazy initialization.
The Singleton pattern ensures a class has only one instance and provides a global point of access to it.
graph TD
App1[Module A] --> Singleton
App2[Module B] --> Singleton
Singleton -- Same Instance --> Instance[Unique Instance]
- Location:
singleton/singleton.js - Key Logic: A
SettingsManagerthat uses a static instance check andObject.freezeto guarantee a single, immutable instance throughout the app lifecycle.
- Node.js (v18.x or higher)
- .NET SDK (for C# examples)
-
Clone the repository:
git clone https://github.com/ibrahimabdullaziz/Design-Patterns.git
-
To run the React demo:
cd chain npm install npm run dev
This project is licensed under the MIT License.
