Skip to content

A comprehensive collection of C++ design pattern implementations including Creational, Structural, and Behavioral patterns with detailed documentation and examples.

License

Notifications You must be signed in to change notification settings

alloydsa/Low-Level-Design-Patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Low-Level Design Patterns in C++

This repository contains implementations of various design patterns in C++. Design patterns are reusable solutions to commonly occurring problems in software design and development.

📋 Table of Contents

🎯 Overview

Design patterns help developers write more maintainable, flexible, and reusable code. This collection demonstrates the implementation of classic Gang of Four (GoF) design patterns using modern C++ practices.

🚀 Design Patterns Included

Creational Patterns

  • Singleton Pattern - Ensures only one instance of a class exists
  • Factory Pattern - Creates objects without specifying exact classes
  • Builder Pattern - Constructs complex objects step by step
  • Prototype Pattern - Creates objects by cloning existing instances

Structural Patterns

  • Adapter Pattern - Allows incompatible interfaces to work together
  • Bridge Pattern - Separates abstraction from implementation
  • Composite Pattern - Composes objects into tree structures
  • Decorator Pattern - Adds behavior to objects dynamically
  • Facade Pattern - Provides simplified interface to complex subsystem
  • Flyweight Pattern - Shares objects efficiently to support large numbers
  • Proxy Pattern - Provides placeholder/surrogate for another object

Behavioral Patterns

  • Observer Pattern - Defines one-to-many dependency between objects
  • Strategy Pattern - Defines family of algorithms and makes them interchangeable
  • Template Method Pattern - Defines skeleton of algorithm in base class
  • Iterator Pattern - Provides way to access elements sequentially

Additional Patterns

  • Abstraction Design - Demonstrates abstraction principles

🛠️ How to Use

  1. Clone the repository:

    git clone https://github.com/alloydsa/Low-Level-Design-Patterns.git
    cd Low-Level-Design-Patterns
  2. Choose a pattern to study: Each .cpp file contains a complete implementation of a design pattern with example usage.

  3. Compile and run:

    g++ -std=c++11 "pattern-name.cpp" -o pattern-name
    ./pattern-name

⚙️ Compilation Instructions

Requirements

  • C++11 or later
  • GCC, Clang, or any modern C++ compiler

Individual Pattern Compilation

# Example: Compile Singleton Pattern
g++ -std=c++11 "singleton design pattern.cpp" -o singleton
./singleton

# Example: Compile Factory Pattern
g++ -std=c++11 "factory design pattern.cpp" -o factory
./factory

Compile All Patterns (Using the provided script)

We've included a handy compilation script that compiles all patterns at once:

# Make the script executable (if not already)
chmod +x compile_all.sh

# Compile all patterns
./compile_all.sh

# Run a specific pattern
./compiled/singleton_design_pattern
./compiled/factory_design_pattern

📚 Pattern Categories

Creational Patterns

Focus on object creation mechanisms, trying to create objects in a manner suitable to the situation.

Structural Patterns

Deal with object composition, creating relationships between objects to form larger structures.

Behavioral Patterns

Focus on communication between objects and the assignment of responsibilities between objects.

🎓 Learning Resources

  • Gang of Four Book: "Design Patterns: Elements of Reusable Object-Oriented Software"
  • Head First Design Patterns: Great for beginners
  • Refactoring Guru: Excellent online resource for design patterns

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingPattern)
  3. Commit your changes (git commit -m 'Add some AmazingPattern')
  4. Push to the branch (git push origin feature/AmazingPattern)
  5. Open a Pull Request

📝 Code Style Guidelines

  • Use meaningful variable and function names
  • Include comments explaining the pattern's intent
  • Provide example usage in the main() function
  • Follow consistent indentation (4 spaces)
  • Include output examples in comments

📄 File Naming Convention

  • Pattern files follow the format: pattern-name design pattern.cpp
  • Each file is self-contained and executable
  • Clear separation between pattern implementation and usage example

🏗️ Project Structure

Low-Level-Design-Patterns/
├── README.md
├── LICENSE
├── .gitignore
├── compile_all.sh
├── abstraction design.cpp
├── adapter design pattern.cpp
├── bridge design pattern.cpp
├── builder design pattern.cpp
├── composite design pattern.cpp
├── Decorator design pattern.cpp
├── facade design pattern.cpp
├── factory design pattern.cpp
├── flyweight design pattern.cpp
├── iterator design pattern.cpp
├── observer design pattern.cpp
├── prototype design pattern.cpp
├── proxy design pattern.cpp
├── singleton design pattern.cpp
├── strategy design pattern.cpp
├── template design pattern.cpp
└── compiled/ (generated after running compile_all.sh)

📊 Examples Output

Each pattern includes example output to demonstrate its functionality:

// Example from Singleton Pattern
Singleton instance created.
Hello from Singleton!
Same instance: Yes

🔧 Troubleshooting

Common Issues:

  • Compilation errors: Ensure you're using C++11 or later
  • Missing headers: Make sure all #include statements are present
  • Linking issues: Most patterns are header-only and don't require external libraries

📞 Contact

For questions, suggestions, or discussions about design patterns, feel free to open an issue in this repository.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Happy Coding! 🚀

This repository is maintained for educational purposes and demonstrates fundamental design patterns in C++.

About

A comprehensive collection of C++ design pattern implementations including Creational, Structural, and Behavioral patterns with detailed documentation and examples.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published