[
  {
    "path": ".gitignore",
    "content": "# Compiled source #\n###################\n*.com\n*.class\n*.dll\n*.exe\n*.o\n*.so\n\n# Packages #\n############\n# it's better to unpack these files and commit the raw source\n# git has its own built in compression methods\n*.7z\n*.dmg\n*.gz\n*.iso\n*.jar\n*.rar\n*.tar\n*.zip\n\n# Logs and databases #\n######################\n*.log\n*.sql\n*.sqlite\n\n# OS generated files #\n######################\n.DS_Store\n.DS_Store?\n._*\n.Spotlight-V100\n.Trashes\nehthumbs.db\nThumbs.db\n\n"
  },
  {
    "path": "Abstract Factory Design Pattern/Furniture /C++/furniture.cpp",
    "content": "#include <iostream>\n\n// Abstract Product: Sofa\nclass Sofa {\npublic:\n    virtual void sitOn() = 0;\n};\n\n// Abstract Product: Chair\nclass Chair {\npublic:\n    virtual void sitOn() = 0;\n};\n\n// Abstract Product: Table\nclass Table {\npublic:\n    virtual void place() = 0;\n};\n\n// Concrete Products: Modern Furniture Items\nclass ModernSofa : public Sofa {\npublic:\n    void sitOn() override {\n        std::cout << \"Sitting on a Modern Sofa\" << std::endl;\n    }\n};\n\nclass ModernChair : public Chair {\npublic:\n    void sitOn() override {\n        std::cout << \"Sitting on a Modern Chair\" << std::endl;\n    }\n};\n\nclass ModernTable : public Table {\npublic:\n    void place() override {\n        std::cout << \"Placing items on a Modern Table\" << std::endl;\n    }\n};\n\n// Concrete Products: Traditional Furniture Items\nclass TraditionalSofa : public Sofa {\npublic:\n    void sitOn() override {\n        std::cout << \"Sitting on a Traditional Sofa\" << std::endl;\n    }\n};\n\nclass TraditionalChair : public Chair {\npublic:\n    void sitOn() override {\n        std::cout << \"Sitting on a Traditional Chair\" << std::endl;\n    }\n};\n\nclass TraditionalTable : public Table {\npublic:\n    void place() override {\n        std::cout << \"Placing items on a Traditional Table\" << std::endl;\n    }\n};\n\n// Abstract Factory: Furniture Factory\nclass FurnitureFactory {\npublic:\n    virtual Sofa* createSofa() = 0;\n    virtual Chair* createChair() = 0;\n    virtual Table* createTable() = 0;\n\n    static FurnitureFactory* CreateFurnitureFactory(std::string type) {\n        if (type == \"modern\") {\n            return new ModernFurnitureFactory();\n        }\n        else if (type == \"traditional\") {\n            return new TraditionalFurnitureFactory();\n        }\n        else return nullptr;\n    }\n};\n\n// Concrete Factory: Modern Furniture Factory\nclass ModernFurnitureFactory : public FurnitureFactory {\npublic:\n    Sofa* createSofa() override {\n        return new ModernSofa();\n    }\n\n    Chair* createChair() override {\n        return new ModernChair();\n    }\n\n    Table* createTable() override {\n        return new ModernTable();\n    }\n};\n\n// Concrete Factory: Traditional Furniture Factory\nclass TraditionalFurnitureFactory : public FurnitureFactory {\npublic:\n    Sofa* createSofa() override {\n        return new TraditionalSofa();\n    }\n\n    Chair* createChair() override {\n        return new TraditionalChair();\n    }\n\n    Table* createTable() override {\n        return new TraditionalTable();\n    }\n};\n\nint main() {\n    FurnitureFactory* modernFactory = FurnitureFactory::CreateFurnitureFactory(\"modern\");\n    //use the abstract factory to create factories\n\n    // Create Modern furniture items\n    Sofa* modernSofa = modernFactory->createSofa();\n    Chair* modernChair = modernFactory->createChair();\n    Table* modernTable = modernFactory->createTable();\n\n    // Use Modern furniture items\n    modernSofa->sitOn();\n    modernChair->sitOn();\n    modernTable->place();\n\n    // Clean up Modern Factory objects\n    delete modernFactory;\n    delete modernSofa;\n    delete modernChair;\n    delete modernTable;\n\n    // Create a Traditional Furniture Factory\n    FurnitureFactory* traditionalFactory = FurnitureFactory::CreateFurnitureFactory(\"traditional\");\n\n   // FurnitureFactory* traditionalFactory = new TraditionalFurnitureFactory();\n\n    // Create Traditional furniture items\n    Sofa* traditionalSofa = traditionalFactory->createSofa();\n    Chair* traditionalChair = traditionalFactory->createChair();\n    Table* traditionalTable = traditionalFactory->createTable();\n\n    // Use Traditional furniture items\n    traditionalSofa->sitOn();\n    traditionalChair->sitOn();\n    traditionalTable->place();\n\n    // Clean up Traditional Factory objects\n    delete traditionalFactory;\n    delete traditionalSofa;\n    delete traditionalChair;\n    delete traditionalTable;\n\n    return 0;\n}"
  },
  {
    "path": "Abstract Factory Design Pattern/Furniture /JAVA/furniture.java",
    "content": "interface Sofa {\n    void sitOn();\n}\n\n// Abstract Product: Chair\ninterface Chair {\n    void sitOn();\n}\n\n// Abstract Product: Table\ninterface Table {\n    void place();\n}\n\n// Concrete Products: Modern Furniture Items\nclass ModernSofa implements Sofa {\n    public void sitOn() {\n        System.out.println(\"Sitting on a Modern Sofa\");\n    }\n}\n\nclass ModernChair implements Chair {\n    public void sitOn() {\n        System.out.println(\"Sitting on a Modern Chair\");\n    }\n}\n\nclass ModernTable implements Table {\n    public void place() {\n        System.out.println(\"Placing items on a Modern Table\");\n    }\n}\n\n// Concrete Products: Traditional Furniture Items\nclass TraditionalSofa implements Sofa {\n    public void sitOn() {\n        System.out.println(\"Sitting on a Traditional Sofa\");\n    }\n}\n\nclass TraditionalChair implements Chair {\n    public void sitOn() {\n        System.out.println(\"Sitting on a Traditional Chair\");\n    }\n}\n\nclass TraditionalTable implements Table {\n    public void place() {\n        System.out.println(\"Placing items on a Traditional Table\");\n    }\n}\n\n// Abstract Factory: Furniture Factory\ninterface FurnitureFactory {\n    Sofa createSofa();\n    Chair createChair();\n    Table createTable();\n\n    public static FurnitureFactory createFurnitureFactory(String type) {\n        if (type.equals(\"modern\")) {\n            return new ModernFurnitureFactory();\n        } else if (type.equals(\"traditional\")) {\n            return new TraditionalFurnitureFactory();\n        } else {\n            return null;\n        }\n    }\n}\n\n// Concrete Factory: Modern Furniture Factory\nclass ModernFurnitureFactory implements FurnitureFactory {\n    public Sofa createSofa() {\n        return new ModernSofa();\n    }\n\n    public Chair createChair() {\n        return new ModernChair();\n    }\n\n    public Table createTable() {\n        return new ModernTable();\n    }\n}\n\n// Concrete Factory: Traditional Furniture Factory\nclass TraditionalFurnitureFactory implements FurnitureFactory {\n    public Sofa createSofa() {\n        return new TraditionalSofa();\n    }\n\n    public Chair createChair() {\n        return new TraditionalChair();\n    }\n\n    public Table createTable() {\n        return new TraditionalTable();\n    }\n}\n\npublic class furniture {\n    public static void main(String[] args) {\n        FurnitureFactory modernFactory = FurnitureFactory.createFurnitureFactory(\"modern\");\n        // use the abstract factory to create factories\n\n        // Create Modern furniture items\n        Sofa modernSofa = modernFactory.createSofa();\n        Chair modernChair = modernFactory.createChair();\n        Table modernTable = modernFactory.createTable();\n\n        // Use Modern furniture items\n        modernSofa.sitOn();\n        modernChair.sitOn();\n        modernTable.place();\n\n        // Create a Traditional Furniture Factory\n        FurnitureFactory traditionalFactory = FurnitureFactory.createFurnitureFactory(\"traditional\");\n\n        // Create Traditional furniture items\n        Sofa traditionalSofa = traditionalFactory.createSofa();\n        Chair traditionalChair = traditionalFactory.createChair();\n        Table traditionalTable = traditionalFactory.createTable();\n\n        // Use Traditional furniture items\n        traditionalSofa.sitOn();\n        traditionalChair.sitOn();\n        traditionalTable.place();\n    }\n}"
  },
  {
    "path": "Abstract Factory Design Pattern/Furniture /Javascript/furniture.js",
    "content": "// Abstract Product: Sofa\nclass Sofa {\n    sitOn() {}\n}\n\n// Abstract Product: Chair\nclass Chair {\n    sitOn() {}\n}\n\n// Abstract Product: Table\nclass Table {\n    place() {}\n}\n\n// Concrete Products: Modern Furniture Items\nclass ModernSofa extends Sofa {\n    sitOn() {\n        console.log(\"Sitting on a Modern Sofa\");\n    }\n}\n\nclass ModernChair extends Chair {\n    sitOn() {\n        console.log(\"Sitting on a Modern Chair\");\n    }\n}\n\nclass ModernTable extends Table {\n    place() {\n        console.log(\"Placing items on a Modern Table\");\n    }\n}\n\n// Concrete Products: Traditional Furniture Items\nclass TraditionalSofa extends Sofa {\n    sitOn() {\n        console.log(\"Sitting on a Traditional Sofa\");\n    }\n}\n\nclass TraditionalChair extends Chair {\n    sitOn() {\n        console.log(\"Sitting on a Traditional Chair\");\n    }\n}\n\nclass TraditionalTable extends Table {\n    place() {\n        console.log(\"Placing items on a Traditional Table\");\n    }\n}\n\n// Abstract Factory: Furniture Factory\nclass FurnitureFactory {\n    createSofa() {}\n    createChair() {}\n    createTable() {}\n\n    static createFurnitureFactory(type) {\n        if (type === \"modern\") {\n            return new ModernFurnitureFactory();\n        } else if (type === \"traditional\") {\n            return new TraditionalFurnitureFactory();\n        } else {\n            return null;\n        }\n    }\n}\n\n// Concrete Factory: Modern Furniture Factory\nclass ModernFurnitureFactory extends FurnitureFactory {\n    createSofa() {\n        return new ModernSofa();\n    }\n\n    createChair() {\n        return new ModernChair();\n    }\n\n    createTable() {\n        return new ModernTable();\n    }\n}\n\n// Concrete Factory: Traditional Furniture Factory\nclass TraditionalFurnitureFactory extends FurnitureFactory {\n    createSofa() {\n        return new TraditionalSofa();\n    }\n\n    createChair() {\n        return new TraditionalChair();\n    }\n\n    createTable() {\n        return new TraditionalTable();\n    }\n}\n\nfunction main() {\n    const modernFactory = FurnitureFactory.createFurnitureFactory(\"modern\");\n\n    // Create Modern furniture items\n    const modernSofa = modernFactory.createSofa();\n    const modernChair = modernFactory.createChair();\n    const modernTable = modernFactory.createTable();\n\n    // Use Modern furniture items\n    modernSofa.sitOn();\n    modernChair.sitOn();\n    modernTable.place();\n\n    // Create a Traditional Furniture Factory\n    const traditionalFactory = FurnitureFactory.createFurnitureFactory(\"traditional\");\n\n    // Create Traditional furniture items\n    const traditionalSofa = traditionalFactory.createSofa();\n    const traditionalChair = traditionalFactory.createChair();\n    const traditionalTable = traditionalFactory.createTable();\n\n    // Use Traditional furniture items\n    traditionalSofa.sitOn();\n    traditionalChair.sitOn();\n    traditionalTable.place();\n}\n\nmain();\n"
  },
  {
    "path": "Abstract Factory Design Pattern/Furniture /Python/furniture.py",
    "content": "# Abstract Product: Sofa\nclass Sofa:\n    def sit_on(self):\n        pass\n\n# Abstract Product: Chair\nclass Chair:\n    def sit_on(self):\n        pass\n\n# Abstract Product: Table\nclass Table:\n    def place(self):\n        pass\n\n# Concrete Products: Modern Furniture Items\nclass ModernSofa(Sofa):\n    def sit_on(self):\n        print(\"Sitting on a Modern Sofa\")\n\nclass ModernChair(Chair):\n    def sit_on(self):\n        print(\"Sitting on a Modern Chair\")\n\nclass ModernTable(Table):\n    def place(self):\n        print(\"Placing items on a Modern Table\")\n\n# Concrete Products: Traditional Furniture Items\nclass TraditionalSofa(Sofa):\n    def sit_on(self):\n        print(\"Sitting on a Traditional Sofa\")\n\nclass TraditionalChair(Chair):\n    def sit_on(self):\n        print(\"Sitting on a Traditional Chair\")\n\nclass TraditionalTable(Table):\n    def place(self):\n        print(\"Placing items on a Traditional Table\")\n\n# Abstract Factory: Furniture Factory\nclass FurnitureFactory:\n    def create_sofa(self):\n        pass\n\n    def create_chair(self):\n        pass\n\n    def create_table(self):\n        pass\n\n    @staticmethod\n    def create_furniture_factory(type):\n        if type == \"modern\":\n            return ModernFurnitureFactory()\n        elif type == \"traditional\":\n            return TraditionalFurnitureFactory()\n        else:\n            return None\n\n# Concrete Factory: Modern Furniture Factory\nclass ModernFurnitureFactory(FurnitureFactory):\n    def create_sofa(self):\n        return ModernSofa()\n\n    def create_chair(self):\n        return ModernChair()\n\n    def create_table(self):\n        return ModernTable()\n\n# Concrete Factory: Traditional Furniture Factory\nclass TraditionalFurnitureFactory(FurnitureFactory):\n    def create_sofa(self):\n        return TraditionalSofa()\n\n    def create_chair(self):\n        return TraditionalChair()\n\n    def create_table(self):\n        return TraditionalTable()\n\ndef main():\n    modern_factory = FurnitureFactory.create_furniture_factory(\"modern\")\n\n    # Create Modern furniture items\n    modern_sofa = modern_factory.create_sofa()\n    modern_chair = modern_factory.create_chair()\n    modern_table = modern_factory.create_table()\n\n    # Use Modern furniture items\n    modern_sofa.sit_on()\n    modern_chair.sit_on()\n    modern_table.place()\n\n    traditional_factory = FurnitureFactory.create_furniture_factory(\"traditional\")\n\n    # Create Traditional furniture items\n    traditional_sofa = traditional_factory.create_sofa()\n    traditional_chair = traditional_factory.create_chair()\n    traditional_table = traditional_factory.create_table()\n\n    # Use Traditional furniture items\n    traditional_sofa.sit_on()\n    traditional_chair.sit_on()\n    traditional_table.place()\n\nif __name__ == \"__main__\":\n    main()\n"
  },
  {
    "path": "Abstract Factory Design Pattern/UI/C++/ui.cpp",
    "content": "#include <string>\n#include <iostream>\nusing namespace std;\n\nclass Ibutton{\n    public :\n    virtual void press() = 0;\n   \n};\nclass ITextbox{\n    public :\n    virtual void settext() = 0;\n   \n};\n\nclass MacButton : public Ibutton{\n    public :\n    void press(){\n        cout<<\"Mac button pressed\"<<endl;\n    }\n   \n};\n\nclass WinButton : public Ibutton{\n    public :\n    void press(){\n        cout<<\"Win button pressed\"<<endl;\n    }\n   \n};\n\nclass MacTextBox : public ITextbox{\n    public :\n    void settext(){\n        cout<<\"Setting text in Mac Textbox\"<<endl;\n    }\n   \n};\n\nclass WinTextBox : public ITextbox{\n    public :\n    void settext(){\n        cout<<\"Setting text in Win Textbox\"<<endl;\n    }\n   \n};\n\nclass IFactory{\n    public :\n        virtual Ibutton* createbutton() = 0;\n        virtual ITextbox* createtextbox() = 0;\n};\n\n\nclass WinFactory : public IFactory{\n    public :\n        Ibutton* createbutton(){\n            return new WinButton();\n        }\n        ITextbox* createtextbox(){\n            return new WinTextBox();\n        }\n   \n};\n\nclass MacFactory : public IFactory{\n    public :\n    Ibutton* createbutton(){\n        return new MacButton();\n    }\n    ITextbox* createtextbox(){\n        return new MacTextBox();\n    }\n   \n};\n\nclass GUIAbstractfactory{\n  public:\n    static IFactory* createfactory(string ostype){\n        if(ostype == \"windows\"){\n            return new WinFactory();\n        }\n        else if(ostype == \"mac\"){\n            return new MacFactory;\n        }\n        return nullptr;\n    }\n};\n\n\nint main(){\n   \n    cout<<\"Enter machine OS\\n\";\n    string ostype;\n    cin>>ostype;\n   \n    IFactory* fact = GUIAbstractfactory::createfactory(ostype);\n   \n    Ibutton* button = fact->createbutton();\n    button->press();\n   \n    ITextbox* textBox = fact->createtextbox();\n    textBox->settext();\n   \n    return 0;\n}\n"
  },
  {
    "path": "Abstract Factory Design Pattern/UI/JAVA/UI.java",
    "content": "import java.util.Scanner;\n\ninterface IButton {\n    void press();\n}\n\ninterface ITextbox {\n    void settext();\n}\n\nclass MacButton implements IButton {\n    @Override\n    public void press() {\n        System.out.println(\"Mac button pressed\");\n    }\n}\n\nclass WinButton implements IButton {\n    @Override\n    public void press() {\n        System.out.println(\"Win button pressed\");\n    }\n}\n\nclass MacTextBox implements ITextbox {\n    @Override\n    public void settext() {\n        System.out.println(\"Setting text in Mac Textbox\");\n    }\n}\n\nclass WinTextBox implements ITextbox {\n    @Override\n    public void settext() {\n        System.out.println(\"Setting text in Win Textbox\");\n    }\n}\n\ninterface IFactory {\n    IButton createButton();\n    ITextbox createTextbox();\n}\n\nclass WinFactory implements IFactory {\n    @Override\n    public IButton createButton() {\n        return new WinButton();\n    }\n\n    @Override\n    public ITextbox createTextbox() {\n        return new WinTextBox();\n    }\n}\n\nclass MacFactory implements IFactory {\n    @Override\n    public IButton createButton() {\n        return new MacButton();\n    }\n\n    @Override\n    public ITextbox createTextbox() {\n        return new MacTextBox();\n    }\n}\n\nclass GUIAbstractFactory {\n    public static IFactory createFactory(String osType) {\n        if (osType.equals(\"windows\")) {\n            return new WinFactory();\n        } else if (osType.equals(\"mac\")) {\n            return new MacFactory();\n        }\n        \n        return null;\n    }\n}\n\npublic class UI {\n    public static void main(String[] args) {\n        System.out.println(\"Enter machine OS\");\n        Scanner scanner = new Scanner(System.in);\n        String osType = scanner.nextLine();\n        scanner.close();\n\n        IFactory factory = GUIAbstractFactory.createFactory(osType);\n\n        if (factory != null) {\n            IButton button = factory.createButton();\n            button.press();\n\n            ITextbox textBox = factory.createTextbox();\n            textBox.settext();\n        } else {\n            System.out.println(\"Invalid OS type\");\n        }\n    }\n}\n"
  },
  {
    "path": "Adapter Design Pattern/Class Adapter/C++/xml_to_json.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// Data analytics tool that expects JSON data\n// Adaptee\nclass JSONAnalyticsTool\n{\n    string pJsonData;\n\npublic:\n    void setJsonData(string jsonData) {\n        pJsonData = jsonData;\n    }\n    void AnalyzeData()\n    {\n        if (pJsonData.find(\"json\") != string::npos) {\n            cout << \"Analysing JSON Data - \" << pJsonData << endl;\n        } else {\n            cout << \"Not correct format. Can't analyse! \" << endl;\n        }\n    }\n};\n\n// Interface Class\n// Target\nclass AnalyticsTool {\n    public:\n        virtual void AnalyzeData() = 0;\n        virtual ~AnalyticsTool() {}\n};\n\n// Adapter\n// Problem with Multiple Inheritance\nclass XMLToJSONAdapter : public AnalyticsTool, public JSONAnalyticsTool\n{\npublic:\n    XMLToJSONAdapter(string xmlData) {\n         cout<<\"Converting the XML Data '\" << xmlData <<\"' to JSON Data!\"<<endl;\n         string newData = xmlData + \" in json\";\n         setJsonData(newData);\n    }\n\n    void AnalyzeData()\n    {    \n        //Could convert here instead of the constructor\n        JSONAnalyticsTool::AnalyzeData();\n    }\n};\n\nint main()\n{\n    string xmlData = \"Sample Data\";\n    JSONAnalyticsTool tool1;\n    tool1.setJsonData(xmlData);\n    tool1.AnalyzeData();\n\n    cout<<\"----------------------------------------------\"<<endl;\n\n    AnalyticsTool *tool2 = new XMLToJSONAdapter(xmlData);\n    tool2->AnalyzeData();\n    delete tool2;\n    return 0;\n}\n"
  },
  {
    "path": "Adapter Design Pattern/Object Adapter/C++/xml_to_json.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// Data analytics tool that expects JSON data\n// Adaptee\nclass JSONAnalyticsTool\n{\n    string pJsonData;\n\npublic:\n    void setJsonData(string jsonData) {\n        pJsonData = jsonData;\n    }\n    void AnalyzeData()\n    {\n        if (pJsonData.find(\"json\") != string::npos) {\n            cout << \"Analysing JSON Data - \" << pJsonData << endl;\n        } else {\n            cout << \"Not correct format. Can't analyse! \" << endl;\n        }\n    }\n};\n\n// Interface Class\n// Target\nclass AnalyticsTool {\n    public:\n        virtual void AnalyzeData() = 0;\n        virtual ~AnalyticsTool() {}\n};\n\n// Adapter\nclass XMLToJSONAdapter : public AnalyticsTool\n{\nprivate:\n    JSONAnalyticsTool jsonAnalyticsTool;\n\npublic:\n    XMLToJSONAdapter(string xmlData) {\n         cout<<\"Converting the XML Data '\" << xmlData <<\"' to JSON Data!\"<<endl;\n         string newData = xmlData + \" in json\";\n         jsonAnalyticsTool.setJsonData(newData);\n    }\n\n    void AnalyzeData()\n    {    \n        //Could convert here instead of the constructor\n        jsonAnalyticsTool.AnalyzeData();\n    }\n};\n\nint main()\n{\n    string xmlData = \"Sample Data\";\n    JSONAnalyticsTool tool1;\n    tool1.setJsonData(xmlData);\n    tool1.AnalyzeData();\n\n    cout<<\"----------------------------------------------\"<<endl;\n\n    AnalyticsTool *tool2 = new XMLToJSONAdapter(xmlData);\n    tool2->AnalyzeData();\n    delete tool2;\n    return 0;\n}\n"
  },
  {
    "path": "Adapter Design Pattern/Object Adapter/JAVA/XmlToJson.java",
    "content": "class JSONAnalyticsTool {\n    private String jsonData;\n\n    public void setJsonData(String jsonData) {\n        this.jsonData = jsonData;\n    }\n\n    public void AnalyzeData() {\n        if (jsonData.contains(\"json\")) {\n            System.out.println(\"Analyzing JSON Data - \" + jsonData);\n        } else {\n            System.out.println(\"Not in the correct format. Can't analyze!\");\n        }\n    }\n}\n\ninterface AnalyticsTool {\n    void AnalyzeData();\n}\n\nclass XMLToJSONAdapter implements AnalyticsTool {\n    private JSONAnalyticsTool jsonAnalyticsTool;\n\n    public XMLToJSONAdapter(String xmlData) {\n        System.out.println(\"Converting the XML Data '\" + xmlData + \"' to JSON Data!\");\n        String newData = xmlData + \" in json\";\n        jsonAnalyticsTool = new JSONAnalyticsTool();\n        jsonAnalyticsTool.setJsonData(newData);\n    }\n\n    public void AnalyzeData() {\n        jsonAnalyticsTool.AnalyzeData();\n    }\n}\n\npublic class XmlToJson {\n    public static void main(String[] args) {\n        String xmlData = \"Sample Data\";\n        JSONAnalyticsTool tool1 = new JSONAnalyticsTool();\n        tool1.setJsonData(xmlData);\n        tool1.AnalyzeData();\n\n        System.out.println(\"----------------------------------------------\");\n\n        AnalyticsTool tool2 = new XMLToJSONAdapter(xmlData);\n        tool2.AnalyzeData();\n    }\n}\n"
  },
  {
    "path": "Bridge Design Pattern/C++/uber.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\n// Implementation Layer\nclass NavigationImpl\n{\npublic:\n    virtual void navigateTo(string destination) = 0;\n};\n\n// Concrete Implementation: GoogleMaps\nclass GoogleMaps : public NavigationImpl\n{\npublic:\n    void navigateTo(string destination)\n    {\n        cout << \"Google Maps.\" << endl;\n        // Actual navigation logic using Google Maps API\n    }\n};\n\n// Concrete Implementation: AppleMaps\nclass AppleMaps : public NavigationImpl\n{\npublic:\n    void navigateTo(string destination)\n    {\n        cout << \"Apple Maps.\" << endl;\n        // Actual navigation logic using Apple Maps API\n    }\n};\n\n// Abstraction Layer\nclass NavigationSystem\n{\nprotected:\n    NavigationImpl *navigationImpl;\n\npublic:\n    virtual void navigate(string destination) = 0;\n};\n\n// Concrete Abstraction: UberRide\nclass UberRide : public NavigationSystem\n{\n\nprivate:\n    string driverName;\n\npublic:\n    UberRide(string driverName) : driverName(driverName) {}\n\n    void navigate(string destination)\n    {\n        cout << \"Uber ride with \" << driverName << \" to \" << destination << \" using \";\n        navigationImpl->navigateTo(destination);\n    }\n\n    void setNavigationImpl(NavigationImpl *impl)\n    {\n        navigationImpl = impl;\n    }\n};\n\n// Concrete Abstraction: UberEats\nclass UberEats : public NavigationSystem\n{\nprivate:\n    string restaurantName;\n\npublic:\n    UberEats(string restaurantName) : restaurantName(restaurantName) {}\n\n    void navigate(string destination)\n    {\n        cout << \"Uber Eats delivery from \" << restaurantName << \" to \" << destination << \" using \";\n        navigationImpl->navigateTo(destination);\n    }\n\n    void setNavigationImpl(NavigationImpl *impl)\n    {\n        navigationImpl = impl;\n    }\n};\n\nint main()\n{\n    // Create an UberRide with a driver\n    UberRide uber(\"Keerti\");\n\n    // Create an UberEats delivery\n    UberEats uberEats(\"Pizza Palace\");\n\n    // Create different navigation implementations\n    GoogleMaps googleMaps;\n    AppleMaps appleMaps;\n\n    // Set the navigation implementation for UberRide\n    uber.setNavigationImpl(&googleMaps);\n\n    // Request an Uber ride with Google Maps navigation\n    uber.navigate(\"Central Park\");\n\n    // Switch to Apple Maps navigation for UberEats\n    uberEats.setNavigationImpl(&appleMaps);\n\n    // Request an Uber Eats delivery with Apple Maps navigation\n    uberEats.navigate(\"123 HSR\");\n\n    return 0;\n}\n"
  },
  {
    "path": "Bridge Design Pattern/JAVA/UberDemo.java",
    "content": "// Implementation Layer\ninterface NavigationImpl {\n    void navigateTo(String destination);\n}\n\n// Abstraction Layer\ninterface NavigationSystem {\n    void navigate(String destination);\n}\n\n// Concrete Abstraction: UberRide\nclass UberRide implements NavigationSystem {\n    private String driverName;\n    private NavigationImpl navigationImpl;\n\n    public UberRide(String driverName) {\n        this.driverName = driverName;\n    }\n\n    public void setNavigationImpl(NavigationImpl impl) {\n        this.navigationImpl = impl;\n    }\n\n    public void navigate(String destination) {\n        System.out.print(\"Uber ride with \" + driverName + \" to \" + destination + \" using \");\n        navigationImpl.navigateTo(destination);\n    }\n}\n\n// Concrete Abstraction: UberEats\nclass UberEats implements NavigationSystem {\n    private String restaurantName;\n    private NavigationImpl navigationImpl;\n\n    public UberEats(String restaurantName) {\n        this.restaurantName = restaurantName;\n    }\n\n    public void setNavigationImpl(NavigationImpl impl) {\n        this.navigationImpl = impl;\n    }\n\n    public void navigate(String destination) {\n        System.out.print(\"Uber Eats delivery from \" + restaurantName + \" to \" + destination + \" using \");\n        navigationImpl.navigateTo(destination);\n    }\n}\n\n// Concrete Implementation: GoogleMaps\nclass GoogleMaps implements NavigationImpl {\n    public void navigateTo(String destination) {\n        System.out.println(\"Google Maps.\");\n        // Actual navigation logic using Google Maps API\n    }\n}\n\n// Concrete Implementation: AppleMaps\nclass AppleMaps implements NavigationImpl {\n    public void navigateTo(String destination) {\n        System.out.println(\"Apple Maps.\");\n        // Actual navigation logic using Apple Maps API\n    }\n}\n\npublic class UberDemo {\n    public static void main(String[] args) {\n        // Create an UberRide with a driver\n        UberRide uber = new UberRide(\"Keerti\");\n\n        // Create an UberEats delivery\n        UberEats uberEats = new UberEats(\"Pizza Palace\");\n\n        // Create different navigation implementations\n        GoogleMaps googleMaps = new GoogleMaps();\n        AppleMaps appleMaps = new AppleMaps();\n\n        // Set the navigation implementation for UberRide\n        uber.setNavigationImpl(googleMaps);\n\n        // Request an Uber ride with Google Maps navigation\n        uber.navigate(\"Central Park\");\n\n        // Switch to Apple Maps navigation for UberEats\n        uberEats.setNavigationImpl(appleMaps);\n\n        // Request an Uber Eats delivery with Apple Maps navigation\n        uberEats.navigate(\"123 HSR\");\n    }\n}\n"
  },
  {
    "path": "Builder Design Pattern/Builder with Chaining/C++/desktop.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\nclass Desktop\n{\npublic:\n    string motherboard;\n    string processor;\n    string memory;\n    string storage;\n    string graphicsCard;\n\n    void display()\n    {\n        cout << \"Desktop Specs:\" << endl;\n        cout << \"Motherboard: \" << motherboard << endl;\n        cout << \"Processor: \" << processor << endl;\n        cout << \"Memory: \" << memory << endl;\n        cout << \"Storage: \" << storage << endl;\n        cout << \"Graphics Card: \" << graphicsCard << endl;\n    }\n};\n\nclass DesktopBuilder\n{\nprotected:\n    Desktop desktop;\n\npublic:\n    virtual DesktopBuilder &buildMotherboard() = 0;\n    virtual DesktopBuilder &buildProcessor() = 0;\n    virtual DesktopBuilder &buildMemory() = 0;\n    virtual DesktopBuilder &buildStorage() = 0;\n    virtual DesktopBuilder &buildGraphicsCard() = 0;\n\n    Desktop build()\n    {\n        return desktop;\n    }\n};\n\nclass DellDesktopBuilder : public DesktopBuilder\n{\npublic:\n    DesktopBuilder &buildMotherboard()\n    {\n        desktop.motherboard = \"Dell Motherboard\";\n        return *this;\n    }\n\n    DesktopBuilder &buildProcessor()\n    {\n        desktop.processor = \"Dell Processor\";\n        return *this;\n    }\n\n    DesktopBuilder &buildMemory()\n    {\n        desktop.memory = \"32GB DDR4 RAM\";\n        return *this;\n    }\n\n    DesktopBuilder &buildStorage()\n    {\n        desktop.storage = \"1TB SSD + 2TB HDD\";\n        return *this;\n    }\n\n    DesktopBuilder &buildGraphicsCard()\n    {\n        desktop.graphicsCard = \"NVIDIA RTX 3080\";\n        return *this;\n    }\n};\n\nclass HpDesktopBuilder : public DesktopBuilder\n{\npublic:\n    DesktopBuilder &buildMotherboard()\n    {\n        desktop.motherboard = \"Hp Motherboard\";\n        return *this;\n    }\n\n    DesktopBuilder &buildProcessor()\n    {\n        desktop.processor = \"Intel Core i5\";\n        return *this;\n    }\n\n    DesktopBuilder &buildMemory()\n    {\n        desktop.memory = \"16GB DDR4 RAM\";\n        return *this;\n    }\n\n    DesktopBuilder &buildStorage()\n    {\n        desktop.storage = \"512GB SSD\";\n        return *this;\n    }\n\n    DesktopBuilder &buildGraphicsCard()\n    {\n        desktop.graphicsCard = \"Integrated Graphics\";\n        return *this;\n    }\n};\n\nclass DesktopDirector\n{\npublic:\n    Desktop buildComputer(DesktopBuilder &builder)\n    {\n        return builder.buildMotherboard().buildProcessor().buildMemory().buildStorage().buildGraphicsCard().build();\n    }\n};\n\nint main()\n{\n    DesktopDirector director;\n\n    DellDesktopBuilder dellDesktopBuilder;\n    Desktop highEndComputer = director.buildComputer(dellDesktopBuilder);\n\n    HpDesktopBuilder officeBuilder;\n    Desktop officeComputer = director.buildComputer(officeBuilder);\n\n    highEndComputer.display();\n    officeComputer.display();\n\n    return 0;\n}"
  },
  {
    "path": "Builder Design Pattern/Builder with Chaining/JAVA/DesktopBuilderDemo.java",
    "content": "class Desktop {\n    String motherboard;\n    String processor;\n    String memory;\n    String storage;\n    String graphicsCard;\n\n    void display() {\n        System.out.println(\"Desktop Specs:\");\n        System.out.println(\"Motherboard: \" + motherboard);\n        System.out.println(\"Processor: \" + processor);\n        System.out.println(\"Memory: \" + memory);\n        System.out.println(\"Storage: \" + storage);\n        System.out.println(\"Graphics Card: \" + graphicsCard);\n    }\n}\n\nabstract class DesktopBuilder {\n    protected Desktop desktop;\n\n    abstract DesktopBuilder buildMotherboard();\n\n    abstract DesktopBuilder buildProcessor();\n\n    abstract DesktopBuilder buildMemory();\n\n    abstract DesktopBuilder buildStorage();\n\n    abstract DesktopBuilder buildGraphicsCard();\n\n    Desktop build() {\n        return desktop;\n    }\n}\n\nclass DellDesktopBuilder extends DesktopBuilder {\n    DellDesktopBuilder() {\n        desktop = new Desktop();\n    }\n\n    @Override\n    DesktopBuilder buildMotherboard() {\n        desktop.motherboard = \"Dell Motherboard\";\n        return this;\n    }\n\n    @Override\n    DesktopBuilder buildProcessor() {\n        desktop.processor = \"Dell Processor\";\n        return this;\n    }\n\n    @Override\n    DesktopBuilder buildMemory() {\n        desktop.memory = \"32GB DDR4 RAM\";\n        return this;\n    }\n\n    @Override\n    DesktopBuilder buildStorage() {\n        desktop.storage = \"1TB SSD + 2TB HDD\";\n        return this;\n    }\n\n    @Override\n    DesktopBuilder buildGraphicsCard() {\n        desktop.graphicsCard = \"NVIDIA RTX 3080\";\n        return this;\n    }\n}\n\nclass HpDesktopBuilder extends DesktopBuilder {\n    HpDesktopBuilder() {\n        desktop = new Desktop();\n    }\n\n    @Override\n    DesktopBuilder buildMotherboard() {\n        desktop.motherboard = \"Hp Motherboard\";\n        return this;\n    }\n\n    @Override\n    DesktopBuilder buildProcessor() {\n        desktop.processor = \"Intel Core i5\";\n        return this;\n    }\n\n    @Override\n    DesktopBuilder buildMemory() {\n        desktop.memory = \"16GB DDR4 RAM\";\n        return this;\n    }\n\n    @Override\n    DesktopBuilder buildStorage() {\n        desktop.storage = \"512GB SSD\";\n        return this;\n    }\n\n    @Override\n    DesktopBuilder buildGraphicsCard() {\n        desktop.graphicsCard = \"Integrated Graphics\";\n        return this;\n    }\n}\n\nclass DesktopDirector {\n    Desktop buildDesktop(DesktopBuilder builder) {\n        return builder.buildMotherboard().buildProcessor().buildMemory().buildStorage().buildGraphicsCard().build();\n    }\n}\n\npublic class DesktopBuilderDemo {\n    public static void main(String[] args) {\n        // Director\n        DesktopDirector director = new DesktopDirector();\n\n        // Build a high-end Desktop\n        DellDesktopBuilder DellBuilder = new DellDesktopBuilder();\n        Desktop DellDesktop = director.buildDesktop(DellBuilder);\n\n        // Build an Hp Desktop\n        HpDesktopBuilder HpBuilder = new HpDesktopBuilder();\n        Desktop HpDesktop = director.buildDesktop(HpBuilder);\n\n        // Display Desktop specifications\n        DellDesktop.display();\n        HpDesktop.display();\n    }\n}"
  },
  {
    "path": "Builder Design Pattern/C++/desktop.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\nclass Desktop\n{\npublic:\n    string motherboard;\n    string processor;\n    string memory;\n    string storage;\n    string graphicsCard;\n\n    void display()\n    {\n        cout << \"Desktop Specs:\" << endl;\n        cout << \"Motherboard: \" << motherboard << endl;\n        cout << \"Processor: \" << processor << endl;\n        cout << \"Memory: \" << memory << endl;\n        cout << \"Storage: \" << storage << endl;\n        cout << \"Graphics Card: \" << graphicsCard << endl;\n    }\n};\n\nclass DesktopBuilder\n{\nprotected:\n    Desktop desktop;\n\npublic:\n    virtual void buildMotherboard() = 0;\n    virtual void buildProcessor() = 0;\n    virtual void buildMemory() = 0;\n    virtual void buildStorage() = 0;\n    virtual void buildGraphicsCard() = 0;\n\n    Desktop getDesktop()\n    {\n        return desktop;\n    }\n};\n\nclass DellDesktopBuilder : public DesktopBuilder\n{\npublic:\n    void buildMotherboard()\n    {\n        desktop.motherboard = \"Dell Motherboard\";\n    }\n\n    void buildProcessor()\n    {\n        desktop.processor = \"Dell Processor\";\n    }\n\n    void buildMemory()\n    {\n        desktop.memory = \"32GB DDR4 RAM\";\n    }\n\n    void buildStorage()\n    {\n        desktop.storage = \"1TB SSD + 2TB HDD\";\n    }\n\n    void buildGraphicsCard()\n    {\n        desktop.graphicsCard = \"NVIDIA RTX 3080\";\n    }\n};\n\nclass HpDesktopBuilder : public DesktopBuilder\n{\npublic:\n    void buildMotherboard()\n    {\n        desktop.motherboard = \"HP Motherboard\";\n    }\n\n    void buildProcessor()\n    {\n        desktop.processor = \"Intel Core i5\";\n    }\n\n    void buildMemory()\n    {\n        desktop.memory = \"16GB DDR4 RAM\";\n    }\n\n    void buildStorage()\n    {\n        desktop.storage = \"512GB SSD\";\n    }\n\n    void buildGraphicsCard()\n    {\n        desktop.graphicsCard = \"Integrated Graphics\";\n    }\n};\n\nclass DesktopDirector\n{\npublic:\n    Desktop buildDesktop(DesktopBuilder &builder)\n    {\n        builder.buildMotherboard();\n        builder.buildProcessor();\n        builder.buildMemory();\n        builder.buildStorage();\n        builder.buildGraphicsCard();\n        return builder.getDesktop();\n    }\n};\n\nint main()\n{\n    DesktopDirector director;\n\n    DellDesktopBuilder dellDesktopBuilder;\n    Desktop dellDesktop = director.buildDesktop(dellDesktopBuilder);\n\n    HpDesktopBuilder hpDesktopBuilder;\n    Desktop hpDesktop = director.buildDesktop(hpDesktopBuilder);\n\n    dellDesktop.display();\n    hpDesktop.display();\n\n    return 0;\n}\n"
  },
  {
    "path": "Builder Design Pattern/JAVA/DesktopBuilderDemo.java",
    "content": "class Desktop {\n    private String motherboard;\n    private String processor;\n    private String memory;\n    private String storage;\n    private String graphicsCard;\n\n    public void display() {\n        System.out.println(\"Desktop Specs:\");\n        System.out.println(\"Motherboard: \" + motherboard);\n        System.out.println(\"Processor: \" + processor);\n        System.out.println(\"Memory: \" + memory);\n        System.out.println(\"Storage: \" + storage);\n        System.out.println(\"Graphics Card: \" + graphicsCard);\n    }\n\n    public String getMotherboard() {\n        return motherboard;\n    }\n\n    public void setMotherboard(String motherboard) {\n        this.motherboard = motherboard;\n    }\n\n    public String getProcessor() {\n        return processor;\n    }\n\n    public void setProcessor(String processor) {\n        this.processor = processor;\n    }\n\n    public String getMemory() {\n        return memory;\n    }\n\n    public void setMemory(String memory) {\n        this.memory = memory;\n    }\n\n    public String getStorage() {\n        return storage;\n    }\n\n    public void setStorage(String storage) {\n        this.storage = storage;\n    }\n\n    public String getGraphicsCard() {\n        return graphicsCard;\n    }\n\n    public void setGraphicsCard(String graphicsCard) {\n        this.graphicsCard = graphicsCard;\n    }\n}\n\nabstract class DesktopBuilder {\n    protected Desktop desktop = new Desktop();\n\n    public abstract void buildMotherboard();\n\n    public abstract void buildProcessor();\n\n    public abstract void buildMemory();\n\n    public abstract void buildStorage();\n\n    public abstract void buildGraphicsCard();\n\n    public Desktop getDesktop() {\n        return desktop;\n    }\n}\n\nclass DellDesktopBuilder extends DesktopBuilder {\n    public void buildMotherboard() {\n        desktop.setMotherboard(\"Dell Motherboard\");\n    }\n\n    public void buildProcessor() {\n        desktop.setProcessor(\"Dell Processor\");\n    }\n\n    public void buildMemory() {\n        desktop.setMemory(\"32GB DDR4 RAM\");\n    }\n\n    public void buildStorage() {\n        desktop.setStorage(\"1TB SSD + 2TB HDD\");\n    }\n\n    public void buildGraphicsCard() {\n        desktop.setGraphicsCard(\"NVIDIA RTX 3080\");\n    }\n}\n\nclass HpDesktopBuilder extends DesktopBuilder {\n    public void buildMotherboard() {\n        desktop.setMotherboard(\"HP Motherboard\");\n    }\n\n    public void buildProcessor() {\n        desktop.setProcessor(\"Intel Core i5\");\n    }\n\n    public void buildMemory() {\n        desktop.setMemory(\"16GB DDR4 RAM\");\n    }\n\n    public void buildStorage() {\n        desktop.setStorage(\"512GB SSD\");\n    }\n\n    public void buildGraphicsCard() {\n        desktop.setGraphicsCard(\"Integrated Graphics\");\n    }\n}\n\nclass DesktopDirector {\n    public Desktop buildDesktop(DesktopBuilder builder) {\n        builder.buildMotherboard();\n        builder.buildProcessor();\n        builder.buildMemory();\n        builder.buildStorage();\n        builder.buildGraphicsCard();\n        return builder.getDesktop();\n    }\n}\n\npublic class DesktopBuilderDemo {\n    public static void main(String[] args) {\n        DesktopDirector director = new DesktopDirector();\n\n        DellDesktopBuilder dellDesktopBuilder = new DellDesktopBuilder();\n        Desktop dellDesktop = director.buildDesktop(dellDesktopBuilder);\n\n        HpDesktopBuilder hpDesktopBuilder = new HpDesktopBuilder();\n        Desktop hpDesktop = director.buildDesktop(hpDesktopBuilder);\n\n        dellDesktop.display();\n        hpDesktop.display();\n    }\n}\n"
  },
  {
    "path": "Chain of Responsibility Design Pattern/C++/swiggy_order.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\n// Define the abstract base class for order handlers.\nclass OrderHandler {\n    protected:\n        OrderHandler* nextHandler;\n    public:\n        OrderHandler(OrderHandler* nextHandler) : nextHandler(nextHandler) {}\n\n        virtual void processOrder(const string& order) = 0;\n};\n\n// Concrete handler for order validation.\nclass OrderValidationHandler : public OrderHandler {\n    public:\n        OrderValidationHandler(OrderHandler* nextHandler) : OrderHandler(nextHandler) {}\n\n        void processOrder(const string& order) {\n            cout<<\"Validating order: \"<<order<<endl;\n\n            if(nextHandler)\n                nextHandler->processOrder(order);\n        }\n\n        ~OrderValidationHandler() {\n            cout<<\"validation handler dtor called\"<<endl;\n        }\n};\n\n// Concrete handler for payment processing.\nclass PaymentProcessingHanlder : public OrderHandler {\n    public:\n        PaymentProcessingHanlder(OrderHandler* nextHandler) : OrderHandler(nextHandler) {}\n\n        void processOrder(const string& order) {\n            cout<<\"Processing payment for order: \"<<order<<endl;\n\n            if(nextHandler)\n                nextHandler->processOrder(order);\n        }\n\n        ~PaymentProcessingHanlder() {\n            cout<<\"PaymentProcessingHanlder dtor called\"<<endl;\n        }\n};\n\n// Concrete handler for order preparation.\nclass OrderPreparationHandler : public OrderHandler {\n    public:\n        OrderPreparationHandler(OrderHandler* nexxtHandler) : OrderHandler(nextHandler) {}\n\n        void processOrder(const string& order) {\n            cout<<\"Preparing order: \"<<order<<endl;\n\n            if(nextHandler)\n                nextHandler->processOrder(order);\n        }\n        ~OrderPreparationHandler() {\n            cout<<\"OrderPreparationHandler dtor called\"<<endl;\n        }\n};\n\n// Concrete handler for delivery assignment.\nclass DeliveryAssignmentHandler : public OrderHandler {\n    public:\n        DeliveryAssignmentHandler(OrderHandler* nexxtHandler) : OrderHandler(nextHandler) {}\n\n        void processOrder(const string& order) {\n            cout<<\"Assigning delivery for order: \"<<order<<endl;\n\n            if(nextHandler)\n                nextHandler->processOrder(order);\n        }\n\n        ~DeliveryAssignmentHandler() {\n            cout<<\"DeliveryAssignmentHandler dtor called\"<<endl;\n        }\n};\n\n// Concrete handler for order tracking.\nclass OrderTrackingHandler : public OrderHandler {\n    public:\n        OrderTrackingHandler(OrderHandler* nexxtHandler) : OrderHandler(nextHandler) {}\n\n        void processOrder(const string& order) {\n            cout<<\"Tracking order: \"<<order<<endl;\n\n            if(nextHandler)\n                nextHandler->processOrder(order);\n        }\n\n        ~OrderTrackingHandler() {\n            cout<<\"OrderTrackingHandler dtor called\"<<endl;\n        }\n};\n\nint main() {\n    \n    // Create a chain of responsibility for order processing\n    OrderHandler* orderProcessingChain = \n        new OrderValidationHandler(\n            new PaymentProcessingHanlder(\n                new OrderPreparationHandler(\n                    new DeliveryAssignmentHandler(  \n                        new OrderTrackingHandler(nullptr)))));\n\n    // Simulate an order being placed\n    string order = \"Pizza\";\n    orderProcessingChain->processOrder(order);\n\n    /*\n        OrderHandler* orderTrackingHandler = new OrderTrackingHandler(nullptr);\n        OrderHandler* deliveryAssignmentHandler = new DeliveryAssignmentHandler(orderTrackingHandler);\n        OrderHandler* orderPreparationHandler = new OrderPreparationHandler(deliveryAssignmentHandler);\n        OrderHandler* paymentProcessingHandler = new PaymentProcessingHandler(orderPreparationHandler);\n        OrderHandler* orderValidationHandler = new OrderValidationHandler(paymentProcessingHandler);\n\n        // Simulate an order being placed\n        std::string order = \"Burger and Fries\";\n        orderValidationHandler->processOrder(order);\n\n        // Clean up by deleting all handler objects\n        delete orderValidationHandler;\n        delete paymentProcessingHandler;\n        delete orderPreparationHandler;\n        delete deliveryAssignmentHandler;\n        delete orderTrackingHandler;\n    \n        //Or use shared pointers so that we don't have to handle cleanup\n    */\n\n   /*\n   //Add setters to choose successor or next handler on run-time\n   //Hanlder will have setSuccessor func\n    orderValidation.setSuccessor(paymentProcessing);\n    paymentProcessing.setSuccessor(shipping);\n   */\n\n    return 0;\n}"
  },
  {
    "path": "Chain of Responsibility Design Pattern/JAVA/SwiggyOrder.java",
    "content": "// Define the abstract base class for order handlers.\nabstract class OrderHandler {\n    protected OrderHandler nextHandler;\n\n    public OrderHandler(OrderHandler nextHandler) {\n        this.nextHandler = nextHandler;\n    }\n\n    public abstract void processOrder(String order);\n}\n\n// Concrete handler for order validation.\nclass OrderValidationHandler extends OrderHandler {\n    public OrderValidationHandler(OrderHandler nextHandler) {\n        super(nextHandler);\n    }\n\n    @Override\n    public void processOrder(String order) {\n        System.out.println(\"Validating order: \" + order);\n        // Perform order validation logic here\n\n        // If the order is valid, pass it to the next handler\n        if (nextHandler != null) {\n            nextHandler.processOrder(order);\n        }\n    }\n}\n\n// Concrete handler for payment processing.\nclass PaymentProcessingHandler extends OrderHandler {\n    public PaymentProcessingHandler(OrderHandler nextHandler) {\n        super(nextHandler);\n    }\n\n    @Override\n    public void processOrder(String order) {\n        System.out.println(\"Processing payment for order: \" + order);\n        // Perform payment processing logic here\n\n        // If payment is successful, pass it to the next handler\n        if (nextHandler != null) {\n            nextHandler.processOrder(order);\n        }\n    }\n}\n\n// Concrete handler for order preparation.\nclass OrderPreparationHandler extends OrderHandler {\n    public OrderPreparationHandler(OrderHandler nextHandler) {\n        super(nextHandler);\n    }\n\n    @Override\n    public void processOrder(String order) {\n        System.out.println(\"Preparing order: \" + order);\n        // Perform order preparation logic here\n\n        // If preparation is complete, pass it to the next handler\n        if (nextHandler != null) {\n            nextHandler.processOrder(order);\n        }\n    }\n}\n\n// Concrete handler for delivery assignment.\nclass DeliveryAssignmentHandler extends OrderHandler {\n    public DeliveryAssignmentHandler(OrderHandler nextHandler) {\n        super(nextHandler);\n    }\n\n    @Override\n    public void processOrder(String order) {\n        System.out.println(\"Assigning delivery for order: \" + order);\n        // Perform delivery assignment logic here\n\n        // If delivery is assigned, pass it to the next handler\n        if (nextHandler != null) {\n            nextHandler.processOrder(order);\n        }\n    }\n}\n\n// Concrete handler for order tracking.\nclass OrderTrackingHandler extends OrderHandler {\n    public OrderTrackingHandler(OrderHandler nextHandler) {\n        super(nextHandler);\n    }\n\n    @Override\n    public void processOrder(String order) {\n        System.out.println(\"Tracking order: \" + order);\n        // Perform order tracking logic here\n    }\n}\n\npublic class SwiggyOrder {\n    public static void main(String[] args) {\n        // Create a chain of responsibility for order processing\n        OrderHandler orderProcessingChain = new OrderValidationHandler(\n            new PaymentProcessingHandler(\n                new OrderPreparationHandler(\n                    new DeliveryAssignmentHandler(\n                        new OrderTrackingHandler(null))))); \n                        // The last handler has no next handler\n\n        // Simulate an order being placed\n        String order = \"Pizza\";\n        orderProcessingChain.processOrder(order);\n    }\n}\n"
  },
  {
    "path": "Command Design Pattern/C++/document.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\n// Command Interface\nclass ActionListenerCommand {\npublic:\n    virtual void execute() = 0;\n    virtual ~ActionListenerCommand() {}\n};\n\n// Receiver - performing the operation\nclass Document {\npublic:\n    void open() {\n        cout << \"Document Opened\" << endl;\n    }\n\n    void save() {\n        cout << \"Document Saved\" << endl;\n    }\n};\n\n// Concrete Command\nclass ActionOpen : public ActionListenerCommand {\nprivate:\n    Document* doc;\n\npublic:\n    ActionOpen(Document* document) : doc(document) {}\n\n    void execute() {\n        doc->open();\n    }\n};\n\n// Concrete Command\nclass ActionSave : public ActionListenerCommand {\nprivate:\n    Document* doc;\n\npublic:\n    ActionSave(Document* document) : doc(document) {}\n\n    void execute() {\n        doc->save();\n    }\n};\n\n// Invoker\nclass MenuOptions {\nprivate:\n    vector<ActionListenerCommand*> commands;\n\npublic:\n    void addCommand(ActionListenerCommand* command) {\n        commands.push_back(command);\n    }\n\n    void executeCommands() {\n        for (ActionListenerCommand* command : commands) {\n            command->execute();\n        }\n    }\n};\n\nint main() {\n    Document doc;\n    MenuOptions menu;\n\n    ActionListenerCommand* clickOpen = new ActionOpen(&doc);\n    ActionListenerCommand* clickSave = new ActionSave(&doc);\n\n    menu.addCommand(clickOpen);\n    menu.addCommand(clickSave);\n    \n    // Client code only adds commands to the menu\n    // The invoker (menu) doesn't need to change when new commands are added\n    menu.executeCommands();\n\n    delete clickOpen;\n    delete clickSave;\n\n    return 0;\n}\n"
  },
  {
    "path": "Command Design Pattern/C++/uber_rides.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\n// Receiver: RideService\nclass RideService {\npublic:\n    void requestRide(const string& passenger, const string& srcLoc, const string& destLoc) {\n        cout << \"Requesting a ride for passenger: \" << passenger\n             << \" from \" << srcLoc << \" to \" << destLoc << endl;\n        // Additional ride request processing logic here\n    }\n\n    void cancelRide(const string& passenger) {\n        cout << \"Canceling the ride for passenger: \" << passenger << endl;\n        // Additional cancellation logic here\n    }\n};\n\n// Abstract Command interface\nclass Command {\npublic:\n    virtual void execute() = 0;\n    virtual ~Command() {}\n};\n\n// Concrete Command: RideRequestCommand\nclass RideRequestCommand : public Command {\nprivate:\n    RideService* receiver;\n    string passenger;\n    string srcLoc;\n    string destLoc;\n\npublic:\n    RideRequestCommand(RideService* receiver, const string& passenger, const string& srcLoc, const string& destLoc)\n        : receiver(receiver), passenger(passenger), srcLoc(srcLoc), destLoc(destLoc) {}\n\n    void execute() override {\n        receiver->requestRide(passenger, srcLoc, destLoc);\n    }\n};\n\n// Concrete Command: CancelRideCommand\nclass CancelRideCommand : public Command {\nprivate:\n    RideService* receiver;\n    string passenger;\n\npublic:\n    CancelRideCommand(RideService* receiver, const string& passenger)\n        : receiver(receiver), passenger(passenger) {}\n\n    void execute() override {\n        receiver->cancelRide(passenger);\n    }\n};\n\n// Invoker: RideRequestInvoker\nclass RideRequestInvoker {\npublic:\n    void processRequest(Command* command) {\n        command->execute();\n    }\n};\n\nint main() {\n    // Create a receiver\n    RideService rideService;\n\n    // Create an invoker\n    RideRequestInvoker rideRequestInvoker;\n\n    // Execute ride request and cancellation commands directly\n    Command* request1 = new RideRequestCommand(&rideService, \"Keerti\", \"Sarjapur\", \"Koramangala\");\n    Command* request2 = new RideRequestCommand(&rideService, \"Amit\", \"Koramangala\", \"Indiranagar\");\n    Command* cancel1 = new CancelRideCommand(&rideService, \"Keerti\");\n\n    // Process the ride requests and cancellations\n    rideRequestInvoker.processRequest(request1);\n    rideRequestInvoker.processRequest(request2);\n    rideRequestInvoker.processRequest(cancel1);\n\n    // Clean up\n    delete request1;\n    delete request2;\n    delete cancel1;\n\n    return 0;\n}\n"
  },
  {
    "path": "Command Design Pattern/JAVA/DocumentDemo.java",
    "content": "import java.util.*;\n\n//Command Interface\ninterface ActionListenerCommand {\n    void execute();\n}\n\n//Receiver - performing the operation\nclass Document {\n    public void open() {\n        System.out.println(\"Document Opened\");\n    }\n\n    public void save() {\n        System.out.println(\"Document Saved\");\n    }\n}\n\n//Concrete Command\nclass ActionOpen implements ActionListenerCommand {\n    private Document doc;\n\n    public ActionOpen(Document doc) {\n        this.doc = doc;\n    }\n\n    @Override\n    public void execute() {\n        doc.open();\n    }\n}\n\n//Concrete Command\nclass ActionSave implements ActionListenerCommand {\n    private Document doc;\n\n    public ActionSave(Document doc) {\n        this.doc = doc;\n    }\n\n    @Override\n    public void execute() {\n        doc.save();\n    }\n}\n\n// Invoker\nclass MenuOptions {\n    private List<ActionListenerCommand> commands = new ArrayList<>();\n\n    public void addCommand(ActionListenerCommand command) {\n        commands.add(command);\n    }\n\n    public void executeCommands() {\n        for (ActionListenerCommand command : commands) {\n            command.execute();\n        }\n    }\n}\n\npublic class DocumentDemo {\n    public static void main(String[] args) {\n        Document doc = new Document(); // Receiver - performing action\n\n        // Create concrete commands\n        // Receiver with command\n        ActionListenerCommand clickOpen = new ActionOpen(doc);\n        ActionListenerCommand clickSave = new ActionSave(doc);\n\n        // Invoker\n        MenuOptions menu = new MenuOptions();\n\n        // Client code only adds commands to the menu\n        menu.addCommand(clickOpen);\n        menu.addCommand(clickSave);\n\n        menu.executeCommands();\n    }\n}\n\n\n"
  },
  {
    "path": "Command Design Pattern/JAVA/UberRidesDemo.java",
    "content": "// Receiver: RideService\nclass RideService {\n    public void requestRide(String passenger, String srcLoc, String destLoc) {\n        System.out.println(\"Requesting a ride for passenger: \" + passenger +\n                \" from \" + srcLoc + \" to \" + destLoc);\n        // Additional ride request processing logic here\n    }\n\n    public void cancelRide(String passenger) {\n        System.out.println(\"Canceling the ride for passenger: \" + passenger);\n        // Additional cancellation logic here\n    }\n}\n\n// Abstract Command interface\ninterface Command {\n    void execute();\n}\n\n// Concrete Command: RideRequestCommand\nclass RideRequestCommand implements Command {\n    private RideService receiver;\n    private String passenger;\n    private String srcLoc;\n    private String destLoc;\n\n    public RideRequestCommand(RideService receiver, String passenger, String srcLoc, String destLoc) {\n        this.receiver = receiver;\n        this.passenger = passenger;\n        this.srcLoc = srcLoc;\n        this.destLoc = destLoc;\n    }\n\n    public void execute() {\n        receiver.requestRide(passenger, srcLoc, destLoc);\n    }\n}\n\n// Concrete Command: CancelRideCommand\nclass CancelRideCommand implements Command {\n    private RideService receiver;\n    private String passenger;\n\n    public CancelRideCommand(RideService receiver, String passenger) {\n        this.receiver = receiver;\n        this.passenger = passenger;\n    }\n\n    public void execute() {\n        receiver.cancelRide(passenger);\n    }\n}\n\n// Invoker: RideRequestInvoker\nclass RideRequestInvoker {\n    public void processRequest(Command command) {\n        command.execute();\n    }\n}\n\npublic class UberRidesDemo {\n    public static void main(String[] args) {\n        // Create a receiver\n        RideService rideService = new RideService();\n\n        // Create an invoker\n        RideRequestInvoker rideRequestInvoker = new RideRequestInvoker();\n\n        // Execute ride request and cancellation commands directly\n        Command request1 = new RideRequestCommand(rideService, \"Keerti\", \"Sarjapur\", \"Koramangala\");\n        Command request2 = new RideRequestCommand(rideService, \"Amit\", \"Koramangala\", \"Indiranagar\");\n        Command cancel1 = new CancelRideCommand(rideService, \"Keerti\");\n\n        // Process the ride requests and cancellations\n        rideRequestInvoker.processRequest(request1);\n        rideRequestInvoker.processRequest(request2);\n        rideRequestInvoker.processRequest(cancel1);\n\n        // Clean up (not required in Java)\n    }\n}\n"
  },
  {
    "path": "Composite Design Pattern/C++/directorystructure.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\nclass FileSystemComponent {\npublic:\n    virtual void listContents() const = 0;\n    virtual int getSize() const = 0;\n};\n\nclass File : public FileSystemComponent {\nprivate:\n    string name;\n    int size;\n\npublic:\n    File(const string& fileName, int fileSize) : name(fileName), size(fileSize) {}\n\n    void listContents() const override {\n        cout << \"File: \" << name << endl;\n    }\n\n    int getSize() const override {\n        return size;\n    }\n};\n\n#include <vector>\n\nclass Directory : public FileSystemComponent {\nprivate:\n    string name;\n    vector<FileSystemComponent*> contents;\n\npublic:\n    Directory(const string& dirName) : name(dirName) {}\n\n    void addComponent(FileSystemComponent* component) {\n        contents.push_back(component);\n    }\n\n    void listContents() const override {\n        cout << \"Directory: \" << name << endl;\n        for (const auto& component : contents) {\n            component->listContents();\n        }\n    }\n\n    int getSize() const override {\n        int totalSize = 0;\n        for (const auto& component : contents) {\n            totalSize += component->getSize();\n        }\n        return totalSize;\n    }\n};\n\nint main() {\n    Directory* root = new Directory(\"Root\");\n\n    FileSystemComponent* file1 = new File(\"Document.txt\", 100);\n    FileSystemComponent* file2 = new File(\"Image.jpg\", 200);\n\n    Directory* subDir = new Directory(\"Subdirectory\");\n    FileSystemComponent* file3 = new File(\"Data.csv\", 150);\n\n    subDir->addComponent(file3);\n\n    root->addComponent(file1);\n    root->addComponent(file2);\n    root->addComponent(subDir);\n\n    // List contents and calculate total size for the directory structure\n    root->listContents();\n    int totalSize = root->getSize();\n    cout << \"Total Size: \" << totalSize << \" KB\" << endl;\n\n    // Clean up memory (consider using smart pointers in a real application)\n    delete root;\n    delete file1;\n    delete file2;\n    delete file3;\n    delete subDir;\n\n    return 0;\n}"
  },
  {
    "path": "Composite Design Pattern/C++/employee.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\nclass EmployeeComponent {\npublic:\n    virtual void displayInfo() = 0;\n    virtual double calculateSalary() = 0;\n    virtual ~EmployeeComponent() {}\n};\n\nclass Employee : public EmployeeComponent {\nprivate:\n    string name;\n    double salary;\n\npublic:\n    Employee(string empName, double empSalary) : name(empName), salary(empSalary) {}\n\n    void displayInfo() override {\n        cout << \"Employee: \" << name << \" Salary: Rs.\" << salary << endl;\n    }\n\n    double calculateSalary() override {\n        return salary;\n    }\n};\n\nclass Department : public EmployeeComponent {\nprivate:\n    string name;\n    vector<EmployeeComponent*> members;\n\npublic:\n    Department(string deptName) : name(deptName) {}\n\n    void addMember(EmployeeComponent* member) {\n        members.push_back(member);\n    }\n\n    void displayInfo() override {\n        cout << \"Department: \" << name << endl;\n        for (auto member : members) {\n            member->displayInfo();\n        }\n    }\n\n    double calculateSalary() override {\n        double totalSalary = 0.0;\n        for (auto member : members) {\n            totalSalary += member->calculateSalary();\n        }\n        return totalSalary;\n    }\n};\n\nclass Team : public EmployeeComponent {\nprivate:\n    string name;\n    vector<EmployeeComponent*> members;\n\npublic:\n    Team(string teamName) : name(teamName) {}\n\n    void addMember(EmployeeComponent* member) {\n        members.push_back(member);\n    }\n\n    void displayInfo() override {\n        cout << \"Team: \" << name << endl;\n        for (auto& member : members) {\n            member->displayInfo();\n        }\n    }\n\n    double calculateSalary() override {\n        double totalSalary = 0.0;\n        for (auto member : members) {\n            totalSalary += member->calculateSalary();\n        }\n        return totalSalary;\n    }\n};\n\n\nint main() {\n    EmployeeComponent* keerti = new Employee(\"Keerti\", 100.0);\n    EmployeeComponent* amit = new Employee(\"Amit\", 200.0);\n\n    Team* sales = new Team(\"Sales\");\n    sales->addMember(keerti);\n    sales->addMember(amit);\n\n    EmployeeComponent* bob = new Employee(\"Bob\", 50.0);\n\n    Team* marketing = new Team(\"Marketing\");\n    marketing->addMember(bob);\n\n    Department* headOffice = new Department(\"Head Office\");\n    headOffice->addMember(sales);\n    headOffice->addMember(marketing);\n\n    // Display and calculate total salary for the organization hierarchy\n    headOffice->displayInfo();\n    double totalSalary = headOffice->calculateSalary();\n    cout << \"Total Salary for the Organization: Rs.\" << totalSalary << endl;\n\n    // Clean up memory (consider using smart pointers in a real application)\n    delete keerti;\n    delete amit;\n    delete sales;\n    delete bob;\n    delete marketing;\n    delete headOffice;\n\n    return 0;\n}\n\n"
  },
  {
    "path": "Composite Design Pattern/JAVA/EmployeesDemo.java",
    "content": "import java.util.*;\n\nabstract class EmployeeComponent {\n    public abstract void displayInfo();\n    public abstract double calculateSalary();\n}\n\nclass Employee extends EmployeeComponent {\n    private String name;\n    private double salary;\n\n    public Employee(String empName, double empSalary) {\n        name = empName;\n        salary = empSalary;\n    }\n\n    @Override\n    public void displayInfo() {\n        System.out.println(\"Employee: \" + name + \" Salary: Rs.\" + salary);\n    }\n\n    @Override\n    public double calculateSalary() {\n        return salary;\n    }\n}\n\nclass Department extends EmployeeComponent {\n    private String name;\n    private List<EmployeeComponent> members;\n\n    public Department(String deptName) {\n        name = deptName;\n        members = new ArrayList<>();\n    }\n\n    public void addMember(EmployeeComponent member) {\n        members.add(member);\n    }\n\n    @Override\n    public void displayInfo() {\n        System.out.println(\"Department: \" + name);\n        for (EmployeeComponent member : members) {\n            member.displayInfo();\n        }\n    }\n\n    @Override\n    public double calculateSalary() {\n        double totalSalary = 0.0;\n        for (EmployeeComponent member : members) {\n            totalSalary += member.calculateSalary();\n        }\n        return totalSalary;\n    }\n}\n\nclass Team extends EmployeeComponent {\n    private String name;\n    private List<EmployeeComponent> members;\n\n    public Team(String teamName) {\n        name = teamName;\n        members = new ArrayList<>();\n    }\n\n    public void addMember(EmployeeComponent member) {\n        members.add(member);\n    }\n\n    @Override\n    public void displayInfo() {\n        System.out.println(\"Team: \" + name);\n        for (EmployeeComponent member : members) {\n            member.displayInfo();\n        }\n    }\n\n    @Override\n    public double calculateSalary() {\n        double totalSalary = 0.0;\n        for (EmployeeComponent member : members) {\n            totalSalary += member.calculateSalary();\n        }\n        return totalSalary;\n    }\n}\n\npublic class EmployeesDemo {\n    public static void main(String[] args) {\n        EmployeeComponent keerti = new Employee(\"Keerti\", 100.0);\n        EmployeeComponent amit = new Employee(\"Amit\", 200.0);\n\n        Team sales = new Team(\"Sales\");\n        sales.addMember(keerti);\n        sales.addMember(amit);\n\n        EmployeeComponent bob = new Employee(\"Bob\", 50.0);\n\n        Team marketing = new Team(\"Marketing\");\n        marketing.addMember(bob);\n\n        Department headOffice = new Department(\"Head Office\");\n        headOffice.addMember(sales);\n        headOffice.addMember(marketing);\n\n        // Display and calculate total salary for the organization hierarchy\n        headOffice.displayInfo();\n        double totalSalary = headOffice.calculateSalary();\n        System.out.println(\"Total Salary for the Organization: Rs.\" + totalSalary);\n    }\n}\n"
  },
  {
    "path": "Composite Design Pattern/JAVA/directorystructure.java",
    "content": "import java.util.*;\n\n// Abstraction Layer\ninterface FileSystemComponent {\n    void listContents();\n    int getSize();\n}\n\n// Concrete Implementation: File\nclass File implements FileSystemComponent {\n    private String name;\n    private int size;\n\n    public File(String fileName, int fileSize) {\n        this.name = fileName;\n        this.size = fileSize;\n    }\n\n    @Override\n    public void listContents() {\n        System.out.println(\"File: \" + name);\n    }\n\n    @Override\n    public int getSize() {\n        return size;\n    }\n}\n\n// Concrete Implementation: Directory\nclass Directory implements FileSystemComponent {\n    private String name;\n    private List<FileSystemComponent> contents;\n\n    public Directory(String dirName) {\n        this.name = dirName;\n        this.contents = new ArrayList<>();\n    }\n\n    public void addComponent(FileSystemComponent component) {\n        contents.add(component);\n    }\n\n    @Override\n    public void listContents() {\n        System.out.println(\"Directory: \" + name);\n        for (FileSystemComponent component : contents) {\n            component.listContents();\n        }\n    }\n\n    @Override\n    public int getSize() {\n        int totalSize = 0;\n        for (FileSystemComponent component : contents) {\n            totalSize += component.getSize();\n        }\n        return totalSize;\n    }\n}\n\npublic class directorystructure {\n    public static void main(String[] args) {\n        Directory root = new Directory(\"Root\");\n\n        FileSystemComponent file1 = new File(\"Document.txt\", 100);\n        FileSystemComponent file2 = new File(\"Image.jpg\", 200);\n\n        Directory subDir = new Directory(\"Subdirectory\");\n        FileSystemComponent file3 = new File(\"Data.csv\", 150);\n\n        subDir.addComponent(file3);\n\n        root.addComponent(file1);\n        root.addComponent(file2);\n        root.addComponent(subDir);\n\n        // List contents and calculate total size for the directory structure\n        root.listContents();\n        int totalSize = root.getSize();\n        System.out.println(\"Total Size: \" + totalSize + \" KB\");\n\n        // Clean up memory (consider using automatic memory management in a real application)\n        // No need to explicitly delete objects in Java\n    }\n}\n"
  },
  {
    "path": "Decorator Design Pattern/C++/swiggy.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// Base interface representing a food item.\n// Component\nclass FoodItem\n{\npublic:\n    virtual string getDescription() = 0;\n    virtual double getPrice() = 0;\n    virtual ~FoodItem() {}\n};\n\n// Concrete component\nclass Pizza : public FoodItem\n{\npublic:\n    string getDescription()\n    {\n        return \"Pizza\";\n    }\n\n    double getPrice()\n    {\n        return 200.0;\n    }\n};\n\n// Concrete component\nclass Burger : public FoodItem\n{\npublic:\n    string getDescription()\n    {\n        return \"Burger\";\n    }\n\n    double getPrice()\n    {\n        return 100.0;\n    }\n};\n\nclass Decorator : public FoodItem\n{\nprotected:\n    FoodItem *foodItem;\n\npublic:\n    Decorator(FoodItem *item) : foodItem(item) {}\n};\n\n// Concrete decorator for adding extra cheese.\nclass ExtraCheeseDecorator : public Decorator\n{\nprivate:\n    double extraCheesePrice;\n\npublic:\n    ExtraCheeseDecorator(FoodItem *item, double price)\n        : Decorator(item), extraCheesePrice(price) {}\n\n    string getDescription()\n    {\n        return foodItem->getDescription() + \" with Extra Cheese\";\n    }\n\n    double getPrice()\n    {\n        return foodItem->getPrice() + extraCheesePrice;\n    }\n};\n\n// Concrete decorator for adding extra sauce.\nclass ExtraSauceDecorator : public Decorator\n{\nprivate:\n    double extraSaucePrice;\n\npublic:\n    ExtraSauceDecorator(FoodItem *item, double price)\n        : Decorator(item), extraSaucePrice(price) {}\n\n    string getDescription()\n    {\n        return foodItem->getDescription() + \" with Extra Sauce\";\n    }\n\n    double getPrice()\n    {\n        return foodItem->getPrice() + extraSaucePrice;\n    }\n};\n\n// Concrete decorator for adding extra toppings.\nclass ExtraToppingsDecorator : public Decorator\n{\nprivate:\n    double extraToppingsPrice;\n\npublic:\n    ExtraToppingsDecorator(FoodItem *item, double price)\n        : Decorator(item), extraToppingsPrice(price) {}\n\n    string getDescription()\n    {\n        return foodItem->getDescription() + \" with Extra Toppings\";\n    }\n\n    double getPrice()\n    {\n        return foodItem->getPrice() + extraToppingsPrice;\n    }\n};\n\nint main()\n{\n    // Order a Pizza and a Burger.\n    FoodItem *pizzaOrder = new Pizza();\n    FoodItem *burgerOrder = new Burger();\n\n    pizzaOrder = new ExtraCheeseDecorator(pizzaOrder, 10.0);\n    pizzaOrder = new ExtraSauceDecorator(pizzaOrder, 5.0);\n\n    burgerOrder = new ExtraCheeseDecorator(burgerOrder, 20.0);\n    burgerOrder = new ExtraToppingsDecorator(burgerOrder, 15.0);\n\n    cout << \"Description of pizza order is \" << pizzaOrder->getDescription() << endl;\n    cout << \"Price of pizza order is : \" << pizzaOrder->getPrice() << endl;\n\n    cout << \"Description of burger order is \" << burgerOrder->getDescription() << endl;\n    cout << \"Price of burger order is : \" << burgerOrder->getPrice() << endl;\n\n    // Clean up allocated memory\n    delete burgerOrder;\n    delete pizzaOrder;\n\n    return 0;\n}\n"
  },
  {
    "path": "Decorator Design Pattern/JAVA/Swiggy.java",
    "content": "// Base interface representing a food item.\n// Component\ninterface FoodItem {\n    String getDescription();\n    double getPrice();\n}\n\n// Concrete component\nclass Pizza implements FoodItem {\n    public String getDescription() {\n        return \"Pizza\";\n    }\n\n    public double getPrice() {\n        return 200.0;\n    }\n}\n\n// Concrete component\nclass Burger implements FoodItem {\n    public String getDescription() {\n        return \"Burger\";\n    }\n\n    public double getPrice() {\n        return 100.0;\n    }\n}\n\n// Decorator interface\nabstract class Decorator implements FoodItem {\n    protected FoodItem foodItem;\n\n    public Decorator(FoodItem item) {\n        this.foodItem = item;\n    }\n}\n\n// Concrete decorator for adding extra cheese.\nclass ExtraCheeseDecorator extends Decorator {\n    private double extraCheesePrice;\n\n    public ExtraCheeseDecorator(FoodItem item, double price) {\n        super(item);\n        this.extraCheesePrice = price;\n    }\n\n    public String getDescription() {\n        return foodItem.getDescription() + \" with Extra Cheese\";\n    }\n\n    public double getPrice() {\n        return foodItem.getPrice() + extraCheesePrice;\n    }\n}\n\n// Concrete decorator for adding extra sauce.\nclass ExtraSauceDecorator extends Decorator {\n    private double extraSaucePrice;\n\n    public ExtraSauceDecorator(FoodItem item, double price) {\n        super(item);\n        this.extraSaucePrice = price;\n    }\n\n    public String getDescription() {\n        return foodItem.getDescription() + \" with Extra Sauce\";\n    }\n\n    public double getPrice() {\n        return foodItem.getPrice() + extraSaucePrice;\n    }\n}\n\n// Concrete decorator for adding extra toppings.\nclass ExtraToppingsDecorator extends Decorator {\n    private double extraToppingsPrice;\n\n    public ExtraToppingsDecorator(FoodItem item, double price) {\n        super(item);\n        this.extraToppingsPrice = price;\n    }\n\n    public String getDescription() {\n        return foodItem.getDescription() + \" with Extra Toppings\";\n    }\n\n    public double getPrice() {\n        return foodItem.getPrice() + extraToppingsPrice;\n    }\n}\n\npublic class Swiggy {\n    public static void main(String[] args) {\n        // Order a Pizza and a Burger.\n        FoodItem pizzaOrder = new Pizza();\n        FoodItem burgerOrder = new Burger();\n\n        pizzaOrder = new ExtraCheeseDecorator(pizzaOrder, 10.0);\n        pizzaOrder = new ExtraSauceDecorator(pizzaOrder, 5.0);\n\n        burgerOrder = new ExtraCheeseDecorator(burgerOrder, 20.0);\n        burgerOrder = new ExtraToppingsDecorator(burgerOrder, 15.0);\n\n        System.out.println(\"Description of pizza order is \" + pizzaOrder.getDescription());\n        System.out.println(\"Price of pizza order is: \" + pizzaOrder.getPrice());\n\n        System.out.println(\"Description of burger order is \" + burgerOrder.getDescription());\n        System.out.println(\"Price of burger order is: \" + burgerOrder.getPrice());\n    }\n}\n"
  },
  {
    "path": "Facade Design Pattern/C++/computer.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// Subsystem 1: CPU\nclass CPU {\npublic:\n    void powerOn() {\n        cout << \"CPU is powered on.\" << endl;\n    }\n\n    void executeInstructions() {\n        cout << \"CPU is executing instructions.\" << endl;\n    }\n};\n\n// Subsystem 2: Memory\nclass Memory {\npublic:\n    void initialize() {\n        cout << \"Memory is initialized.\" << endl;\n    }\n};\n\n// Subsystem 3: GPU\nclass GPU {\npublic:\n    void enableGraphics() {\n        cout << \"GPU graphics are enabled.\" << endl;\n    }\n};\n\n// Subsystem 4: Disk Drive\nclass DiskDrive {\npublic:\n    void bootFromDisk() {\n        cout << \"Booting from the disk drive.\" << endl;\n    }\n};\n\n// Subsystem 5: Network Interface\nclass NetworkInterface {\npublic:\n    void connectToNetwork() {\n        cout << \"Connected to the network.\" << endl;\n    }\n};\n\n// Facade: Computer System\nclass ComputerSystemFacade {\nprivate:\n    CPU cpu;\n    Memory memory;\n    GPU gpu;\n    DiskDrive diskDrive;\n    NetworkInterface networkInterface;\n\npublic:\n    void startComputer() {\n        cout << \"Starting the computer...\" << endl;\n        cpu.powerOn();\n        memory.initialize();\n        gpu.enableGraphics();\n        diskDrive.bootFromDisk();\n        networkInterface.connectToNetwork();\n        cpu.executeInstructions();\n        cout << \"Computer is ready to use.\" << endl;\n    }\n};\n\nint main() {\n    ComputerSystemFacade computer;\n\n    // User initiates the computer startup process with a single call\n    computer.startComputer();\n\n    return 0;\n}\n"
  },
  {
    "path": "Facade Design Pattern/JAVA/ComputerDemo.java",
    "content": "// Subsystem 1: CPU\nclass CPU {\n    public void powerOn() {\n        System.out.println(\"CPU is powered on.\");\n    }\n\n    public void executeInstructions() {\n        System.out.println(\"CPU is executing instructions.\");\n    }\n}\n\n// Subsystem 2: Memory\nclass Memory {\n    public void initialize() {\n        System.out.println(\"Memory is initialized.\");\n    }\n}\n\n// Subsystem 3: GPU\nclass GPU {\n    public void enableGraphics() {\n        System.out.println(\"GPU graphics are enabled.\");\n    }\n}\n\n// Subsystem 4: Disk Drive\nclass DiskDrive {\n    public void bootFromDisk() {\n        System.out.println(\"Booting from the disk drive.\");\n    }\n}\n\n// Subsystem 5: Network Interface\nclass NetworkInterface {\n    public void connectToNetwork() {\n        System.out.println(\"Connected to the network.\");\n    }\n}\n\n// Facade: Computer System\nclass ComputerSystemFacade {\n    private CPU cpu;\n    private Memory memory;\n    private GPU gpu;\n    private DiskDrive diskDrive;\n    private NetworkInterface networkInterface;\n\n    public ComputerSystemFacade() {\n        this.cpu = new CPU();\n        this.memory = new Memory();\n        this.gpu = new GPU();\n        this.diskDrive = new DiskDrive();\n        this.networkInterface = new NetworkInterface();\n    }\n\n    public void startComputer() {\n        System.out.println(\"Starting the computer...\");\n        cpu.powerOn();\n        memory.initialize();\n        gpu.enableGraphics();\n        diskDrive.bootFromDisk();\n        networkInterface.connectToNetwork();\n        cpu.executeInstructions();\n        System.out.println(\"Computer is ready to use.\");\n    }\n}\n\npublic class ComputerDemo {\n    public static void main(String[] args) {\n        ComputerSystemFacade computer = new ComputerSystemFacade();\n\n        // User initiates the computer startup process with a single call\n        computer.startComputer();\n    }\n}\n"
  },
  {
    "path": "Factory Method Design Pattern/Furniture/C++/furniture.cpp",
    "content": "//The Factory Method pattern is a creational design pattern that defines an interface for creating objects but lets subclasses alter the type of objects that will be created.\n\n#include <iostream>\n#include <string>\n\n// Abstract Product: Furniture Item\nclass FurnitureItem {\npublic:\n    virtual void display() = 0;\n};\n\n// Concrete Products: Sofa, Chair, Table\nclass Sofa : public FurnitureItem {\npublic:\n    void display() override {\n        std::cout << \"Sofa\" << std::endl;\n    }\n};\n\nclass Chair : public FurnitureItem {\npublic:\n    void display() override {\n        std::cout << \"Chair\" << std::endl;\n    }\n};\n\nclass Table : public FurnitureItem {\npublic:\n    void display() override {\n        std::cout << \"Table\" << std::endl;\n    }\n};\n\n// Abstract Creator: Furniture Factory\nclass FurnitureFactory {\npublic:\n    virtual FurnitureItem* createFurniture() = 0;\n};\n\n// Concrete Creators: Sofa Factory, Chair Factory, Table Factory\nclass SofaFactory : public FurnitureFactory {\npublic:\n    FurnitureItem* createFurniture() override {\n        return new Sofa();\n    }\n};\n\nclass ChairFactory : public FurnitureFactory {\npublic:\n    FurnitureItem* createFurniture() override {\n        return new Chair();\n    }\n};\n\nclass TableFactory : public FurnitureFactory {\npublic:\n    FurnitureItem* createFurniture() override {\n        return new Table();\n    }\n};\n\nint main() {\n    // Create factories for different types of furniture\n    FurnitureFactory* sofaFactory = new SofaFactory();\n    FurnitureFactory* chairFactory = new ChairFactory();\n    FurnitureFactory* tableFactory = new TableFactory();\n\n    // Create furniture objects using the factory methods\n    FurnitureItem* sofa = sofaFactory->createFurniture();\n    FurnitureItem* chair = chairFactory->createFurniture();\n    FurnitureItem* table = tableFactory->createFurniture();\n\n    // Display the created furniture items\n    sofa->display();\n    chair->display();\n    table->display();\n\n    // Clean up objects\n    delete sofaFactory;\n    delete chairFactory;\n    delete tableFactory;\n    delete sofa;\n    delete chair;\n    delete table;\n\n    return 0;\n}"
  },
  {
    "path": "Factory Method Design Pattern/Furniture/JAVA/furniture.java",
    "content": "// Abstract Product: Furniture Item\ninterface FurnitureItem {\n    void display();\n}\n\n// Concrete Products: Sofa, Chair, Table\nclass Sofa implements FurnitureItem {\n    @Override\n    public void display() {\n        System.out.println(\"Sofa\");\n    }\n}\n\nclass Chair implements FurnitureItem {\n    @Override\n    public void display() {\n        System.out.println(\"Chair\");\n    }\n}\n\nclass Table implements FurnitureItem {\n    @Override\n    public void display() {\n        System.out.println(\"Table\");\n    }\n}\n\n// Abstract Creator: Furniture Factory\ninterface FurnitureFactory {\n    FurnitureItem createFurniture();\n}\n\n// Concrete Creators: Sofa Factory, Chair Factory, Table Factory\nclass SofaFactory implements FurnitureFactory {\n    @Override\n    public FurnitureItem createFurniture() {\n        return new Sofa();\n    }\n}\n\nclass ChairFactory implements FurnitureFactory {\n    @Override\n    public FurnitureItem createFurniture() {\n        return new Chair();\n    }\n}\n\nclass TableFactory implements FurnitureFactory {\n    @Override\n    public FurnitureItem createFurniture() {\n        return new Table();\n    }\n}\n\npublic class furniture {\n    public static void main(String[] args) {\n        // Create factories for different types of furniture\n        FurnitureFactory sofaFactory = new SofaFactory();\n        FurnitureFactory chairFactory = new ChairFactory();\n        FurnitureFactory tableFactory = new TableFactory();\n\n        // Create furniture objects using the factory methods\n        FurnitureItem sofa = sofaFactory.createFurniture();\n        FurnitureItem chair = chairFactory.createFurniture();\n        FurnitureItem table = tableFactory.createFurniture();\n\n        // Display the created furniture items\n        sofa.display();\n        chair.display();\n        table.display();\n    }\n}"
  },
  {
    "path": "Factory Method Design Pattern/Furniture/Javascript/furniture.js",
    "content": "// Abstract Product: Furniture Item\nclass FurnitureItem {\n    display() {}\n}\n\n// Concrete Products: Sofa, Chair, Table\nclass Sofa extends FurnitureItem {\n    display() {\n        console.log(\"Sofa\");\n    }\n}\n\nclass Chair extends FurnitureItem {\n    display() {\n        console.log(\"Chair\");\n    }\n}\n\nclass Table extends FurnitureItem {\n    display() {\n        console.log(\"Table\");\n    }\n}\n\n// Abstract Creator: Furniture Factory\nclass FurnitureFactory {\n    createFurniture() {}\n}\n\n// Concrete Creators: Sofa Factory, Chair Factory, Table Factory\nclass SofaFactory extends FurnitureFactory {\n    createFurniture() {\n        return new Sofa();\n    }\n}\n\nclass ChairFactory extends FurnitureFactory {\n    createFurniture() {\n        return new Chair();\n    }\n}\n\nclass TableFactory extends FurnitureFactory {\n    createFurniture() {\n        return new Table();\n    }\n}\n\nfunction main() {\n    // Create factories for different types of furniture\n    const sofaFactory = new SofaFactory();\n    const chairFactory = new ChairFactory();\n    const tableFactory = new TableFactory();\n\n    // Create furniture objects using the factory methods\n    const sofa = sofaFactory.createFurniture();\n    const chair = chairFactory.createFurniture();\n    const table = tableFactory.createFurniture();\n\n    // Display the created furniture items\n    sofa.display();\n    chair.display();\n    table.display();\n}\n\nmain();\n"
  },
  {
    "path": "Factory Method Design Pattern/Furniture/Python/furniture.py",
    "content": "# Abstract Product: Furniture Item\nclass FurnitureItem:\n    def display(self):\n        pass\n\n# Concrete Products: Sofa, Chair, Table\nclass Sofa(FurnitureItem):\n    def display(self):\n        print(\"Sofa\")\n\nclass Chair(FurnitureItem):\n    def display(self):\n        print(\"Chair\")\n\nclass Table(FurnitureItem):\n    def display(self):\n        print(\"Table\")\n\n# Abstract Creator: Furniture Factory\nclass FurnitureFactory:\n    def create_furniture(self):\n        pass\n\n# Concrete Creators: Sofa Factory, Chair Factory, Table Factory\nclass SofaFactory(FurnitureFactory):\n    def create_furniture(self):\n        return Sofa()\n\nclass ChairFactory(FurnitureFactory):\n    def create_furniture(self):\n        return Chair()\n\nclass TableFactory(FurnitureFactory):\n    def create_furniture(self):\n        return Table()\n\ndef main():\n    # Create factories for different types of furniture\n    sofa_factory = SofaFactory()\n    chair_factory = ChairFactory()\n    table_factory = TableFactory()\n\n    # Create furniture objects using the factory methods\n    sofa = sofa_factory.create_furniture()\n    chair = chair_factory.create_furniture()\n    table = table_factory.create_furniture()\n\n    # Display the created furniture items\n    sofa.display()\n    chair.display()\n    table.display()\n\nif __name__ == \"__main__\":\n    main()\n"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/common.hpp",
    "content": "#pragma once\n\n#include <iostream>\n\nusing namespace std;\n\nenum class LogLevel {\n    DEBUG,\n    INFO,\n    ERROR\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/debug_logger.cpp",
    "content": "#include \"debug_logger.hpp\"\n\nvoid DebugLogger::log(const string &msg)\n{\n    cout << \"DEBUG : \" << msg << endl;\n}"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/debug_logger.hpp",
    "content": "#pragma once\n#include \"ilogger.hpp\"\n\nclass DebugLogger : public ILogger {\n    public:\n        void log(const string& msg);\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/debug_logger_factory.hpp",
    "content": "#pragma once\n\n#include \"logger_factory.hpp\"\n\nclass DebugLoggerFactory : public ILoggerFactory{\n    public:\n        ILogger* createLogger() {\n            return new DebugLogger();\n        }\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/error_logger.cpp",
    "content": "#include \"error_logger.hpp\"\n\nvoid ErrorLogger::log(const string& msg) {\n    cout<<\"ERROR : \"<<msg<<endl;\n}"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/error_logger.hpp",
    "content": "#pragma once\n#include \"ilogger.hpp\"\n\nclass ErrorLogger : public ILogger{\n    public:\n        void log(const string& msg);\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/error_logger_factory.hpp",
    "content": "#pragma once\n\n#include \"logger_factory.hpp\"\n\nclass ErrorLoggerFactory : public ILoggerFactory{\n    public:\n        ILogger* createLogger() {\n            return new ErrorLogger();\n        }\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/ilogger.hpp",
    "content": "#pragma once\n#include \"common.hpp\"\n\nclass ILogger {\n    public:\n        virtual void log(const string& msg) = 0;\n        virtual ~ILogger() {}\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/info_logger.cpp",
    "content": "#include \"info_logger.hpp\"\n\nvoid InfoLogger::log(const string& msg) {\n    cout<<\"INFO : \"<<msg<<endl;\n}"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/info_logger.hpp",
    "content": "#pragma once\n#include \"ilogger.hpp\"\n\nclass InfoLogger : public ILogger {\n    public:\n        void log(const string& msg);\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/info_logger_factory.hpp",
    "content": "#pragma once\n\n#include \"logger_factory.hpp\"\n\nclass InfoLoggerFactory : public ILoggerFactory{\n    public:\n        ILogger* createLogger() {\n            return new InfoLogger();\n        }\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/logger_factory.hpp",
    "content": "#pragma once\n#include \"ilogger.hpp\"\n#include \"debug_logger.hpp\"\n#include \"info_logger.hpp\"\n#include \"error_logger.hpp\"\n\nclass ILoggerFactory {\n    public:\n        virtual ILogger* createLogger() = 0;\n};"
  },
  {
    "path": "Factory Method Design Pattern/Logger/C++/main.cpp",
    "content": "#include \"info_logger_factory.hpp\"\n#include \"debug_logger_factory.hpp\"\n#include \"error_logger_factory.hpp\"\n\nint main() {\n    ILoggerFactory* loggerFactory1 = new InfoLoggerFactory;\n    ILogger* infoLogger = loggerFactory1->createLogger();\n\n    ILoggerFactory* loggerFactory2 = new ErrorLoggerFactory;\n    ILogger* errorLogger = loggerFactory2->createLogger();\n\n    ILoggerFactory* loggerFactory3 = new DebugLoggerFactory;\n    ILogger* debugLogger = loggerFactory3->createLogger();\n\n    debugLogger->log(\"This is a debug log msg\");\n    infoLogger->log(\"This is an info log msg\");\n    errorLogger->log(\"This is an error log msg\");\n\n    delete debugLogger;\n    delete infoLogger;\n    delete errorLogger;\n\n    return 0;\n}"
  },
  {
    "path": "Factory Method Design Pattern/Logger/JAVA/LoggerDemo.java",
    "content": "interface ILogger {\n    void log(String msg);\n}\n\nclass DebugLogger implements ILogger {\n    @Override\n    public void log(String msg) {\n        System.out.println(\"DEBUG : \" + msg);\n    }\n}\n\nclass ErrorLogger implements ILogger {\n    @Override\n    public void log(String msg) {\n        System.out.println(\"ERROR : \" + msg);\n    }\n}\n\nclass InfoLogger implements ILogger {\n    @Override\n    public void log(String msg) {\n        System.out.println(\"INFO : \" + msg);\n    }\n}\n\ninterface LoggerFactory {\n    ILogger createLogger();\n}\n\nclass DebugLoggerFactory implements LoggerFactory {\n    @Override\n    public ILogger createLogger() {\n        return new DebugLogger();\n    }\n}\n\nclass ErrorLoggerFactory implements LoggerFactory {\n    @Override\n    public ILogger createLogger() {\n        return new ErrorLogger();\n    }\n}\n\nclass InfoLoggerFactory implements LoggerFactory {\n    @Override\n    public ILogger createLogger() {\n        return new InfoLogger();\n    }\n}\n\npublic class LoggerDemo {\n    public static void main(String[] args) {\n        LoggerFactory loggerFactory = new InfoLoggerFactory();\n        ILogger logger = loggerFactory.createLogger();\n\n        logger.log(\"This is an info log message\");\n    }\n}\n"
  },
  {
    "path": "Iterator Design Pattern/C++/amazon_inventory.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\n// Product class representing individual products\nclass Product {\n    private:\n        string name;\n        double price;\n\n    public:\n        Product(const string& name, const double& price) : name(name), price(price) {}\n\n        const string& getName() const {\n            return name;\n        }\n\n        double getPrice() const {\n            return price;\n        }\n};\n\n// Iterator interface\nclass Iterator {\n    public:\n        virtual ~Iterator() {}\n        virtual Product* first() = 0;\n        virtual Product* next() = 0;\n        virtual bool hasNext() = 0;\n};\n\n// Concrete iterator for the product collection\nclass ProductIterator : public Iterator {\n    private:\n\n        vector<Product*>& products;\n        size_t current;\n\n    public:\n\n        ProductIterator(vector<Product*>& products) : products(products), current(0) {}\n\n        Product* first() {\n            if (products.empty()) {\n                return nullptr;\n            }\n            current = 0;\n            return products[current];\n        }\n\n        Product* next() {\n            if (hasNext()) {\n                return products[++current];\n            }\n            return nullptr;\n        }\n\n        bool hasNext() {\n            return current < products.size();\n        }\n};\n\n// Aggregate class that stores products and provides an iterator\nclass Inventory {\n    private:\n        vector<Product*> products;\n    public:\n        void addProduct(Product* product) {\n            products.push_back(product);\n        }\n\n        Iterator* createIterator() {\n            return new ProductIterator(products);\n        }\n};\n\n\nint main() {\n\n    // Create some products\n    Product product1(\"Laptop\", 99999.99);\n    Product product2(\"Smartphone\", 49999.99);\n    Product product3(\"Headphones\", 7999.99);\n\n    // Create an inventory and add products\n    Inventory inventory;\n    inventory.addProduct(&product1);\n    inventory.addProduct(&product2);\n    inventory.addProduct(&product3);\n\n    // Create an iterator and iterate over the products\n    Iterator* iterator = inventory.createIterator();\n    Product* currentProduct = iterator->first();\n\n    while (currentProduct) {\n        cout << \"Product: \" << currentProduct->getName() << \n                        \", Price: $\" << currentProduct->getPrice() << std::endl;\n        currentProduct = iterator->next();\n    }\n\n    delete iterator;\n\n    return 0;\n}"
  },
  {
    "path": "Iterator Design Pattern/JAVA/AmazonInventory.java",
    "content": "import java.util.*;\n\n// Product class representing individual products\nclass Product {\n    private String name;\n    private double price;\n\n    public Product(String name, double price) {\n        this.name = name;\n        this.price = price;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public double getPrice() {\n        return price;\n    }\n}\n\n// Iterator interface\ninterface Iterator {\n    Product first();\n    Product next();\n    boolean hasNext();\n}\n\n// Concrete iterator for the product collection\nclass ProductIterator implements Iterator {\n    private List<Product> products;\n    private int current;\n\n    public ProductIterator(List<Product> products) {\n        this.products = products;\n        this.current = 0;\n    }\n\n    public Product first() {\n        if (products.isEmpty()) {\n            return null;\n        }\n        current = 0;\n        return products.get(current);\n    }\n\n    public Product next() {\n        if (hasNext()) {\n            return products.get(++current);\n        }\n        return null;\n    }\n\n    public boolean hasNext() {\n        return current < products.size() - 1;\n    }\n}\n\n// Aggregate class that stores products and provides an iterator\nclass Inventory {\n    private List<Product> products = new ArrayList<>();\n\n    public void addProduct(Product product) {\n        products.add(product);\n    }\n\n    public Iterator createIterator() {\n        return new ProductIterator(products);\n    }\n}\n\npublic class AmazonInventory {\n    public static void main(String[] args) {\n        // Create some products\n        Product product1 = new Product(\"Laptop\", 99999.99);\n        Product product2 = new Product(\"Smartphone\", 49999.99);\n        Product product3 = new Product(\"Headphones\", 7999.99);\n\n        // Create an inventory and add products\n        Inventory inventory = new Inventory();\n        inventory.addProduct(product1);\n        inventory.addProduct(product2);\n        inventory.addProduct(product3);\n\n        // Create an iterator and iterate over the products\n        Iterator iterator = inventory.createIterator();\n        Product currentProduct = iterator.first();\n\n        while (currentProduct != null) {\n            System.out.println(\"Product: \" + currentProduct.getName() + \", Price: $\" + currentProduct.getPrice());\n            currentProduct = iterator.next();\n        }\n    }\n}\n"
  },
  {
    "path": "Observer Design Pattern/C++/order_status.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\nclass Order;\n\n// Observer interface\nclass Observer\n{\npublic:\n    virtual void update(Order *order) = 0;\n};\n\n// Concrete Observer: Customer\nclass Customer : public Observer\n{\nprivate:\n    string name;\n\npublic:\n    Customer(string name) : name(name) {}\n\n    void update(Order *order);\n};\n\n// Concrete Observer: Restaurant\nclass Restaurant : public Observer\n{\nprivate:\n    string restaurantName;\n\npublic:\n    Restaurant(string name) : restaurantName(name) {}\n\n    void update(Order *order);\n};\n\n// Concrete Observer: DeliveryDriver\nclass DeliveryDriver : public Observer\n{\nprivate:\n    string driverName;\n\npublic:\n    DeliveryDriver(string name) : driverName(name) {}\n\n    void update(Order *order);\n};\n\n// Concrete Observer: CallCenter\nclass CallCenter : public Observer\n{\npublic:\n    void update(Order *order);\n};\n\n// Subject: Order\nclass Order\n{\nprivate:\n    int id;\n    string status;\n    vector<Observer *> observers;\n\npublic:\n    Order(int id) : id(id), status(\"Order Placed\") {}\n\n    int getId()\n    {\n        return id;\n    }\n\n    string getStatus()\n    {\n        return status;\n    }\n\n    void setStatus(string newStatus)\n    {\n        status = newStatus;\n        notifyObservers();\n    }\n\n    void attach(Observer *observer)\n    {\n        observers.push_back(observer);\n    }\n\n    void detach(Observer *observer)\n    {\n        for (auto it = observers.begin(); it != observers.end(); ++it)\n        {\n            if (*it == observer)\n            {\n                observers.erase(it);\n                break; // Assuming each observer can be attached only once\n            }\n        }\n    }\n\n    void notifyObservers()\n    {\n        for (Observer *observer : observers)\n        {\n            observer->update(this);\n        }\n    }\n};\n\nvoid Customer::update(Order *order)\n{\n    cout << \"Hello, \" << name << \"! Order #\" << order->getId() << \" is now \" << order->getStatus() << endl;\n}\n\nvoid Restaurant::update(Order *order)\n{\n    cout << \"Restaurant \" << restaurantName << \": Order #\" << order->getId() << \" is now \" << order->getStatus() << endl;\n}\n\nvoid DeliveryDriver::update(Order *order)\n{\n    cout << \"Driver \" << driverName << \": Order #\" << order->getId() << \" is now \" << order->getStatus() << endl;\n}\nvoid CallCenter::update(Order *order)\n{\n    cout << \"Call center: Order #\" << order->getId() << \" is now \" << order->getStatus() << endl;\n}\n\nint main()\n{\n    // Create an order\n    Order order1(123);\n\n    // Create customers, restaurants, drivers, and a call center to track the order\n    Customer customer1(\"Customer 1\");\n    Restaurant restaurant1(\"Rest 1\");\n    DeliveryDriver driver1(\"Driver 1\");\n    CallCenter callCenter;\n\n    // Attach observers to the order\n    order1.attach(&customer1);\n    order1.attach(&restaurant1);\n    order1.attach(&driver1);\n    order1.attach(&callCenter);\n\n    // Simulate order status updates\n    order1.setStatus(\"Out for Delivery\");\n\n    // Detach an observer (if needed)\n    order1.detach(&callCenter);\n\n    // Simulate more order status updates\n    order1.setStatus(\"Delivered\");\n\n    return 0;\n}\n"
  },
  {
    "path": "Observer Design Pattern/JAVA/OrderStatus.java",
    "content": "import java.util.*;\n\ninterface Observer {\n    void update(Order order);\n}\n\nclass Customer implements Observer {\n    private String name;\n\n    public Customer(String name) {\n        this.name = name;\n    }\n\n    @Override\n    public void update(Order order) {\n        System.out.println(\"Hello, \" + name + \"! Order #\" + order.getId() + \" is now \" + order.getStatus() + \".\");\n    }\n}\n\nclass Restaurant implements Observer {\n    private String restaurantName;\n\n    public Restaurant(String name) {\n        this.restaurantName = name;\n    }\n\n    @Override\n    public void update(Order order) {\n        System.out.println(\"Restaurant \" + restaurantName + \": Order #\" + order.getId() + \" is now \" + order.getStatus() + \".\");\n    }\n}\n\nclass DeliveryDriver implements Observer {\n    private String driverName;\n\n    public DeliveryDriver(String name) {\n        this.driverName = name;\n    }\n\n    @Override\n    public void update(Order order) {\n        System.out.println(\"Driver \" + driverName + \": Order #\" + order.getId() + \" is now \" + order.getStatus() + \".\");\n    }\n}\n\nclass CallCenter implements Observer {\n    @Override\n    public void update(Order order) {\n        System.out.println(\"Call center: Order #\" + order.getId() + \" is now \" + order.getStatus() + \".\");\n    }\n}\n\nclass Order {\n    private int id;\n    private String status;\n    private List<Observer> observers = new ArrayList<>();\n\n    public Order(int id) {\n        this.id = id;\n        this.status = \"Order Placed\";\n    }\n\n    public int getId() {\n        return id;\n    }\n\n    public String getStatus() {\n        return status;\n    }\n\n    public void setStatus(String newStatus) {\n        status = newStatus;\n        notifyObservers();\n    }\n\n    public void attach(Observer observer) {\n        observers.add(observer);\n    }\n\n    public void detach(Observer observer) {\n        observers.remove(observer);\n    }\n\n    public void notifyObservers() {\n        for (Observer observer : observers) {\n            observer.update(this);\n        }\n    }\n}\n\npublic class OrderStatus {\n    public static void main(String[] args) {\n        // Create an order\n        Order order1 = new Order(123);\n\n        // Create customers, restaurants, drivers, and a call center to track the order\n        Customer customer1 = new Customer(\"Customer 1\");\n        Restaurant restaurant1 = new Restaurant(\"Rest 1\");\n        DeliveryDriver driver1 = new DeliveryDriver(\"Driver 1\");\n        CallCenter callCenter = new CallCenter();\n\n        // Attach observers to the order\n        order1.attach(customer1);\n        order1.attach(restaurant1);\n        order1.attach(driver1);\n        order1.attach(callCenter);\n\n        // Simulate order status updates\n        order1.setStatus(\"Out for Delivery\");\n\n        // Detach an observer (if needed)\n        order1.detach(callCenter);\n\n        // Simulate more order status updates\n        order1.setStatus(\"Delivered\");\n    }\n}\n"
  },
  {
    "path": "Prototype Design Pattern/C++/product.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// Abstract base class representing a prototype for products\nclass ProductPrototype {\npublic:\n    virtual ProductPrototype* clone() = 0;\n    virtual void display() = 0;\n    virtual ~ProductPrototype() {}\n};\n\n// Concrete prototype class representing a product\nclass Product : public ProductPrototype {\nprivate:\n    string name;\n    double price;\n\npublic:\n    Product(const string& name, double price)\n        : name(name), price(price) {}\n\n    ProductPrototype* clone() override {\n        return new Product(*this); // Copy constructor used for cloning\n    }\n\n    void display() override {\n        cout << \"Product: \" << name << endl;\n        cout << \"Price: $\" << price << endl;\n    }\n};\n\nint main() {\n    // Create prototype instances of products\n    ProductPrototype* product1 = new Product(\"Laptop\", 999.99);\n    ProductPrototype* product2 = new Product(\"Smartphone\", 499.99);\n\n    // Clone the prototypes to create new product instances\n    ProductPrototype* newProduct1 = product1->clone();\n    ProductPrototype* newProduct2 = product2->clone();\n\n    // Display product details\n    cout << \"Original Products:\\n\";\n    product1->display();\n    product2->display();\n\n    cout << \"\\nCloned Products:\\n\";\n    newProduct1->display();\n    newProduct2->display();\n\n    // Clean up\n    delete product1;\n    delete product2;\n    delete newProduct1;\n    delete newProduct2;\n\n    return 0;\n}\n"
  },
  {
    "path": "Prototype Design Pattern/C++/router.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\nclass NetworkDevice {\npublic:\n    virtual NetworkDevice* clone() const = 0;\n    virtual void display() const = 0;\n    virtual void update(string newName) = 0; // Update the device's name\n};\n\nclass Router : public NetworkDevice {\npublic:\n    Router(string name, string ip, string securityPolicy)\n        : name(move(name)), ip(move(ip)), securityPolicy(move(securityPolicy)) {}\n\n    NetworkDevice* clone() const override {\n        return new Router(*this);\n    }\n\n    void display() const override {\n        cout << \"Router - Name: \" << name << \", IP: \" << ip << \", Security Policy: \" << securityPolicy << endl;\n    }\n\n    void update(string newName) override {\n        name = move(newName);\n    }\n\nprivate:\n    string name;\n    string ip;\n    string securityPolicy;\n};\n\nclass Switch : public NetworkDevice {\npublic:\n    Switch(string name, string protocol)\n        : name(move(name)), protocol(move(protocol)) {}\n\n    NetworkDevice* clone() const override {\n        return new Switch(*this);\n    }\n\n    void display() const override {\n        cout << \"Switch - Name: \" << name << \", Protocol: \" << protocol << endl;\n    }\n\n    void update(string newName) override {\n        name = move(newName);\n    }\n\nprivate:\n    string name;\n    string protocol;\n};\n\nint main() {\n    // Create prototype instances of a router and a switch\n    NetworkDevice* routerPrototype = new Router(\"Router A\", \"192.168.1.1\", \"Firewall Enabled\");\n    NetworkDevice* switchPrototype = new Switch(\"Switch X\", \"Ethernet\");\n\n    // Clone and display router and switch devices\n    NetworkDevice* routerClone = routerPrototype->clone();\n    NetworkDevice* switchClone = switchPrototype->clone();\n\n    cout << \"Router Clone:\" << endl;\n    routerClone->display();\n\n    cout << \"\\nSwitch Clone:\" << endl;\n    switchClone->display();\n\n    // Update the names of the clones\n    routerClone->update(\"Router B\");\n    switchClone->update(\"Switch Y\");\n\n    cout << \"\\nUpdated Router Clone:\" << endl;\n    routerClone->display();\n\n    cout << \"\\nUpdated Switch Clone:\" << endl;\n    switchClone->display();\n\n    // Clean up\n    delete routerPrototype;\n    delete switchPrototype;\n    delete routerClone;\n    delete switchClone;\n\n    return 0;\n}"
  },
  {
    "path": "Prototype Design Pattern/JAVA/ProductDemo.java",
    "content": "// Abstract base class representing a prototype for products\nabstract class ProductPrototype {\n    public abstract ProductPrototype clone();\n    public abstract void display();\n}\n\n// Concrete prototype class representing a product\nclass Product extends ProductPrototype {\n    private String name;\n    private double price;\n\n    public Product(String name, double price) {\n        this.name = name;\n        this.price = price;\n    }\n\n    @Override\n    public ProductPrototype clone() {\n        return new Product(name, price);\n    }\n\n    @Override\n    public void display() {\n        System.out.println(\"Product: \" + name);\n        System.out.println(\"Price: $\" + price);\n    }\n}\n\npublic class ProductDemo {\n    public static void main(String[] args) {\n        // Create prototype instances of products\n        ProductPrototype product1 = new Product(\"Laptop\", 999.99);\n        ProductPrototype product2 = new Product(\"Smartphone\", 499.99);\n\n        // Clone the prototypes to create new product instances\n        ProductPrototype newProduct1 = product1.clone();\n        ProductPrototype newProduct2 = product2.clone();\n\n        System.out.println(\"Original Products:\");\n        product1.display();\n        product2.display();\n\n        System.out.println(\"\\nCloned Products:\");\n        newProduct1.display();\n        newProduct2.display();\n    }\n}\n"
  },
  {
    "path": "Prototype Design Pattern/JAVA/RouterDemo.java",
    "content": "abstract class NetworkDevice {\n    public abstract NetworkDevice clone();\n\n    public abstract void display();\n\n    public abstract void update(String newName);\n}\n\nclass Router extends NetworkDevice {\n    private String name;\n    private String ip;\n    private String securityPolicy;\n\n    public Router(String name, String ip, String securityPolicy) {\n        this.name = name;\n        this.ip = ip;\n        this.securityPolicy = securityPolicy;\n    }\n\n    @Override\n    public NetworkDevice clone() {\n        return new Router(name, ip, securityPolicy);\n    }\n\n    @Override\n    public void display() {\n        System.out.println(\"Router - Name: \" + name + \", IP: \" + ip + \", Security Policy: \" + securityPolicy);\n    }\n\n    @Override\n    public void update(String newName) {\n        name = newName;\n    }\n}\n\nclass Switch extends NetworkDevice {\n    private String name;\n    private String protocol;\n\n    public Switch(String name, String protocol) {\n        this.name = name;\n        this.protocol = protocol;\n    }\n\n    @Override\n    public NetworkDevice clone() {\n        return new Switch(name, protocol);\n    }\n\n    @Override\n    public void display() {\n        System.out.println(\"Switch - Name: \" + name + \", Protocol: \" + protocol);\n    }\n\n    @Override\n    public void update(String newName) {\n        name = newName;\n    }\n}\n\npublic class RouterDemo {\n    public static void main(String[] args) {\n        // Create prototype instances of a router and a switch\n        NetworkDevice routerPrototype = new Router(\"Router A\", \"192.168.1.1\", \"Firewall Enabled\");\n        NetworkDevice switchPrototype = new Switch(\"Switch X\", \"Ethernet\");\n\n        // Clone and display router and switch devices\n        NetworkDevice routerClone = routerPrototype.clone();\n        NetworkDevice switchClone = switchPrototype.clone();\n\n        System.out.println(\"Router Clone:\");\n        routerClone.display();\n\n        System.out.println(\"\\nSwitch Clone:\");\n        switchClone.display();\n\n        // Update the names of the clones\n        routerClone.update(\"Router B\");\n        switchClone.update(\"Switch Y\");\n\n        System.out.println(\"\\nUpdated Router Clone:\");\n        routerClone.display();\n\n        System.out.println(\"\\nUpdated Switch Clone:\");\n        switchClone.display();\n    }\n}"
  },
  {
    "path": "Proxy Design Pattern/C++/image.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// The Subject interface represents the Image.\nclass Image {\npublic:\n    virtual void display() = 0;\n};\n\n// The RealImage is the actual implementation of the Image.\nclass RealImage : public Image {\nprivate:\n    string filename;\n\npublic:\n    RealImage(const string& filename) : filename(filename) {\n        loadFromDisk();\n    }\n\n    void display() {\n        cout << \"Displaying image: \" << filename << endl;\n    }\n\n    void loadFromDisk() {\n        cout << \"Loading image from disk: \" << filename << endl;\n    }\n};\n\n// The ImageProxy is the proxy class that loads and displays high-resolution images on-demand.\nclass ImageProxy : public Image {\nprivate:\n    RealImage* realImage;\n    string filename;\n\npublic:\n    ImageProxy(const string& filename) : filename(filename), realImage(nullptr) {}\n\n    void display() {\n        if (!realImage) {\n            realImage = new RealImage(filename);\n        }\n        realImage->display();\n    }\n\n    ~ImageProxy() {\n        if (realImage) {\n            delete realImage;\n        }\n    }\n};\n\nint main() {\n    // Create an ImageProxy for a high-resolution image.\n    ImageProxy proxy(\"high_res_image.jpg\");\n\n    // Display the image (loading it on-demand).\n    proxy.display();\n\n    // The image is not loaded again if we display it multiple times.\n    proxy.display();\n\n    return 0;\n}\n"
  },
  {
    "path": "Proxy Design Pattern/JAVA/ImageDemo.java",
    "content": "interface Image {\n    void display();\n}\n\nclass RealImage implements Image {\n    private String filename;\n\n    public RealImage(String filename) {\n        this.filename = filename;\n        loadFromDisk();\n    }\n\n    @Override\n    public void display() {\n        System.out.println(\"Displaying image: \" + filename);\n    }\n\n    private void loadFromDisk() {\n        System.out.println(\"Loading image from disk: \" + filename);\n    }\n}\n\nclass ImageProxy implements Image {\n    private RealImage realImage;\n    private String filename;\n\n    public ImageProxy(String filename) {\n        this.filename = filename;\n        this.realImage = null;\n    }\n\n    @Override\n    public void display() {\n        if (realImage == null) {\n            realImage = new RealImage(filename);\n        }\n        realImage.display();\n    }\n}\n\npublic class ImageDemo {\n    public static void main(String[] args) {\n        // Create an ImageProxy for a high-resolution image.\n        Image proxy = new ImageProxy(\"high_res_image.jpg\");\n\n        // Display the image (loading it on-demand).\n        proxy.display();\n\n        // The image is not loaded again if we display it multiple times.\n        proxy.display();\n    }\n}\n"
  },
  {
    "path": "Simple Factory Design Pattern/C++/common.hpp",
    "content": "#pragma once\n\n#include <iostream>\n\nusing namespace std;\n\nenum class LogLevel {\n    DEBUG,\n    INFO,\n    ERROR\n};"
  },
  {
    "path": "Simple Factory Design Pattern/C++/debug_logger.cpp",
    "content": "#include \"debug_logger.hpp\"\n\nvoid DebugLogger::log(const string &msg)\n{\n    cout << \"DEBUG : \" << msg << endl;\n}"
  },
  {
    "path": "Simple Factory Design Pattern/C++/debug_logger.hpp",
    "content": "#pragma once\n#include \"ilogger.hpp\"\n\nclass DebugLogger : public ILogger {\n    public:\n        void log(const string& msg);\n};"
  },
  {
    "path": "Simple Factory Design Pattern/C++/error_logger.cpp",
    "content": "#include \"error_logger.hpp\"\n\nvoid ErrorLogger::log(const string& msg) {\n    cout<<\"ERROR : \"<<msg<<endl;\n}"
  },
  {
    "path": "Simple Factory Design Pattern/C++/error_logger.hpp",
    "content": "#pragma once\n#include \"ilogger.hpp\"\n\nclass ErrorLogger : public ILogger{\n    public:\n        void log(const string& msg);\n};"
  },
  {
    "path": "Simple Factory Design Pattern/C++/ilogger.hpp",
    "content": "#pragma once\n#include \"common.hpp\"\n\nclass ILogger {\n    public:\n        virtual void log(const string& msg) = 0;\n        virtual ~ILogger() {}\n};"
  },
  {
    "path": "Simple Factory Design Pattern/C++/info_logger.cpp",
    "content": "#include \"info_logger.hpp\"\n\nvoid InfoLogger::log(const string& msg) {\n    cout<<\"INFO : \"<<msg<<endl;\n}"
  },
  {
    "path": "Simple Factory Design Pattern/C++/info_logger.hpp",
    "content": "#pragma once\n#include \"ilogger.hpp\"\n\nclass InfoLogger : public ILogger {\n    public:\n        void log(const string& msg);\n};"
  },
  {
    "path": "Simple Factory Design Pattern/C++/logger_factory.cpp",
    "content": "#include \"logger_factory.hpp\"\n\nILogger* LoggerFactory::createLogger(LogLevel pLogLevel) {\n    if(pLogLevel == LogLevel::DEBUG)\n        return new DebugLogger();\n    if(pLogLevel == LogLevel::INFO)\n        return new InfoLogger();\n    if(pLogLevel == LogLevel::ERROR)\n        return new ErrorLogger();\n    return nullptr;\n}"
  },
  {
    "path": "Simple Factory Design Pattern/C++/logger_factory.hpp",
    "content": "#pragma once\n#include \"ilogger.hpp\"\n#include \"debug_logger.hpp\"\n#include \"info_logger.hpp\"\n#include \"error_logger.hpp\"\n\nclass LoggerFactory {\n    public:\n        static ILogger* createLogger(LogLevel pLogLevel);\n};"
  },
  {
    "path": "Simple Factory Design Pattern/C++/main.cpp",
    "content": "#include \"logger_factory.hpp\"\n\nint main() {\n    ILogger* debugLogger = LoggerFactory::createLogger(LogLevel::DEBUG);\n    ILogger* infoLogger = LoggerFactory::createLogger(LogLevel::INFO);\n    ILogger* errorLogger = LoggerFactory::createLogger(LogLevel::ERROR);\n\n    debugLogger->log(\"This is a debug log msg\");\n    infoLogger->log(\"This is an info log msg\");\n    errorLogger->log(\"This is an error log msg\");\n\n    delete debugLogger;\n    delete infoLogger;\n    delete errorLogger;\n\n    return 0;\n}"
  },
  {
    "path": "Simple Factory Design Pattern/JAVA/Main.java",
    "content": "import logger.*;\n\n\npublic class Main {\n    public static void main(String[] args) {\n        ILogger debugLogger = LoggerFactory.createLogger(LogLevel.DEBUG);\n        ILogger infoLogger = LoggerFactory.createLogger(LogLevel.INFO);\n        ILogger errorLogger = LoggerFactory.createLogger(LogLevel.ERROR);\n\n        debugLogger.log(\"This is a debug log msg\");\n        infoLogger.log(\"This is an info log msg\");\n        errorLogger.log(\"This is an error log msg\");\n    }\n}\n"
  },
  {
    "path": "Simple Factory Design Pattern/JAVA/logger/DebugLogger.java",
    "content": "package logger;\n\npublic class DebugLogger implements ILogger {\n    public void log(String msg) {\n        System.out.println(\"DEBUG: \" + msg);\n    }\n}\n"
  },
  {
    "path": "Simple Factory Design Pattern/JAVA/logger/ErrorLogger.java",
    "content": "package logger;\n\npublic class ErrorLogger implements ILogger {\n    public void log(String msg) {\n        System.out.println(\"ERROR: \" + msg);\n    }\n}\n"
  },
  {
    "path": "Simple Factory Design Pattern/JAVA/logger/ILogger.java",
    "content": "package logger;\n\npublic interface ILogger {\n    void log (String msg);\n}\n"
  },
  {
    "path": "Simple Factory Design Pattern/JAVA/logger/InfoLogger.java",
    "content": "package logger;\n\npublic class InfoLogger implements ILogger {\n    public void log(String msg) {\n        System.out.println(\"INFO: \" + msg);\n    }\n}\n"
  },
  {
    "path": "Simple Factory Design Pattern/JAVA/logger/LogLevel.java",
    "content": "package logger;\n\npublic enum LogLevel {\n    DEBUG, INFO, ERROR\n}\n\n"
  },
  {
    "path": "Simple Factory Design Pattern/JAVA/logger/LoggerFactory.java",
    "content": "package logger;\n\npublic class LoggerFactory {\n    public static ILogger createLogger(LogLevel logLevel) {\n        switch(logLevel) {\n            case DEBUG:\n                return new DebugLogger();\n            case INFO:\n                return new InfoLogger();\n            case ERROR:\n                return new ErrorLogger();\n            default:\n                return null;\n        }\n    }\n}\n"
  },
  {
    "path": "Singleton Design Pattern/C++/payment_gateway.cpp",
    "content": "#include <iostream>\n\nusing namespace std;\n\nclass PaymentGatewayManager\n{\n\nprivate:\n    PaymentGatewayManager()\n    {\n        cout << \"Payment Gateway Manager initialized.\" << endl;\n    }\n\n    static PaymentGatewayManager *instance;\n\n    static mutex mtx;\n\npublic:\n    static PaymentGatewayManager *getInstance()\n    {\n        if (instance == nullptr)\n        {\n            mtx.lock();\n            if (instance == nullptr)\n            {\n                instance = new PaymentGatewayManager();\n            }\n            mtx.unlock();\n        }\n        return instance;\n    }\n\n    void processPayment(double amount)\n    {\n        cout << \"Processing payment of $\" << amount << \" through the payment gateway.\" << endl;\n    }\n};\n\nPaymentGatewayManager *PaymentGatewayManager::instance = nullptr;\n\nmutex PaymentGatewayManager::mtx;\n\nint main()\n{\n\n    PaymentGatewayManager *paymentGateway = PaymentGatewayManager::getInstance();\n\n    paymentGateway->processPayment(100.0);\n\n    // Attempt to create another instance (should return the existing instance)\n    PaymentGatewayManager *anotherPaymentGateway = PaymentGatewayManager::getInstance();\n\n    // Check if both instances are the same.\n    if (paymentGateway == anotherPaymentGateway)\n    {\n        cout << \"Both instances are the same. Singleton pattern is working\" << endl;\n    }\n    else\n    {\n        cout << \"Singleton pattern is not working correctly\" << endl;\n    }\n    return 0;\n}"
  },
  {
    "path": "Singleton Design Pattern/JAVA/PaymentGateway.java",
    "content": "import java.util.concurrent.locks.Lock;\nimport java.util.concurrent.locks.ReentrantLock;\n\nclass PaymentGatewayManager {\n\n    private PaymentGatewayManager() {\n        System.out.println(\"Payment Gateway Manager initialized.\");\n    }\n\n    private static PaymentGatewayManager instance;\n\n    private static Lock mtx = new ReentrantLock();\n\n    public static PaymentGatewayManager getInstance() {\n        if (instance == null) { // First check without locking\n            mtx.lock(); // Acquire the lock before creating the instance\n            try {\n                if (instance == null) { // Double-checked locking\n                    instance = new PaymentGatewayManager();\n                }\n            } finally {\n                mtx.unlock(); // Always release the lock\n            }\n        }\n        return instance;\n    }\n\n    public void processPayment(double amount) {\n        System.out.println(\"Processing payment of $\" + amount + \" through the payment gateway.\");\n    }\n\n}\n\npublic class PaymentGateway {\n    public static void main(String[] args) {\n\n        PaymentGatewayManager paymentGateway = PaymentGatewayManager.getInstance();\n\n        paymentGateway.processPayment(100.0);\n\n        // Attempt to create another instance (should return the existing instance)\n        PaymentGatewayManager anotherPaymentGateway = PaymentGatewayManager.getInstance();\n\n        // Check if both instances are the same.\n        if (paymentGateway == anotherPaymentGateway) {\n            System.out.println(\"Both instances are the same. Singleton pattern is working.\");\n        } else {\n            System.out.println(\"Singleton pattern is not working correctly.\");\n        }\n    }\n}\n"
  },
  {
    "path": "State Design Pattern/C++/state.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// Define the RideState interface.\nclass RideState {\npublic:\n    virtual void handleRequest() = 0;\n    virtual void handleCancel() = 0;\n};\n\n// Implement concrete states.\n\nclass RideRequestedState : public RideState {\npublic:\n    void handleRequest() override {\n        cout << \"Ride has been requested.\" << endl;\n    }\n\n    void handleCancel() override {\n        cout << \"Ride request has been canceled.\" << endl;\n    }\n};\n\nclass DriverAssignedState : public RideState {\npublic:\n    void handleRequest() override {\n        cout << \"Ride is already assigned to a driver.\" << endl;\n    }\n\n    void handleCancel() override {\n        cout << \"Ride request has been canceled. The driver is notified.\" << endl;\n    }\n};\n\nclass EnRouteState : public RideState {\npublic:\n    void handleRequest() override {\n        cout << \"Ride is already en route.\" << endl;\n    }\n\n    void handleCancel() override {\n        cout << \"Ride request cannot be canceled while en route.\" << endl;\n    }\n};\n\n// Context\n\nclass Ride {\nprivate:\n    RideState* state;\n\npublic:\n    Ride() {\n        // Initial state is RideRequestedState.\n        state = new RideRequestedState();\n    }\n\n    void setState(RideState* newState) {\n        delete state;\n        state = newState;\n    }\n\n    void requestRide() {\n        state->handleRequest();\n    }\n\n    void cancelRide() {\n        state->handleCancel();\n    }\n};\n\nint main() {\n    Ride ride;\n    \n    ride.requestRide();  // Output: Ride has been requested.\n    \n    ride.cancelRide();   // Output: Ride request has been canceled.\n\n    cout<<\"--------------------------------------------------\"<<endl;\n    cout<<\"Setting state to Driver Assigned.\"<<endl;\n\n    ride.setState(new DriverAssignedState());\n    \n    ride.requestRide();  // Output: Ride is already assigned to a driver.\n    \n    ride.cancelRide();   // Output: Ride request has been canceled. The driver is notified.\n\n    cout<<\"--------------------------------------------------\"<<endl;\n    cout<<\"Setting state to EnRoute.\"<<endl;\n    ride.setState(new EnRouteState());\n    \n    ride.requestRide();  // Output: Ride is already en route.\n    \n    ride.cancelRide();   // Output: Ride request cannot be canceled while en route.\n\n    return 0;\n}\n"
  },
  {
    "path": "State Design Pattern/JAVA/StateDemo.java",
    "content": "// Define the RideState interface.\ninterface RideState {\n    void handleRequest();\n    void handleCancel();\n}\n\n// Implement concrete states.\n\nclass RideRequestedState implements RideState {\n    @Override\n    public void handleRequest() {\n        System.out.println(\"Ride has been requested.\");\n    }\n\n    @Override\n    public void handleCancel() {\n        System.out.println(\"Ride request has been canceled.\");\n    }\n}\n\nclass DriverAssignedState implements RideState {\n    @Override\n    public void handleRequest() {\n        System.out.println(\"Ride is already assigned to a driver.\");\n    }\n\n    @Override\n    public void handleCancel() {\n        System.out.println(\"Ride request has been canceled. The driver is notified.\");\n    }\n}\n\nclass EnRouteState implements RideState {\n    @Override\n    public void handleRequest() {\n        System.out.println(\"Ride is already en route.\");\n    }\n\n    @Override\n    public void handleCancel() {\n        System.out.println(\"Ride request cannot be canceled while en route.\");\n    }\n}\n\n// Context\n\nclass Ride {\n    private RideState state;\n\n    public Ride() {\n        // Initial state is RideRequestedState.\n        state = new RideRequestedState();\n    }\n\n    public void setState(RideState newState) {\n        state = newState;\n    }\n\n    public void requestRide() {\n        state.handleRequest();\n    }\n\n    public void cancelRide() {\n        state.handleCancel();\n    }\n}\n\npublic class StateDemo {\n    public static void main(String[] args) {\n        Ride ride = new Ride();\n    \n        ride.requestRide();  // Output: Ride has been requested.\n        ride.cancelRide();   // Output: Ride request has been canceled.\n\n        System.out.println(\"--------------------------------------------------\");\n        System.out.println(\"Setting state to Driver Assigned.\");\n\n        ride.setState(new DriverAssignedState());\n        ride.requestRide();  // Output: Ride is already assigned to a driver.\n        ride.cancelRide();   // Output: Ride request has been canceled. The driver is notified.\n\n        System.out.println(\"--------------------------------------------------\");\n        System.out.println(\"Setting state to EnRoute.\");\n        \n        ride.setState(new EnRouteState());\n        ride.requestRide();  // Output: Ride is already en route.\n        ride.cancelRide();   // Output: Ride request cannot be canceled while en route.\n    }\n}\n"
  },
  {
    "path": "Strategy Design Pattern/C++/payment.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\nclass PaymentStrategy {\npublic:\n    virtual void processPayment(double amount) = 0;\n    virtual ~PaymentStrategy() {}\n};\n\nclass CreditCardPayment : public PaymentStrategy {\npublic:\n    void processPayment(double amount) override {\n        cout << \"Processing credit card payment of $\" << amount << endl;\n    }\n};\n\nclass PayPalPayment : public PaymentStrategy {\npublic:\n    void processPayment(double amount) override {\n        cout << \"Processing PayPal payment of $\" << amount << endl;\n    }\n};\n\nclass CryptocurrencyPayment : public PaymentStrategy {\npublic:\n    void processPayment(double amount) override {\n        cout << \"Processing cryptocurrency payment of $\" << amount << endl;\n    }\n};\n\nclass PaymentProcessor {\nprivate:\n    PaymentStrategy* paymentStrategy;\n\npublic:\n    PaymentProcessor() : paymentStrategy(nullptr) {}\n\n    void setPaymentStrategy(PaymentStrategy* strategy) {\n        paymentStrategy = strategy;\n    }\n\n    void processPayment(double amount) {\n        if (paymentStrategy) {\n            paymentStrategy->processPayment(amount);\n        } else {\n            cerr << \"Payment strategy not set.\" << endl;\n        }\n    }\n\n    ~PaymentProcessor() {\n        if (paymentStrategy) {\n            delete paymentStrategy; // Clean up the strategy instance\n        }\n    }\n};\n\nint main() {\n    PaymentProcessor processor;\n\n    // Select and set the payment strategy at runtime\n    PaymentStrategy* strategy = new CreditCardPayment();\n    processor.setPaymentStrategy(strategy);\n\n    // Process the payment\n    processor.processPayment(100.0);\n\n    // Change the payment strategy\n    delete strategy; // Clean up the previous strategy\n    strategy = new PayPalPayment();\n    processor.setPaymentStrategy(strategy);\n\n    // Process another payment using the new strategy\n    processor.processPayment(50.0);\n\n    // Clean up\n    delete strategy;\n\n    return 0;\n}\n"
  },
  {
    "path": "Strategy Design Pattern/JAVA/PaymentDemo.java",
    "content": "// PaymentStrategy interface\ninterface PaymentStrategy {\n    void processPayment(double amount);\n}\n\n// Concrete PaymentStrategy classes\nclass CreditCardPayment implements PaymentStrategy {\n    public void processPayment(double amount) {\n        System.out.println(\"Processing credit card payment of $\" + amount);\n    }\n}\n\nclass PayPalPayment implements PaymentStrategy {\n    public void processPayment(double amount) {\n        System.out.println(\"Processing PayPal payment of $\" + amount);\n    }\n}\n\nclass CryptocurrencyPayment implements PaymentStrategy {\n    public void processPayment(double amount) {\n        System.out.println(\"Processing cryptocurrency payment of $\" + amount);\n    }\n}\n\n// PaymentProcessor\nclass PaymentProcessor {\n    private PaymentStrategy paymentStrategy;\n\n    public PaymentProcessor() {\n        paymentStrategy = null;\n    }\n\n    public void setPaymentStrategy(PaymentStrategy strategy) {\n        if (paymentStrategy != null) {\n            // Clean up the previous strategy\n            paymentStrategy = null;\n        }\n        paymentStrategy = strategy;\n    }\n\n    public void processPayment(double amount) {\n        if (paymentStrategy != null) {\n            paymentStrategy.processPayment(amount);\n        } else {\n            System.err.println(\"Payment strategy not set.\");\n        }\n    }\n\n    public void finalize() {\n        if (paymentStrategy != null) {\n            // Clean up the strategy instance\n            paymentStrategy = null;\n        }\n    }\n}\n\npublic class PaymentDemo {\n    public static void main(String[] args) {\n        PaymentProcessor processor = new PaymentProcessor();\n\n        // Select and set the payment strategy at runtime\n        PaymentStrategy strategy = new CreditCardPayment();\n        processor.setPaymentStrategy(strategy);\n\n        // Process the payment\n        processor.processPayment(100.0);\n\n        // Change the payment strategy\n        strategy = new PayPalPayment();\n        processor.setPaymentStrategy(strategy);\n\n        // Process another payment using the new strategy\n        processor.processPayment(50.0);\n    }\n}\n"
  },
  {
    "path": "Strategy and Factory Design Pattern/C++/payment.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// PaymentStrategy interface\nclass PaymentStrategy {\npublic:\n    virtual ~PaymentStrategy() {}\n    virtual void processPayment(double amount) = 0;\n};\n\n// Concrete PaymentStrategy classes\nclass CreditCardPayment : public PaymentStrategy {\npublic:\n    void processPayment(double amount) override {\n        cout << \"Processing credit card payment of $\" << amount << endl;\n    }\n};\n\nclass PayPalPayment : public PaymentStrategy {\npublic:\n    void processPayment(double amount) override {\n        cout << \"Processing PayPal payment of $\" << amount << endl;\n    }\n};\n\nclass CryptocurrencyPayment : public PaymentStrategy {\npublic:\n    void processPayment(double amount) override {\n        cout << \"Processing cryptocurrency payment of $\" << amount << endl;\n    }\n};\n\n// PaymentStrategyFactory\nclass PaymentStrategyFactory {\npublic:\n    static PaymentStrategy* createPaymentStrategy(const string& paymentMethod) {\n        if (paymentMethod == \"CreditCard\") {\n            return new CreditCardPayment();\n        } else if (paymentMethod == \"PayPal\") {\n            return new PayPalPayment();\n        } else if (paymentMethod == \"Cryptocurrency\") {\n            return new CryptocurrencyPayment();\n        } else {\n            //default\n            return new CreditCardPayment();\n        }\n    }\n};\n\n// PaymentProcessor\nclass PaymentProcessor {\nprivate:\n    PaymentStrategy* paymentStrategy;\n\npublic:\n    PaymentProcessor() : paymentStrategy(nullptr) {}\n\n    void setPaymentStrategy(const string& paymentMethod) {\n        if (paymentStrategy) {\n            delete paymentStrategy; // Clean up the previous strategy\n        }\n        paymentStrategy = PaymentStrategyFactory::createPaymentStrategy(paymentMethod);\n    }\n\n    void processPayment(double amount) {\n        if (paymentStrategy) {\n            paymentStrategy->processPayment(amount);\n        } else {\n            cerr << \"Payment strategy not set.\" << endl;\n        }\n    }\n\n    ~PaymentProcessor() {\n        if (paymentStrategy) {\n            delete paymentStrategy; // Clean up the strategy instance\n        }\n    }\n};\n\nint main() {\n    PaymentProcessor processor;\n\n    // Use the factory to create payment strategies\n    processor.setPaymentStrategy(\"CreditCard\");\n    processor.processPayment(100.0);\n\n    processor.setPaymentStrategy(\"PayPal\");\n    processor.processPayment(50.0);\n\n    return 0;\n}\n"
  },
  {
    "path": "Strategy and Factory Design Pattern/JAVA/PaymentDemo.java",
    "content": "// PaymentStrategy interface\ninterface PaymentStrategy {\n    void processPayment(double amount);\n}\n\n// Concrete PaymentStrategy classes\nclass CreditCardPayment implements PaymentStrategy {\n    public void processPayment(double amount) {\n        System.out.println(\"Processing credit card payment of $\" + amount);\n    }\n}\n\nclass PayPalPayment implements PaymentStrategy {\n    public void processPayment(double amount) {\n        System.out.println(\"Processing PayPal payment of $\" + amount);\n    }\n}\n\nclass CryptocurrencyPayment implements PaymentStrategy {\n    public void processPayment(double amount) {\n        System.out.println(\"Processing cryptocurrency payment of $\" + amount);\n    }\n}\n\n// PaymentStrategyFactory\nclass PaymentStrategyFactory {\n    public static PaymentStrategy createPaymentStrategy(String paymentMethod) {\n        if (paymentMethod.equals(\"CreditCard\")) {\n            return new CreditCardPayment();\n        } else if (paymentMethod.equals(\"PayPal\")) {\n            return new PayPalPayment();\n        } else if (paymentMethod.equals(\"Cryptocurrency\")) {\n            return new CryptocurrencyPayment();\n        } else {\n            // Default to CreditCardPayment\n            return new CreditCardPayment();\n        }\n    }\n}\n\n// PaymentProcessor\nclass PaymentProcessor {\n    private PaymentStrategy paymentStrategy;\n\n    public PaymentProcessor() {\n        paymentStrategy = null;\n    }\n\n    public void setPaymentStrategy(String paymentMethod) {\n        if (paymentStrategy != null) {\n            // Clean up the previous strategy\n            paymentStrategy = null;\n        }\n        paymentStrategy = PaymentStrategyFactory.createPaymentStrategy(paymentMethod);\n    }\n\n    public void processPayment(double amount) {\n        if (paymentStrategy != null) {\n            paymentStrategy.processPayment(amount);\n        } else {\n            System.err.println(\"Payment strategy not set.\");\n        }\n    }\n\n    public void finalize() {\n        if (paymentStrategy != null) {\n            // Clean up the strategy instance\n            paymentStrategy = null;\n        }\n    }\n}\n\npublic class PaymentDemo {\n    public static void main(String[] args) {\n        PaymentProcessor processor = new PaymentProcessor();\n\n        // Use the factory to create payment strategies\n        processor.setPaymentStrategy(\"CreditCard\");\n        processor.processPayment(100.0);\n\n        processor.setPaymentStrategy(\"PayPal\");\n        processor.processPayment(50.0);\n    }\n}\n"
  },
  {
    "path": "Template Design Pattern/C++/amazon_order.cpp",
    "content": "#include <iostream>\nusing namespace std;\n\n// Abstract class representing the template for order processing\nclass OrderProcessingTemplate {\npublic:\n    void processOrder() {\n        verifyOrder();\n        assignDeliveryAgent();\n        trackDelivery();\n    }\n\n    virtual void verifyOrder() = 0;\n    virtual void assignDeliveryAgent() = 0;\n    virtual void trackDelivery() = 0;\n};\n\n// Concrete subclass for processing orders from local restaurants\nclass LocalOrderProcessor : public OrderProcessingTemplate {\npublic:\n    void verifyOrder() {\n        cout << \"Verifying local order...\" << endl;\n        // Specific logic for verifying local orders\n    }\n\n    void assignDeliveryAgent() {\n        cout << \"Assigning a local delivery agent...\" << endl;\n        // Specific logic for assigning local delivery agents\n    }\n\n    void trackDelivery() {\n        cout << \"Tracking local delivery...\" << endl;\n        // Specific logic for tracking local deliveries\n    }\n};\n\n// Concrete subclass for processing orders from international restaurants\nclass InternationalOrderProcessor : public OrderProcessingTemplate {\npublic:\n    void verifyOrder() {\n        cout << \"Verifying international order...\" << endl;\n        // Specific logic for verifying international orders\n    }\n\n    void assignDeliveryAgent() {\n        cout << \"Assigning an international delivery agent...\" << endl;\n        // Specific logic for assigning international delivery agents\n    }\n\n    void trackDelivery() {\n        cout << \"Tracking international delivery...\" << endl;\n        // Specific logic for tracking international deliveries\n    }\n};\n\nint main() {\n    OrderProcessingTemplate* localOrder = new LocalOrderProcessor();\n    OrderProcessingTemplate* internationalOrder = new InternationalOrderProcessor();\n\n    cout << \"Processing a local order:\" << endl;\n    localOrder->processOrder();\n    cout << endl;\n\n    cout << \"Processing an international order:\" << endl;\n    internationalOrder->processOrder();\n\n    delete localOrder;\n    delete internationalOrder;\n\n    return 0;\n}\n"
  },
  {
    "path": "Template Design Pattern/JAVA/AmazonOrderProcessor.java",
    "content": "// Abstract class representing the template for order processing\nabstract class OrderProcessingTemplate {\n    public void processOrder() {\n        verifyOrder();\n        assignDeliveryAgent();\n        trackDelivery();\n    }\n\n    abstract void verifyOrder();\n    abstract void assignDeliveryAgent();\n    abstract void trackDelivery();\n}\n\n// Concrete subclass for processing orders from local restaurants\nclass LocalOrderProcessor extends OrderProcessingTemplate {\n    void verifyOrder() {\n        System.out.println(\"Verifying local order...\");\n        // Specific logic for verifying local orders\n    }\n\n    void assignDeliveryAgent() {\n        System.out.println(\"Assigning a local delivery agent...\");\n        // Specific logic for assigning local delivery agents\n    }\n\n    void trackDelivery() {\n        System.out.println(\"Tracking local delivery...\");\n        // Specific logic for tracking local deliveries\n    }\n}\n\n// Concrete subclass for processing orders from international restaurants\nclass InternationalOrderProcessor extends OrderProcessingTemplate {\n    void verifyOrder() {\n        System.out.println(\"Verifying international order...\");\n        // Specific logic for verifying international orders\n    }\n\n    void assignDeliveryAgent() {\n        System.out.println(\"Assigning an international delivery agent...\");\n        // Specific logic for assigning international delivery agents\n    }\n\n    void trackDelivery() {\n        System.out.println(\"Tracking international delivery...\");\n        // Specific logic for tracking international deliveries\n    }\n}\n\npublic class AmazonOrderProcessor {\n    public static void main(String[] args) {\n        OrderProcessingTemplate localOrder = new LocalOrderProcessor();\n        OrderProcessingTemplate internationalOrder = new InternationalOrderProcessor();\n\n        System.out.println(\"Processing a local order:\");\n        localOrder.processOrder();\n        System.out.println();\n\n        System.out.println(\"Processing an international order:\");\n        internationalOrder.processOrder();\n    }\n}\n"
  }
]