Code Monkey home page Code Monkey logo

design_pattern's Introduction

Design Patterns

CMake

Minimal modern C++ implementation of design patterns in the book Design Patterns: Elements of Reusable Object-Oriented Software>

Author: PPM

Usage

Set-up

source setup.sh

Create a new class

create_class.py /path/to/dir/ ClassName

see also create_class.py -h

Testing with ctest

# in `build` folder
ctest -C Debug -VV

Creational

Abstract Factory

Builder

Factory Method

Template ConcreteCreator.

template <class ProductType>
class ConcreteCreator : public Creator {
public:
    ConcreteCreator();
    virtual Product* MakeProduct() override;
};

Prototype

Singleton

Generic Singleton.

template <typename Type, typename... Args>
class Singleton;
using MyClassSingleton = Singleton<MyClass, int, int>;
MyClassSingleton::Instance(800, 600);

Structural

Adapter

Class Adapter

class Adapter : public Target, private Adaptee

Bridge

Composite

Decorator

Façade

Singleton Façade. High-level interface.

Facade& Facade::Instance() noexcept {
    static Facade instance;
    return instance;
}

Flyweight

Proxy

Behavioral

Chain of Responsibility

Command

No undo or redo. FIFO.

Interpreter

Iterator

ConcreteAggregate is List; A fixed-capacity stack.

template <class Item>
class ConcreteAggregate : public Aggregate<Item> {
public:
    // ...
    void        Push(Item item) noexcept;
    void        Pop() noexcept;
    Item        Top() const;
    // ...
private:
    std::array<Item, MAX_CAPACITY> m_data;
};

Mediator

Manual connection to mediator

class Colleague {
public:
    virtual void Changed();
    virtual void ConnectTo(Mediator* mediator);
    // ...
};

Memento

Observer

State

State is friend class of Context.

Strategy

Template Method

Visitor

design_pattern's People

Watchers

Bowen Zhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.