Crafting brilliance through low-level design mastery.
The Low-Level-Design-Patterns project offers a collection of practical code examples showcasing various design patterns like Builder, Singleton, and Factory. It simplifies creating complex objects, managing database connections efficiently, and enabling dynamic behaviors in software systems. Ideal for developers seeking hands-on guidance in designing robust and scalable applications.
Folder | Summary | |
---|---|---|
⚙️ | Creational Patterns |
|
🔩 | Structural Patterns |
|
📄 | Behavioral Patterns |
|
└── Low-Level-Design-Patterns/
├── README.md
├── behavioral-design-pattern
│ ├── chain-of-responsibility-design-pattern.cpp
│ ├── command-design-pattern.cpp
│ ├── interpreter-design-pattern.cpp
│ ├── iterator-design-pattern.cpp
│ ├── mediator-design-pattern.cpp
│ ├── momento-design-pattern.cpp
│ ├── observer-design-pattern.cpp
│ ├── state-design-pattern.png
│ ├── strategy-design-pattern.cpp
│ ├── template-design-pattern.cpp
│ └── visitor-design-pattern.cpp
├── creational-design-pattern
│ ├── builder-design-pattern.cpp
│ ├── factory-design-pattern.cpp
│ └── singleton-design-pattern.cpp
└── structural-design-pattern
├── adapter-design-pattern.cpp
├── bridge-design-pattern.cpp
├── composite-design-pattern.cpp
├── decorator-design-pattern.cpp
├── facade-design-pattern.png
├── flyweight-design-pattern-with-singleton-concept.cpp
├── flyweight-design-pattern.cpp
└── proxy-design-pattern.cpp
LOW-LEVEL-DESIGN-PATTERNS/
creational-design-pattern
builder-design-pattern.cpp - Demonstrates the Builder design pattern for creating complex objects step by step
- Encapsulates object construction, enabling easy management and extension
- Concrete builders like EngineeringStudentBuilder and MBAStudentBuilder set specific attributes for different types of students
- Main function showcases building and printing details of Engineering and MBA students.singleton-design-pattern.cpp - Implements singleton design patterns for database connections with eager, lazy, and double-checked locking initialization methods
- Provides global access to single instances of classes, ensuring thread safety and efficient resource usage
- Demonstrates different strategies for creating and accessing singleton objects in the codebase architecture.factory-design-pattern.cpp - Implements Factory Pattern to create various shapes like Circle, Square, and Rectangle
- Defines Shape superclass with draw method and concrete classes for each shape
- ShapeFactory class generates shape objects based on input strings
- Demonstrates pattern usage by creating a Rectangle object and calling its draw method.
behavioral-design-pattern
strategy-design-pattern.cpp - Demonstrates the Strategy Design Pattern for dynamic driving behaviors in vehicles
- Encapsulates various driving strategies (e.g., Sport, Normal, Passenger) as separate classes
- The Vehicle class can change strategies dynamically, promoting flexibility and scalability without modifying the Vehicle class itself.template-design-pattern.cpp - Implements a Template Method Design Pattern for payment processing
- Defines a base class with common steps and abstract methods for subclasses to implement specific payment types
- Demonstrates sending money to a friend and a merchant by overriding the template methods
- Executed through instances of PayToFriend and PayToMerch classes.observer-design-pattern.cpp - Implements observer design pattern for stock updates
- Defines observables for iPhone and Samsung stocks, with mobile and email alert observers
- Demonstrates notifications to observers based on stock count changes.chain-of-responsibility-design-pattern.cpp - Implements a Chain of Responsibility design pattern for logging messages based on their severity levels
- The code defines different log processors for handling INFO, DEBUG, and ERROR messages in a chain
- By passing messages through the chain, it ensures that each message is processed by the appropriate log processor without the sender needing to know the specific handler.mediator-design-pattern.cpp - Demonstrates the Mediator Design Pattern, fostering loose coupling between objects by centralizing communication through a mediator
- Objects interact indirectly via the mediator, enhancing system maintainability and flexibility
- The code showcases how bidders in an auction place bids and receive notifications through the mediator, streamlining communication and reducing dependencies.interpreter-design-pattern.cpp - Demonstrates the Interpreter Design Pattern by evaluating complex mathematical expressions using terminal and non-terminal expressions within a defined context
- The code creates a context to store variable values, constructs expressions for multiplication and addition, and outputs the result of the expression evaluation.command-design-pattern.cpp - Implements the Command Design Pattern to decouple command execution from command producers
- Defines commands for an Air Conditioner, allowing operations like turning on/off and setting temperature
- Utilizes an invoker class to manage and execute commands, showcasing features like undo/redo functionality.visitor-design-pattern.cpp - Implements Visitor Design Pattern to separate operations (pricing, maintenance) from room classes
- Defines visitors for different room types to perform specific operations without modifying room classes
- Main function demonstrates pricing and maintenance operations on single, double, and deluxe rooms using respective visitor instances.iterator-design-pattern.cpp - Implements the Iterator Design Pattern to enable sequential access to a collection of books without exposing its structure
- The code defines classes for books, iterators, and libraries, showcasing how to iterate over and print book names in a library using an iterator.momento-design-pattern.cpp - Demonstrates the Memento Design Pattern by enabling objects to be restored to previous states without revealing implementation details
- The code showcases saving and restoring object states using Mementos managed by a CareTaker, facilitating undo/redo functionality within the project's architecture.
structural-design-pattern
flyweight-design-pattern.cpp - Demonstrates the Flyweight Design Pattern to optimize memory usage by sharing common data among similar objects
- The code defines interfaces for letters, concrete letter implementations, and a factory to manage object creation and reuse
- By creating and displaying letters using the factory, it showcases efficient memory utilization through object sharing.bridge-design-pattern.cpp - Demonstrates the Bridge Design Pattern by decoupling abstractions from implementations, allowing independent variation
- Defines breathing processes for land and water entities, showcasing how Dogs and Fish can use different implementors
- This promotes extensibility and flexibility in managing diverse living things.flyweight-design-pattern-with-singleton-concept.cpp - Demonstrates the Flyweight Design Pattern by efficiently managing memory usage through object sharing
- The code showcases the creation and reuse of letter objects using a Singleton Factory, emphasizing memory optimization for large quantities of similar objects.decorator-design-pattern.cpp - Implements the Decorator Design Pattern for pizzas, allowing dynamic addition of toppings to base pizza objects
- Demonstrates how to enhance pizza objects with Mushroom and Cheese toppings while maintaining scalability and reusability in the codebase architecture.adapter-design-pattern.cpp - Implements the Adapter Design Pattern to bridge incompatible interfaces, converting weight from pounds to kilograms
- The code creates classes for weighing machines in pounds and kilograms, demonstrating adaptation between the two units.proxy-design-pattern.cpp - Implements a Proxy Design Pattern to control access to an Employee Database
- The code defines classes for Employee, EmployeeDB, EmployeeDBImpl, and EmployeeDBProxy
- The proxy restricts access based on client permissions, allowing creation and retrieval of employee records
- The main function demonstrates creating an employee record and retrieving it based on client roles.composite-design-pattern.cpp - Demonstrates the Composite Design Pattern by creating a hierarchical structure of directories and files
- Allows uniform treatment of individual objects and compositions
- Enables representing part-whole hierarchies where files and directories are handled uniformly
- The code showcases how directories can contain files and subdirectories in a tree-like manner.
Before getting started with Low-Level-Design-Patterns, ensure your runtime environment meets the following requirements:
- Programming Language: CPP
Install Low-Level-Design-Patterns using one of the following methods:
Build from source:
- Clone the Low-Level-Design-Patterns repository:
❯ git clone https://github.com/samyakmehta28/Low-Level-Design-Patterns
- Navigate to the project directory:
❯ cd Low-Level-Design-Patterns
- 💬 Join the Discussions: Share your insights, provide feedback, or ask questions.
- 🐛 Report Issues: Submit bugs found or log feature requests for the
Low-Level-Design-Patterns
project. - 💡 Submit Pull Requests: Review open PRs, and submit your own PRs.
Contributing Guidelines
- Fork the Repository: Start by forking the project repository to your github account.
- Clone Locally: Clone the forked repository to your local machine using a git client.
git clone https://github.com/samyakmehta28/Low-Level-Design-Patterns
- Create a New Branch: Always work on a new branch, giving it a descriptive name.
git checkout -b new-feature-x
- Make Your Changes: Develop and test your changes locally.
- Commit Your Changes: Commit with a clear message describing your updates.
git commit -m 'Implemented new feature x.'
- Push to github: Push the changes to your forked repository.
git push origin new-feature-x
- Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
- Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
This project is protected under the SELECT-A-LICENSE License. For more details, refer to the LICENSE file.
-
I would like to express my sincere gratitude to Shreyansh Jain for his invaluable contributions through his YouTube playlist on Low-Level System Design. This collection of C++ implementations of various design patterns was primarily inspired by the examples presented in his videos. While I have closely followed the examples provided in his content, I have adapted and implemented them in C++.
-
You can find Shreyansh Jain's YouTube playlist here: Low-Level System Design Playlist.