diff --git a/CMakeLists.txt b/CMakeLists.txt index 77ff4f3..fc15cea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,7 +111,9 @@ set(APP_SOURCES "src/patterns/behavioral/Observer.cpp" "src/patterns/creational/Singleton.cpp" "src/patterns/creational/FactoryMethod.cpp" + "src/patterns/creational/AbstractFactory.cpp" "src/patterns/creational/Builder.cpp" + "src/patterns/creational/Prototype.cpp" ) # Test files diff --git a/docs/uml/patterns_creational_abstractfactory.drawio.svg b/docs/uml/patterns_creational_abstractfactory.drawio.svg new file mode 100644 index 0000000..9a3bd9b --- /dev/null +++ b/docs/uml/patterns_creational_abstractfactory.drawio.svg @@ -0,0 +1,4 @@ + + + +
Client
+ clientCode(IProductFactory* factory): type
main:
{
 IProduct factory* factory = new WindowsProductFactory();
 clientCode(factory);
}

clientCode:
{
 IGdbProduct* gdb = factory->createGdbProduct();
// do some logics with gdb
 ICMakeProduct* cmake = factory->createCmakeProduct();
//
}

<<Interface>>
IGdbProduct


+ method(Type): Type

+ launch(): Type

LinuxGdbProduct
+ field: type
+ launch(): Type
WindowGdbProduct
+ field: type
+ launch(): Type
MacOsGdbProduct
+ field: type
+ launch(): Type

<<Interface>>
IProductFactory


+ createGdbProduct(Type): IGdbProduct*

createCMakeProduct(Type): ICMakeProduct*


LinuxProductFactory
+ field: type

+ createGdbProduct(Type): IGdbProduct*

createCMakeProduct(Type): ICMakeProduct*

WindowsProductFactory
+ field: type

+ createGdbProduct(Type): IGdbProduct*

createCMakeProduct(Type): ICMakeProduct*

MacOsProductFactory
+ field: type

+ createGdbProduct(Type): IGdbProduct*

createCMakeProduct(Type): ICMakeProduct*

1
Use
create-gdb
{
 // to create the concrete product 
 return new MacOsGdbProduct();
}

create-cmake
{
 // to create the concrete product 
 return new MacOsCMakeProduct();
}

<<Interface>>
ICmakeProduct


+ method(Type): Type

+ launch(): Type

LinuxCMakeProduct
+ field: type
+ launch(): Type
WindowCMakeProduct
+ field: type
+ launch(): Type
MacOsCMakeProduct
+ field: type
+ launch(): Type
Text
1
\ No newline at end of file diff --git a/docs/uml/patterns_creational_factorymethod.drawio.svg b/docs/uml/patterns_creational_factorymethod.drawio.svg index 37de042..d92db5c 100644 --- a/docs/uml/patterns_creational_factorymethod.drawio.svg +++ b/docs/uml/patterns_creational_factorymethod.drawio.svg @@ -1,4 +1,4 @@ -
Client
+ clientCode(IGdbCreator* creator): type
main:
{
 IGdbCreator* creator= new WindowsGdbCreator();
 clientCode(creator);
}

clientCode:
{
creator->launch();
}

<<Interface>>
IGdbProduct


+ method(Type): Type

+ launch(): Type

LinuxGdbProduct
+ field: type
+ launch(): Type
WindowGdbProduct
+ field: type
+ launch(): Type
MacOsGdbProduct
+ field: type
+ launch(): Type

<<Interface>>
IGdbCreator


+ factoryMethod(Type): IGdbProduct*

+ launch(): Type

<<Abstract>>
AbstractGdbCreator


+ launch(): Type

LinuxGdbCreator
+ field: type

+ factoryMethod(Type): IGdbProduct*


WindowsGdbCreator
+ field: type

+ factoryMethod(Type): IGdbProduct*


MacOsGdbCreator
+ field: type

+ factoryMethod(Type): IGdbProduct*


1
Extends
Extends
Extends
Use
lauch:
{
// execute the complex logics
pacman -Syu mingw-w64-x86_64-gdb && gdb --version
}
lauch:
{
IGdbProduct* gdb = this-> templateMethod();
if(gdb != nullptr){
 gdb->launch();
 delete gdb;
 }
}
factoryMethod:
{
 // to create the concrete product 
 return new MacOsGdbProduct();
}
\ No newline at end of file +
Client
+ clientCode(IGdbFactory* f): type
main:
{
 IGdbCreator* gdbFactory= new WindowsGdbFactory();
 clientCode(gdbFactory);
}

clientCode:
{
f->launch();
}

<<Interface>>
IGdbProduct


+ method(Type): Type

+ launch(): Type

LinuxGdbProduct
+ field: type
+ launch(): Type
WindowGdbProduct
+ field: type
+ launch(): Type
MacOsGdbProduct
+ field: type
+ launch(): Type

<<Interface>>
IGdbFactory


+ factoryMethod(Type): IGdbProduct*

+ launch(): Type

<<Abstract>>
AbstractGdbFactory


+ launch(): Type

LinuxGdbFactory
+ field: type

+ factoryMethod(Type): IGdbProduct*


WindowsGdbFactory
+ field: type

+ factoryMethod(Type): IGdbProduct*


MacOsGdbFactory
+ field: type

+ factoryMethod(Type): IGdbProduct*


1
Extends
Extends
Extends
Use
lauch:
{
// execute the complex logics
pacman -Syu mingw-w64-x86_64-gdb && gdb --version
}
lauch:
{
IGdbProduct* gdb = this-> templateMethod();
if(gdb != nullptr){
 gdb->launch();
 delete gdb;
 }
}
factoryMethod:
{
 // to create the concrete product 
 return new MacOsGdbProduct();
}
\ No newline at end of file diff --git a/docs/uml/patterns_creational_prototype.drawio.svg b/docs/uml/patterns_creational_prototype.drawio.svg new file mode 100644 index 0000000..aee15a9 --- /dev/null +++ b/docs/uml/patterns_creational_prototype.drawio.svg @@ -0,0 +1,4 @@ + + + +
main:
{
 ExtensionPrototypeRegistry* registry = new ExtensionPrototypeRegistry();
 registry->registerExtension("id.logger",new LoggerExtensionPrototype()); 
 registry->registerExtension("id.launch",new LaunchExtensionPrototype()); 
 
 clientCode(registry);
}

clientCode:
{
 IExtensionPrototype* e1 = registry->createExtension("id.logger");
 e1->execute();
 ..
 IExtensionPrototype* en = registry->createExtension("id.logger");
}
Client
+ clientCode(ExtensionPrototypeRegistry* r)
Use
ExtensionPrototypeRegistry
- m_prototypes: map<string,IExtensionPrototype*>
+ registerExtension(string id, IExtensionPrototype* p): type
+ createExtension(string id): IExtensionPrototype*

<<Interface>>
IExtensionPrototype


+ clone(Type): IExtensionPrototype*

+ execute(Type): Type

LoggerExtensionPrototype


LaunchExtensionPrototype


0..*
clone:
{
 return new LaunchExtensionPrototype(*this);
}
create:
{
 IExentionPrototype* p = m_prototypes.get(id);
 return p->clone();
}
\ No newline at end of file diff --git a/src/core/datatypes/class/CConstructors.cpp b/src/core/datatypes/class/CConstructors.cpp index 57947f6..b119d30 100644 --- a/src/core/datatypes/class/CConstructors.cpp +++ b/src/core/datatypes/class/CConstructors.cpp @@ -302,8 +302,8 @@ void constructers() { } } // namespace Move -struct CConstructorsAutoRuner { - CConstructorsAutoRuner() { +struct CConstructorsAutoRunner { + CConstructorsAutoRunner() { InitializerList::constructers(); Default::constructers(); Delegate::constructors(); @@ -312,4 +312,4 @@ struct CConstructorsAutoRuner { } }; -static CConstructorsAutoRuner instance; +static CConstructorsAutoRunner instance; diff --git a/src/core/datatypes/class/CDestructors.cpp b/src/core/datatypes/class/CDestructors.cpp index 06afc00..1e3a651 100644 --- a/src/core/datatypes/class/CDestructors.cpp +++ b/src/core/datatypes/class/CDestructors.cpp @@ -57,11 +57,11 @@ void destructers() { } } // namespace Virtual -struct CDestructorsAutoRuner { - CDestructorsAutoRuner() { +struct CDestructorsAutoRunner { + CDestructorsAutoRunner() { Basic::destructers(); Virtual::destructers(); } }; -static CDestructorsAutoRuner instance; +static CDestructorsAutoRunner instance; diff --git a/src/core/datatypes/class/RoleOfThreeFiveZero.cpp b/src/core/datatypes/class/RoleOfThreeFiveZero.cpp index 59374c7..9ba2a93 100644 --- a/src/core/datatypes/class/RoleOfThreeFiveZero.cpp +++ b/src/core/datatypes/class/RoleOfThreeFiveZero.cpp @@ -171,7 +171,7 @@ class Model { // noexcept is a specifier that indicates a function will not throw // exceptions. Model(Model&& other) noexcept - : cstring(std::exchange(other.cstring, nullptr)){}; + : cstring(std::exchange(other.cstring, nullptr)) {}; // V. move assignment Model& operator=(Model&& other) noexcept { @@ -271,9 +271,9 @@ void run() { } } // namespace RoleOfZero } // namespace -struct RoleOfThreeFiveZeroAutoRuner { +struct RoleOfThreeFiveZeroAutoRunner { // Virtual default destructor: Does not break Rule of Three, Five, or Zero - RoleOfThreeFiveZeroAutoRuner() { + RoleOfThreeFiveZeroAutoRunner() { Problem::run(); RoleOfThree::run(); RoleOfFive::run(); @@ -281,4 +281,4 @@ struct RoleOfThreeFiveZeroAutoRuner { } }; -static RoleOfThreeFiveZeroAutoRuner instance; \ No newline at end of file +static RoleOfThreeFiveZeroAutoRunner instance; \ No newline at end of file diff --git a/src/patterns/creational/AbstractFactory.cpp b/src/patterns/creational/AbstractFactory.cpp index 3a0767f..0ed94b7 100644 --- a/src/patterns/creational/AbstractFactory.cpp +++ b/src/patterns/creational/AbstractFactory.cpp @@ -4,24 +4,170 @@ // families of related objects without specifying their concrete classes. // Appicability: // (*) when your code needs to work with various families of related products, -// but you don’t want it to depend on the concrete classes +// but you don’t want it to depend on the concrete classes // of those products—they might be unknown beforehand or you simply want to // allow for future extensibility. // (**) when you have a class with a set of Factory Methods that blur its -// primary responsibility. +// primary responsibility. -// UML: docs/uml/patterns_behavioral_iterator.drawio.svg +// UML: docs/uml/patterns_creational_abstractfactory.drawio.svg #include +#include +namespace { +namespace AbstractFactory { +/** + * The Product interface declares the operations that all concrete products must + * implement. + */ +class IGdbProduct { + public: + virtual ~IGdbProduct() = default; + virtual void launch() const = 0; +}; -namespace {} +/** + * Concrete Products provide various implementations of the Product interface. + */ +class LinuxGdbProduct : public IGdbProduct { + public: + void launch() const override { + std::cout + << "\tsudo apt update && sudo apt install -y gdb && gdb --version\n"; + } +}; -// struct SingletonAutoRuner -// { -// SingletonAutoRuner() -// { -// std::cout << "\n--- Singleton Pattern Example ---\n"; -// } -// }; +class WindowsGdbProduct : public IGdbProduct { + public: + void launch() const override { + std::cout << "\tpacman -Syu mingw-w64-x86_64-gdb && gdb --version\n"; + } +}; -// static SingletonAutoRuner instance; \ No newline at end of file +class MacOsGdbProduct : public IGdbProduct { + public: + void launch() const override { + std::cout << "\tbrew install gdb && gdb --version\n"; + } +}; + +class ICMakeProduct { + public: + virtual ~ICMakeProduct() = default; + virtual void launch() const = 0; +}; + +class LinuxCMakeProduct : public ICMakeProduct { + public: + void launch() const override { + std::cout << "\tsudo apt update && sudo apt install -y cmake && cmake " + "--version\n"; + } +}; + +class WindowsCMakeProduct : public ICMakeProduct { + public: + void launch() const override { + std::cout << "\tpacman -Syu cmake && cmake --version\n"; + } +}; + +class MacOsCMakeProduct : public ICMakeProduct { + public: + void launch() const override { + std::cout << "\tbrew install cmake && cmake --version\n"; + } +}; + +// =================================================================================== + +/* + * Abstract Factory + * provides an abstract interface for creating a family of products + */ +class IProductAbstractFactory { + public: + virtual ~IProductAbstractFactory() = default; + virtual IGdbProduct* createGdbProduct() = 0; + virtual ICMakeProduct* createCMakeProduct() = 0; +}; + +/* + * Concrete Factory + * each concrete factory create a family of products and client uses + * one of these factories so it never has to instantiate a product object + */ +class WindowsProductFactory : public IProductAbstractFactory { + public: + IGdbProduct* createGdbProduct() override { return new WindowsGdbProduct(); } + ICMakeProduct* createCMakeProduct() override { + return new WindowsCMakeProduct(); + } +}; + +class LinuxProductFactory : public IProductAbstractFactory { + public: + IGdbProduct* createGdbProduct() override { return new LinuxGdbProduct(); } + ICMakeProduct* createCMakeProduct() override { + return new LinuxCMakeProduct(); + } +}; + +class MacOsProductFactory : public IProductAbstractFactory { + public: + IGdbProduct* createGdbProduct() override { return new MacOsGdbProduct(); } + ICMakeProduct* createCMakeProduct() override { + return new MacOsCMakeProduct(); + } +}; + +// =================================================================================== + +/** + * The client code works with factories and products only through abstract + * types: AbstractFactory and AbstractProduct. This lets you pass any factory or + * product subclass to the client code without breaking it. + */ +namespace ClientCode { +void clientCode(IProductAbstractFactory* f) { + ICMakeProduct* cmake = f->createCMakeProduct(); + IGdbProduct* gdb = f->createGdbProduct(); + cmake->launch(); + gdb->launch(); + + delete cmake; + delete gdb; +} +} // namespace ClientCode + +// static redudant inside anonymous namespace +IProductAbstractFactory* createProductFactory(const std::string& os) { + if (os == "linux") { + return new LinuxProductFactory(); + } else if (os == "windows") { + return new WindowsProductFactory(); + } else if (os == "macos") { + return new MacOsProductFactory(); + } else { + std::cout << "OS not support yet - " << os << "\n"; + return nullptr; + } +} + +void run() { + std::string os = "linux"; + IProductAbstractFactory* factory = createProductFactory(os); + ClientCode::clientCode(factory); + delete factory; +} +} // namespace AbstractFactory +} // namespace + +struct AbstractFactoryAutoRunner { + AbstractFactoryAutoRunner() { + std::cout << "\n--- AbstractFactory Pattern Example ---\n"; + AbstractFactory::run(); + } +}; + +static AbstractFactoryAutoRunner instance; \ No newline at end of file diff --git a/src/patterns/creational/FactoryMethod.cpp b/src/patterns/creational/FactoryMethod.cpp index 8a80c10..bb4a5ee 100644 --- a/src/patterns/creational/FactoryMethod.cpp +++ b/src/patterns/creational/FactoryMethod.cpp @@ -51,22 +51,23 @@ class MacOsGdbProduct : public IGdbProduct { } }; +// =================================================================================== + /** * The Creator class declares the factory method that is supposed to return an * object of a Product class. The Creator's subclasses usually provide the - * implementation of this method. + * implementation of this method. (a.k.a IGdbFactory) */ -class IGdbCreator { +class IGdbFactory { public: - virtual ~IGdbCreator() = default; + virtual ~IGdbFactory() = default; virtual IGdbProduct* factoryMethod() = 0; virtual void launchGdb() = 0; }; -class AbstractGdbCreater : public IGdbCreator { +class AbstractGdbFactory : public IGdbFactory { public: - // Call the factory method to create a Product object. - + // Call the factory method to create a Product object. void launchGdb() override final { IGdbProduct* gdb = this->factoryMethod(); gdb->launch(); @@ -78,52 +79,51 @@ class AbstractGdbCreater : public IGdbCreator { * Concrete Creators override the factory method in order to change the * resulting product's type. */ -class WindowsGdbCreator : public AbstractGdbCreater { +class WindowsGdbFactory : public AbstractGdbFactory { public: IGdbProduct* factoryMethod() override { return new WindowsGdbProduct(); } }; -class LinuxGdbCreator : public AbstractGdbCreater { +class LinuxGdbFactory : public AbstractGdbFactory { public: IGdbProduct* factoryMethod() override { return new LinuxGdbProduct(); } }; -class MacOsGdbCreator : public AbstractGdbCreater { +class MacOsGdbFactory : public AbstractGdbFactory { public: IGdbProduct* factoryMethod() override { return new MacOsGdbProduct(); } }; +// =================================================================================== + /** * The client code works with an instance of a concrete creator, albeit through * its base interface. As long as the client keeps working with the creator via * the base interface, you can pass it any creator's subclass. */ namespace ClientCode { -void clientCode(IGdbCreator* gdb) { +void clientCode(IGdbFactory* gdb) { if (gdb != nullptr) gdb->launchGdb(); } } // namespace ClientCode -class GdbCreatorFactory { - public: - static IGdbCreator* createGdbCreator(const std::string& os) { - if (os == "linux") { - return new LinuxGdbCreator(); - } else if (os == "windows") { - return new WindowsGdbCreator(); - } else if (os == "macos") { - return new MacOsGdbCreator(); - } else { - std::cout << "OS not support yet - " << os << "\n"; - return nullptr; - } +IGdbFactory* createGdbFactory(const std::string& os) { + if (os == "linux") { + return new LinuxGdbFactory(); + } else if (os == "windows") { + return new WindowsGdbFactory(); + } else if (os == "macos") { + return new MacOsGdbFactory(); + } else { + std::cout << "OS not support yet - " << os << "\n"; + return nullptr; } -}; +} void run() { std::string os = "linux"; - IGdbCreator* gdb = GdbCreatorFactory::createGdbCreator(os); + IGdbFactory* gdb = createGdbFactory(os); ClientCode::clientCode(gdb); delete gdb; } diff --git a/src/patterns/creational/Prototype.cpp b/src/patterns/creational/Prototype.cpp index 95b4150..8743fe3 100644 --- a/src/patterns/creational/Prototype.cpp +++ b/src/patterns/creational/Prototype.cpp @@ -1,24 +1,127 @@ // cppcheck-suppress-file [functionStatic] -// Prototype is a creational design pattern that lets you copy existing objects -// without making your code dependent on their classes. Appicability: -// (*) when your code shouldn’t depend on the concrete classes of objects that -// you need to copy. -// (**) when you want to reduce the number of subclasses that only differ in the -// way they initialize their respective objects. +// Prototype is a creational design pattern that lets you "copy existing objects" without making your code "dependent on their classes". +// Appicability: +// (*) when your code shouldn’t depend on the concrete classes of objects that you need to copy. +// (**) when you want to reduce the number of subclasses that only differ in the way they initialize their respective objects. -// UML: docs/uml/patterns_behavioral_iterator.drawio.svg +// UML: docs/uml/patterns_behavioral_prototype.drawio.svg #include +#include +namespace { +namespace Prototy { -namespace {} +/* + * Prototype interface declares the cloning methods. + * In most cases, it’s a single `clone` method. + */ +class IExtensionPrototype { + public: + virtual ~IExtensionPrototype() = default; + virtual IExtensionPrototype* clone() = 0; + virtual void execute() const = 0; +}; -// struct SingletonAutoRuner -// { -// SingletonAutoRuner() -// { -// std::cout << "\n--- Singleton Pattern Example ---\n"; -// } -// }; +/* + * Concrete Prototype implement an operation for cloning itself + * In addition to copying the original object’s data to the clone, + * this method may also handle some edge cases of the cloning process related to cloning linked objects, + * untangling recursive dependencies, etc. + */ +class LoggerExtension : public IExtensionPrototype { + private: + std::string m_logLevel; -// static SingletonAutoRuner instance; \ No newline at end of file + public: + explicit LoggerExtension(const std::string& level = "DEBUG") + : m_logLevel{level} {} + + IExtensionPrototype* clone() override { return new LoggerExtension(*this); } + + void execute() const override { + std::cout << "[Logger] log level: " << m_logLevel << "\n"; + } +}; + +class AnalyticsExtension : public IExtensionPrototype { + private: + int m_sRate; + + public: + explicit AnalyticsExtension(int level = 1) : m_sRate{level} {} + + IExtensionPrototype* clone() override { + return new AnalyticsExtension(*this); + } + + void execute() const override { + std::cout << "[Analytics] sampling rate: " << m_sRate << "\n"; + } +}; + +/** + * Prototype Registry provides an easy way to access frequently-used prototypes. + * It stores a set of pre-built objects that are ready to be copied. + * The simplest prototype registry is a name ^ prototype hash map. + * However, if you need better search criteria than a simple name, you can build a much more robust version of the registry. + */ +class ExtensionPrototypeRegistry { + private: + std::unordered_map prototypes; + + public: + ~ExtensionPrototypeRegistry() { + for (auto it = prototypes.begin(); it != prototypes.end();) { + delete it->second; // free the pointer + it = prototypes.erase(it); // erase and move to next + } + } + void registerExtension(const std::string& id, IExtensionPrototype* proto) { + prototypes[id] = proto; + } + + IExtensionPrototype* create(const std::string& id) const { + auto it = prototypes.find(id); + if (it != prototypes.end()) { + return it->second->clone(); + } + return nullptr; + } +}; + +/* + * Client creates a new object by asking a prototype to clone itself + */ +namespace Client { +void clientCode(const ExtensionPrototypeRegistry* const registry) { + IExtensionPrototype* loggerEtx = registry->create("logger"); + loggerEtx->execute(); + IExtensionPrototype* analyxEtx = registry->create("analyze"); + analyxEtx->execute(); + + delete loggerEtx; + delete analyxEtx; +} + +} // namespace Client + +void run() { + ExtensionPrototypeRegistry* registry = new ExtensionPrototypeRegistry(); + registry->registerExtension("logger", new LoggerExtension("DEBUG")); + registry->registerExtension("analyze", new AnalyticsExtension(1200)); + Client::clientCode(registry); + + delete registry; +} +} // namespace Prototy +} // namespace + +struct PrototypeAutoRunner { + PrototypeAutoRunner() { + std::cout << "\n--- Prototype Pattern Example ---\n"; + Prototy::run(); + } +}; + +static PrototypeAutoRunner instance; \ No newline at end of file diff --git a/src/patterns/creational/Singleton.cpp b/src/patterns/creational/Singleton.cpp index 74f04bd..b062aad 100644 --- a/src/patterns/creational/Singleton.cpp +++ b/src/patterns/creational/Singleton.cpp @@ -70,11 +70,11 @@ void run() { } // namespace SingletonPattern } // namespace -struct SingletonAutoRuner { - SingletonAutoRuner() { +struct SingletonAutoRunner { + SingletonAutoRunner() { std::cout << "\n--- Singleton Pattern Example ---\n"; SingletonPattern::run(); } }; -static SingletonAutoRuner instance; \ No newline at end of file +static SingletonAutoRunner instance; \ No newline at end of file diff --git a/src/patterns/structural/Adapter.cpp b/src/patterns/structural/Adapter.cpp index 7c81695..1b79389 100644 --- a/src/patterns/structural/Adapter.cpp +++ b/src/patterns/structural/Adapter.cpp @@ -141,12 +141,12 @@ void run() { } } // namespace CaseStudy -struct AdapterAutoRuner { - AdapterAutoRuner() { +struct AdapterAutoRunner { + AdapterAutoRunner() { std::cout << "\n--- Factory Pattern Example ---\n"; AdapterPattern::run(); CaseStudy::run(); } }; -static AdapterAutoRuner instance; \ No newline at end of file +static AdapterAutoRunner instance; \ No newline at end of file diff --git a/src/patterns/structural/Bridge.cpp b/src/patterns/structural/Bridge.cpp index 246d6ea..50076ba 100644 --- a/src/patterns/structural/Bridge.cpp +++ b/src/patterns/structural/Bridge.cpp @@ -166,13 +166,13 @@ void run() { } } // namespace BridgePattern -struct BridgeAutoruner { - BridgeAutoruner() { +struct BridgeAutoRunner { + BridgeAutoRunner() { std::cout << "\n--- Bridge Pattern Example ---\n"; Problem::run(); BridgePattern::run(); } }; -static BridgeAutoruner instance; +static BridgeAutoRunner instance; } // namespace \ No newline at end of file diff --git a/src/patterns/structural/Composite.cpp b/src/patterns/structural/Composite.cpp index 89dfb65..139741b 100644 --- a/src/patterns/structural/Composite.cpp +++ b/src/patterns/structural/Composite.cpp @@ -425,12 +425,12 @@ void run() { } // namespace -struct CompositeAutoRuner { - CompositeAutoRuner() { +struct CompositeAutoRunner { + CompositeAutoRunner() { std::cout << "\n--- Composite Pattern Example ---\n"; Problem::run(); CompositePattern::run(); } }; -static CompositeAutoRuner instance; \ No newline at end of file +static CompositeAutoRunner instance; \ No newline at end of file diff --git a/src/patterns/structural/Decorator.cpp b/src/patterns/structural/Decorator.cpp index 000a491..02f05b8 100644 --- a/src/patterns/structural/Decorator.cpp +++ b/src/patterns/structural/Decorator.cpp @@ -185,12 +185,12 @@ void run() { } // namespace -struct DecoratorAutoRuner { - DecoratorAutoRuner() { +struct DecoratorAutoRunner { + DecoratorAutoRunner() { std::cout << "\n--- Decorator Pattern Example ---\n"; Problem::run(); DecoratorPattern::run(); } }; -static DecoratorAutoRuner instance; \ No newline at end of file +static DecoratorAutoRunner instance; \ No newline at end of file diff --git a/src/patterns/structural/Facade.cpp b/src/patterns/structural/Facade.cpp index 3a5534f..ce4db50 100644 --- a/src/patterns/structural/Facade.cpp +++ b/src/patterns/structural/Facade.cpp @@ -209,12 +209,12 @@ void run() { } // namespace Facade } // namespace -struct FacadeAutoRuner { - FacadeAutoRuner() { +struct FacadeAutoRunner { + FacadeAutoRunner() { std::cout << "\n--- Facade Pattern Example ---\n"; Problem::run(); Facade::run(); } }; -static FacadeAutoRuner instance; \ No newline at end of file +static FacadeAutoRunner instance; \ No newline at end of file diff --git a/src/patterns/structural/Flyweight.cpp b/src/patterns/structural/Flyweight.cpp index 5c5f363..efc0464 100644 --- a/src/patterns/structural/Flyweight.cpp +++ b/src/patterns/structural/Flyweight.cpp @@ -327,12 +327,12 @@ void run() { } // namespace FlyweightPattern } // namespace -struct FlyweightAutoRuner { - FlyweightAutoRuner() { +struct FlyweightAutoRunner { + FlyweightAutoRunner() { std::cout << "\n--- Flyweight Pattern Example ---\n"; Problem::run(); FlyweightPattern::run(); } }; -static FlyweightAutoRuner instance; \ No newline at end of file +static FlyweightAutoRunner instance; \ No newline at end of file