Skip to content

MarkoMilenovic01/DesignPatterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Patterns in C++

This repository contains C++ implementations of classical Object-Oriented Design Patterns, developed as part of the OOP2 (Object-Oriented Programming 2) course.

The goal of this project is to demonstrate how and why design patterns are used, using clear, minimal, and educational C++ examples.


📂 Repository Organization

Each folder represents one or more design patterns, implemented independently for clarity and learning purposes.

Patterns are grouped according to the Gang of Four (GoF) classification:

  • Creational
  • Structural
  • Behavioral

🧩 Creational Design Patterns

Creational patterns focus on how objects are created, helping to make a system independent of how its objects are instantiated.

Singleton

Ensures that a class has only one instance and provides a global access point to it.
Used when exactly one object is needed to coordinate actions (e.g. configuration, logging).

Builder

Separates the construction of a complex object from its representation.
Allows the same construction process to create different representations.

Factory Method

Defines an interface for creating objects, but allows subclasses to decide which class to instantiate.
Promotes loose coupling by eliminating direct object creation.

Abstract Factory

Provides an interface for creating families of related objects without specifying their concrete classes.
Useful when systems must be independent of how products are created.

Prototype

Creates new objects by cloning existing ones, rather than instantiating new classes.
Efficient when object creation is expensive or complex.


🏗 Structural Design Patterns

Structural patterns deal with how classes and objects are composed to form larger structures while keeping them flexible.

Adapter

Allows incompatible interfaces to work together by converting one interface into another expected by the client.

Bridge

Decouples an abstraction from its implementation so that both can vary independently.

Composite

Composes objects into tree structures to represent part–whole hierarchies.
Allows clients to treat individual objects and compositions uniformly.

Decorator

Dynamically adds new responsibilities to objects without modifying their structure.
A flexible alternative to subclassing.

Facade

Provides a simplified interface to a complex subsystem, reducing dependencies.

Proxy

Provides a placeholder or surrogate for another object to control access to it.


🔄 Behavioral Design Patterns

Behavioral patterns focus on communication between objects, defining how responsibilities are distributed.

Iterator

Provides a way to access elements of a collection sequentially without exposing its internal structure.

Interpreter

Defines a representation for a language grammar and an interpreter to evaluate sentences in the language.

Chain of Responsibility

Passes a request along a chain of handlers, allowing multiple objects to process the request without coupling the sender to a specific receiver.

Command

Encapsulates a request as an object, allowing parameterization, queuing, and logging of requests.

Observer

Defines a one-to-many dependency so that when one object changes state, all dependents are notified automatically.

Mediator

Centralizes complex communications between objects into a mediator, reducing direct dependencies.

State

Allows an object to change its behavior when its internal state changes.
The object appears to change its class.

Strategy

Defines a family of algorithms, encapsulates each one, and makes them interchangeable at runtime.

Template Method

Defines the skeleton of an algorithm, allowing subclasses to redefine specific steps.

Visitor

Separates algorithms from object structures by moving operations into a visitor object.

Memento

Captures and restores an object’s internal state without violating encapsulation.


🎯 Project Goals

  • Learn object-oriented design principles through real implementations
  • Understand when and why to apply each design pattern
  • Improve code:
    • Maintainability
    • Flexibility
    • Readability
  • Practice clean C++ design

🛠 Technologies & Concepts

  • Language: C++
  • Paradigm: Object-Oriented Programming
  • Key concepts:
    • Interfaces (abstract base classes)
    • Polymorphism
    • Composition over inheritance
    • SOLID principles
    • Decoupled architecture

▶️ How to Run

  1. Clone the repository:
    git clone https://github.com/MarkoMilenovic01/Design-Patterns.git

About

A collection of classic object-oriented design patterns implemented in C++.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages