├── Behavioral
├── Observer
│ ├── new
│ │ ├── Observer.cpp
│ │ ├── SaferObservable.cpp
│ │ ├── Observable.cpp
│ │ ├── Observer.hpp
│ │ ├── Observable.hpp
│ │ ├── headers.hpp
│ │ └── SaferObservable.hpp
│ ├── Observer.vcxproj.user
│ ├── Observer.vcxproj.filters
│ ├── observer3.cpp
│ ├── observer1.cpp
│ ├── ObserverCodingExercise.cpp
│ ├── observer2.cpp
│ └── observer_book.cpp
├── Mediator
│ ├── packages.config
│ ├── Mediator.vcxproj.user
│ ├── chatroom.h
│ ├── chat.cpp
│ ├── person.cpp
│ ├── person.h
│ ├── chatroom.cpp
│ ├── Mediator.vcxproj.filters
│ ├── MediatorCodingExercise.cpp
│ └── soccer.cpp
├── Iterator
│ ├── packages.config
│ ├── Iterator.vcxproj.user
│ ├── Iterator.vcxproj.filters
│ ├── facade.cpp
│ └── IteratorCodingExercise.cpp
├── State
│ ├── State.vcxproj.user
│ ├── State.vcxproj.filters
│ ├── classic.cpp
│ ├── StateCodingExercise.cpp
│ ├── msm.cpp
│ └── handmade.cpp
├── Command
│ ├── Command.vcxproj.user
│ ├── Command.vcxproj.filters
│ ├── CommandCodingExercise.cpp
│ ├── command_undo.cpp
│ └── command.cpp
├── Memento
│ ├── Memento.vcxproj.user
│ ├── Memento.vcxproj.filters
│ ├── MementoCodingExercise.cpp
│ └── memento.cpp
├── Strategy
│ ├── Strategy.vcxproj.user
│ ├── Strategy.vcxproj.filters
│ ├── strategy_static.cpp
│ ├── strategy_dynamic.cpp
│ └── StrategyCodingExercise.cpp
├── Visitor
│ ├── Visitor.vcxproj.user
│ ├── visitor.hpp
│ ├── Visitor.vcxproj.filters
│ ├── std_visit.cpp
│ ├── visitor_intrusive.cpp
│ ├── visitor_reflective.cpp
│ ├── multimethods.cpp
│ ├── model.hpp
│ ├── visitor_acyclic.cpp
│ ├── VisitorCodingExercise.cpp
│ ├── single_double.cpp
│ └── visitor.cpp
├── Interpreter
│ ├── Interpreter.vcxproj.user
│ ├── Interpreter.vcxproj.filters
│ └── InterpreterCodingExercise.cpp
├── NullObject
│ ├── NullObject.vcxproj.user
│ ├── NullObject.vcxproj.filters
│ └── null_object.cpp
├── TemplateMethod
│ ├── TemplateMethod.vcxproj.user
│ ├── TemplateMethod.vcxproj.filters
│ ├── template_method.cpp
│ └── TemplateMethodCodingExercise.cpp
└── ChainOfResponsibility
│ ├── ChainOfResponsibility.vcxproj.user
│ ├── ChainOfResponsibility.vcxproj.filters
│ ├── cor_broker.cpp
│ ├── cor_pointer.cpp
│ └── CoRCodingExercise.cpp
├── .gitattributes
├── Creational
├── Creational
│ ├── FactoryExercise.h
│ ├── Person.cpp
│ ├── HotDrinkFactory.h
│ ├── Creational.vcxproj.user
│ ├── TeaFactory.h
│ ├── Monostate.cpp
│ ├── capitals.txt
│ ├── CoffeeFactory.h
│ ├── PersonBuilder.cpp
│ ├── Facets.cpp
│ ├── HotDrink.h
│ ├── AbstractFactory.cpp
│ ├── PersonAddressBuilder.h
│ ├── PersonJobBuilder.h
│ ├── PersonBuilder.h
│ ├── Factory.cpp
│ ├── BoostDIDemo.hpp
│ ├── SingletonTests.cpp
│ ├── FactoryCodingExercise.cpp
│ ├── SingletonCodingExercise.cpp
│ ├── FactoryMethod.cpp
│ ├── DrinkFactory.h
│ ├── InnerFactory.cpp
│ ├── SRP.cpp
│ ├── PrototypeCodingExercise.cpp
│ ├── ISP.cpp
│ ├── LSP.cpp
│ ├── BoostDI.cpp
│ ├── MaybeMonad.cpp
│ ├── Person.h
│ ├── GroovyStyle.cpp
│ ├── Serialization.cpp
│ ├── DIP.cpp
│ ├── Singleton.h
│ ├── Builder.cpp
│ └── BuilderCodingExercise.cpp
├── Creational.tss
└── Creational.sln
├── Structural
├── Proxy
│ ├── .vscode
│ │ └── .browse.VC.db
│ ├── Proxy.vcxproj.user
│ ├── packages.config
│ ├── Proxy.vcxproj.filters
│ └── ProxyCodingExercise.cpp
├── Adapter
│ ├── .vs
│ │ └── Adapter
│ │ │ └── v14
│ │ │ └── .suo
│ ├── Adapter.vcxproj.user
│ ├── Adapter.vcxproj.filters
│ ├── AdapterCodingExercise.cpp
│ └── adapter.cpp
├── AdapterVisual
│ ├── AdapterVisual.aps
│ ├── AdapterVisual.rc
│ ├── res
│ │ ├── AdapterVisual.ico
│ │ └── AdapterVisual.rc2
│ ├── AdapterVisual.vcxproj.user
│ ├── stdafx.cpp
│ ├── targetver.h
│ ├── Resource.h
│ ├── AdapterVisual.h
│ ├── AdapterVisualDlg.h
│ ├── Geometry.h
│ ├── stdafx.h
│ ├── AdapterVisual.vcxproj.filters
│ └── AdapterVisual.cpp
├── Flyweight
│ ├── .vscode
│ │ └── .browse.VC.db
│ ├── Flyweight.vcxproj.user
│ ├── Flyweight.vcxproj.filters
│ ├── FlyweightCodingExercise.cpp
│ ├── capitalize.cpp
│ └── flyweight.cpp
├── NullObject
│ ├── .vscode
│ │ └── .browse.VC.db
│ ├── NullObject.vcxproj.user
│ ├── NullObject.vcxproj.filters
│ └── nullobject.cpp
├── Bridge
│ ├── Bridge.vcxproj.user
│ ├── Person.cpp
│ ├── Person.h
│ ├── Bridge.vcxproj.filters
│ ├── BridgeCodingExercise.cpp
│ └── bridge.cpp
├── Façade
│ ├── Façade.vcxproj.user
│ ├── Façade.vcxproj.filters
│ ├── Bloom.cpp
│ └── Console.h
├── Composite
│ ├── Composite.vcxproj.user
│ ├── Composite.vcxproj.filters
│ ├── graphics.h
│ ├── CompositeCodingExercise.cpp
│ ├── composite.cpp
│ ├── ArrayBackedProps.cpp
│ └── neurons.cpp
├── Decorator
│ ├── Decorator.vcxproj.user
│ ├── Decorator.vcxproj.filters
│ └── DecoratorCodingExercise.cpp
└── PingPongService
│ ├── appsettings.json
│ ├── wwwroot
│ └── web.config
│ ├── Properties
│ └── launchSettings.json
│ ├── Controllers
│ └── PingPongController.cs
│ ├── PingPongService.csproj
│ └── Startup.cs
├── README.md
├── Contributing.md
└── LICENSE.txt
/Behavioral/Observer/new/Observer.cpp:
--------------------------------------------------------------------------------
1 | #include "Observer.hpp"
2 |
--------------------------------------------------------------------------------
/Behavioral/Observer/new/SaferObservable.cpp:
--------------------------------------------------------------------------------
1 | #include "SaferObservable.hpp"
2 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/Behavioral/Observer/new/Observable.cpp:
--------------------------------------------------------------------------------
1 | #include "Observer.hpp"
2 | #include "Observable.hpp"
3 |
--------------------------------------------------------------------------------
/Creational/Creational/FactoryExercise.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | class FactoryExercise
4 | {
5 | public:
6 |
7 | };
8 |
--------------------------------------------------------------------------------
/Structural/Proxy/.vscode/.browse.VC.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/design-patterns-in-modern-cpp/HEAD/Structural/Proxy/.vscode/.browse.VC.db
--------------------------------------------------------------------------------
/Structural/Adapter/.vs/Adapter/v14/.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/design-patterns-in-modern-cpp/HEAD/Structural/Adapter/.vs/Adapter/v14/.suo
--------------------------------------------------------------------------------
/Structural/AdapterVisual/AdapterVisual.aps:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/design-patterns-in-modern-cpp/HEAD/Structural/AdapterVisual/AdapterVisual.aps
--------------------------------------------------------------------------------
/Structural/AdapterVisual/AdapterVisual.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/design-patterns-in-modern-cpp/HEAD/Structural/AdapterVisual/AdapterVisual.rc
--------------------------------------------------------------------------------
/Structural/Flyweight/.vscode/.browse.VC.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/design-patterns-in-modern-cpp/HEAD/Structural/Flyweight/.vscode/.browse.VC.db
--------------------------------------------------------------------------------
/Structural/NullObject/.vscode/.browse.VC.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/design-patterns-in-modern-cpp/HEAD/Structural/NullObject/.vscode/.browse.VC.db
--------------------------------------------------------------------------------
/Creational/Creational/Person.cpp:
--------------------------------------------------------------------------------
1 | #include "Person.h"
2 | #include "PersonBuilder.h"
3 |
4 | PersonBuilder Person::create()
5 | {
6 | return PersonBuilder{};
7 | }
--------------------------------------------------------------------------------
/Structural/AdapterVisual/res/AdapterVisual.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/design-patterns-in-modern-cpp/HEAD/Structural/AdapterVisual/res/AdapterVisual.ico
--------------------------------------------------------------------------------
/Structural/AdapterVisual/res/AdapterVisual.rc2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Apress/design-patterns-in-modern-cpp/HEAD/Structural/AdapterVisual/res/AdapterVisual.rc2
--------------------------------------------------------------------------------
/Behavioral/Mediator/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Creational/Creational/HotDrinkFactory.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "HotDrink.h"
3 |
4 | struct HotDrinkFactory
5 | {
6 | virtual unique_ptr make() const = 0;
7 | };
--------------------------------------------------------------------------------
/Behavioral/Iterator/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/State/State.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/Bridge/Bridge.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/Façade/Façade.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/Proxy/Proxy.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/Command/Command.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/Iterator/Iterator.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/Mediator/Mediator.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/Memento/Memento.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/Observer/Observer.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/Strategy/Strategy.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/Visitor/Visitor.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/Adapter/Adapter.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/Interpreter/Interpreter.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/NullObject/NullObject.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Creational/Creational/Creational.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/Composite/Composite.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/Decorator/Decorator.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/Flyweight/Flyweight.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/NullObject/NullObject.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/AdapterVisual/AdapterVisual.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Behavioral/TemplateMethod/TemplateMethod.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Creational/Creational/TeaFactory.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "HotDrinkFactory.h"
3 |
4 | struct TeaFactory : HotDrinkFactory
5 | {
6 | unique_ptr make() const override {
7 | return make_unique();
8 | }
9 | };
--------------------------------------------------------------------------------
/Behavioral/ChainOfResponsibility/ChainOfResponsibility.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Structural/PingPongService/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Verbose",
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Structural/Façade/Façade.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Behavioral/Memento/Memento.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Behavioral/Interpreter/Interpreter.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Structural/AdapterVisual/stdafx.cpp:
--------------------------------------------------------------------------------
1 |
2 | // stdafx.cpp : source file that includes just the standard includes
3 | // AdapterVisual.pch will be the pre-compiled header
4 | // stdafx.obj will contain the pre-compiled type information
5 |
6 | #include "stdafx.h"
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural/Decorator/Decorator.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Structural/NullObject/NullObject.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Behavioral/NullObject/NullObject.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Behavioral/TemplateMethod/TemplateMethod.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Creational/Creational/Monostate.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | class Printer
4 | {
5 | static int id;
6 | public:
7 | int get_id() const { return id; }
8 | void set_id(int value) { id = value; }
9 | };
10 |
11 | int main_73468()
12 | {
13 | Printer p;
14 |
15 | return 0;
16 | }
--------------------------------------------------------------------------------
/Creational/Creational/capitals.txt:
--------------------------------------------------------------------------------
1 | Tokyo
2 | 33200000
3 | New York
4 | 17800000
5 | Sao Paulo
6 | 17700000
7 | Seoul
8 | 17500000
9 | Mexico City
10 | 17400000
11 | Osaka
12 | 16425000
13 | Manila
14 | 14750000
15 | Mumbai
16 | 14350000
17 | Delhi
18 | 14300000
19 | Jakarta
20 | 14250000
--------------------------------------------------------------------------------
/Behavioral/Command/Command.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Structural/Proxy/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Structural/Flyweight/Flyweight.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Behavioral/Mediator/chatroom.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | struct ChatRoom
4 | {
5 | vector people; // assume append-only
6 |
7 | void join(Person* p);
8 | void broadcast(const string& origin, const string& message);
9 | void message(const string& origin, const string& who, const string& message);
10 | };
11 |
--------------------------------------------------------------------------------
/Behavioral/Strategy/Strategy.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Creational/Creational/CoffeeFactory.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include "HotDrink.h"
4 | #include "HotDrinkFactory.h"
5 |
6 | struct HotDrink;
7 |
8 | struct CoffeeFactory : HotDrinkFactory
9 | {
10 | unique_ptr make() const override
11 | {
12 | return make_unique();
13 | }
14 | };
--------------------------------------------------------------------------------
/Structural/Proxy/Proxy.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Behavioral/ChainOfResponsibility/ChainOfResponsibility.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Behavioral/Observer/new/Observer.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | template struct Observer
5 | {
6 | virtual void field_changed(
7 | T& source, // reference to the object that changed
8 | const std::string& field_name // name of field (property) that changed
9 | ) = 0;
10 | };
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Structural/Adapter/Adapter.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Structural/AdapterVisual/targetver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // Including SDKDDKVer.h defines the highest available Windows platform.
4 |
5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7 |
8 | #include
9 |
--------------------------------------------------------------------------------
/Creational/Creational/PersonBuilder.cpp:
--------------------------------------------------------------------------------
1 | #include "PersonBuilder.h"
2 | #include "PersonAddressBuilder.h"
3 | #include "PersonJobBuilder.h"
4 |
5 | PersonAddressBuilder PersonBuilderBase::lives() const
6 | {
7 | return PersonAddressBuilder{ person };
8 | }
9 |
10 | PersonJobBuilder PersonBuilderBase::works() const
11 | {
12 | return PersonJobBuilder{ person };
13 | }
14 |
--------------------------------------------------------------------------------
/Behavioral/State/State.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Structural/Bridge/Person.cpp:
--------------------------------------------------------------------------------
1 | #include "Person.h"
2 |
3 | struct Person::PersonImpl
4 | {
5 | void greet(Person* p);
6 | };
7 |
8 | void Person::PersonImpl::greet(Person* p)
9 | {
10 | printf("hello %s", p->name.c_str());
11 | }
12 |
13 | Person::Person()
14 | : impl(new PersonImpl)
15 | {
16 | }
17 |
18 | Person::~Person()
19 | {
20 | delete impl;
21 | }
22 |
23 | void Person::greet()
24 | {
25 | impl->greet(this);
26 | }
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Structural/Composite/Composite.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Structural/PingPongService/wwwroot/web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Behavioral/Observer/Observer.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Structural/Bridge/Person.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | struct Person
5 | {
6 | std::string name;
7 |
8 | class PersonImpl;
9 | PersonImpl *impl; // bridge - not necessarily inner class, can vary
10 |
11 | Person();
12 | ~Person();
13 |
14 | void greet();
15 | };
16 |
17 | // pimpl
18 | // binary interfaces are fragile; this removes most of the internals to a separate class
19 | // prevents recompilation of sources reliant on the header
--------------------------------------------------------------------------------
/Behavioral/Iterator/Iterator.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Apress Source Code
2 |
3 | This repository accompanies [*Design Patterns in Modern C++*](http://www.apress.com/9781484236024) by Dmitri Nesteruk (Apress, 2018).
4 |
5 | [comment]: #cover
6 |
7 | Download the files as a zip using the green button, or clone the repository to your machine using Git.
8 |
9 | ## Releases
10 |
11 | Release v1.0 corresponds to the code in the published book, without corrections or updates.
12 |
13 | ## Contributions
14 |
15 | See the file Contributing.md for more information on how you can contribute to this repository.
--------------------------------------------------------------------------------
/Creational/Creational/Facets.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | using namespace std;
7 |
8 | #include "Person.h"
9 | #include "PersonBuilder.h"
10 | #include "PersonAddressBuilder.h"
11 | #include "PersonJobBuilder.h"
12 |
13 | int main__()
14 | {
15 | Person p = Person::create()
16 | .lives().at("123 London Road").with_postcode("SW1 1GB").in("London")
17 | .works().at("PragmaSoft").as_a("Consultant").earning(10e6);
18 |
19 | cout << p << endl;
20 | getchar();
21 | return 0;
22 | }
--------------------------------------------------------------------------------
/Creational/Creational.tss:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | C:\Dropbox\Courses\Pluralsight - C++ Design Patterns\Creational\Creational\Serialization.cpp
6 |
7 |
8 | C:\Dropbox\Courses\Pluralsight - C++ Design Patterns\Creational\Creational\Prototype.cpp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Behavioral/Mediator/chat.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | using namespace std;
5 |
6 | #include "person.h"
7 | #include "chatroom.h"
8 |
9 | int main__()
10 | {
11 | ChatRoom room;
12 |
13 | Person john{ "john" };
14 | Person jane{ "jane" };
15 | room.join(&john);
16 | room.join(&jane);
17 | john.say("hi room");
18 | jane.say("oh, hey john");
19 |
20 | Person simon("simon");
21 | room.join(&simon);
22 | simon.say("hi everyone!");
23 |
24 | jane.pm("simon", "glad you could join us, simon");
25 |
26 | getchar();
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/Behavioral/Mediator/person.cpp:
--------------------------------------------------------------------------------
1 | #include "person.h"
2 | #include "chatroom.h"
3 |
4 | Person::Person(const string& name) : name(name)
5 | {
6 | }
7 |
8 | void Person::receive(const string& origin, const string& message)
9 | {
10 | string s{ origin + ": \"" + message + "\"" };
11 | cout << "[" << name << "'s chat session] " << s << "\n";
12 | chat_log.emplace_back(s);
13 | }
14 |
15 | void Person::say(const string& message) const
16 | {
17 | room->broadcast(name, message);
18 | }
19 |
20 | void Person::pm(const string& who, const string& message) const
21 | {
22 | room->message(name, who, message);
23 | }
24 |
--------------------------------------------------------------------------------
/Structural/AdapterVisual/Resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by AdapterVisual.rc
4 | //
5 | #define IDR_MAINFRAME 128
6 | #define IDM_ABOUTBOX 0x0010
7 | #define IDD_ABOUTBOX 100
8 | #define IDS_ABOUTBOX 101
9 | #define IDD_ADAPTERVISUAL_DIALOG 102
10 |
11 | // Next default values for new objects
12 | //
13 | #ifdef APSTUDIO_INVOKED
14 | #ifndef APSTUDIO_READONLY_SYMBOLS
15 |
16 | #define _APS_NEXT_RESOURCE_VALUE 129
17 | #define _APS_NEXT_CONTROL_VALUE 1000
18 | #define _APS_NEXT_SYMED_VALUE 101
19 | #define _APS_NEXT_COMMAND_VALUE 32771
20 | #endif
21 | #endif
22 |
--------------------------------------------------------------------------------
/Behavioral/Visitor/visitor.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | struct Paragraph;
5 | struct BoldParagraph;
6 | struct ListItem;
7 | struct List;
8 | struct Div;
9 |
10 | struct Visitor
11 | {
12 | virtual ~Visitor() = default;
13 |
14 | virtual void visit(const Paragraph& p) = 0;
15 | virtual void visit(const BoldParagraph& p) = 0;
16 | virtual void visit(const ListItem& li) = 0;
17 | // here is the problem
18 | virtual void visit(const List& l) = 0;
19 | virtual void visit(const Div& div) = 0;
20 |
21 | // need to add another visit function whenever a new type is added
22 |
23 | virtual std::string str() const = 0;
24 | };
25 |
--------------------------------------------------------------------------------
/Creational/Creational/HotDrink.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include