├── .gitattributes ├── .gitignore ├── 1_Creational Design Patterns ├── AbstractFactory │ ├── AbstractFactory.md │ ├── AbstractFactory1Demo │ │ ├── AbstractFactory1Demo.csproj │ │ ├── Client.cs │ │ ├── Explain.md │ │ ├── Program.cs │ │ ├── Step1-Abstract Products │ │ │ ├── ProductA.cs │ │ │ └── ProductB.cs │ │ ├── Step2-Concrete Products │ │ │ ├── ConcreteProductA1.cs │ │ │ ├── ConcreteProductA2.cs │ │ │ ├── ConcreteProductB1.cs │ │ │ └── ConcreteProductB2.cs │ │ ├── Step3-Abstract Factory │ │ │ └── AbstractFactory.cs │ │ └── Step4-Concrete Factories │ │ │ ├── ConcreteFactory1.cs │ │ │ └── ConcreteFactory2.cs │ ├── AbstractFactory2Demo │ │ ├── AbstractFactory2Demo.csproj │ │ ├── Explain.md │ │ ├── Program.cs │ │ ├── Step1-AbstractProducts │ │ │ ├── IChair.cs │ │ │ ├── ICoffeeTable.cs │ │ │ └── ISofa.cs │ │ ├── Step2-Concrete Products │ │ │ ├── ModernChair.cs │ │ │ ├── ModernCoffeeTable.cs │ │ │ ├── ModernSofa.cs │ │ │ ├── VictorianChair.cs │ │ │ ├── VictorianCoffeeTable.cs │ │ │ └── VictorianSofa.cs │ │ ├── Step3-Abstract Factories │ │ │ └── IFurnitureFactory.cs │ │ ├── Step4-Concrete Factories │ │ │ ├── ModernFurnitureFactory .cs │ │ │ └── VictorianFurnitureFactory .cs │ │ └── Step5-Client │ │ │ └── FurnitureStore.cs │ ├── AbstractFactory3Demo │ │ ├── AbstractFactory3Demo.csproj │ │ ├── Enums │ │ │ ├── Brands.cs │ │ │ ├── ComputerTypes.cs │ │ │ └── Processors.cs │ │ ├── Explain.md │ │ ├── Program.cs │ │ ├── Step1-Abstract Products │ │ │ ├── IBrand.cs │ │ │ ├── IComputerType.cs │ │ │ └── IProcessor.cs │ │ ├── Step2-Concrete Products │ │ │ ├── Brands │ │ │ │ ├── Apple.cs │ │ │ │ ├── Dell.cs │ │ │ │ └── MSI.cs │ │ │ ├── ComputerTypes │ │ │ │ ├── Desktop.cs │ │ │ │ └── Laptop.cs │ │ │ └── ProcessorTypes │ │ │ │ ├── ProcessorI3.cs │ │ │ │ ├── ProcessorI5.cs │ │ │ │ ├── ProcessorI7.cs │ │ │ │ └── ProcessorI9.cs │ │ ├── Step3-Abstract Factory │ │ │ └── IComputerFactory.cs │ │ ├── Step4-Concrete Factories │ │ │ ├── AppleDesktopFactory.cs │ │ │ ├── AppleLaptopFactory.cs │ │ │ ├── DellDesktopFactory.cs │ │ │ ├── DellLaptopFactory.cs │ │ │ └── EmployeeSystemFactory.cs │ │ └── Step5-Client │ │ │ └── EmployeeSystemManager.cs │ ├── AbstractFactory4Demo │ │ ├── AbstractFactory4Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Abstract Products │ │ │ ├── IDoor.cs │ │ │ └── IWindow.cs │ │ ├── Step2-Concrete Products │ │ │ ├── ModernDoor.cs │ │ │ ├── ModernWindow.cs │ │ │ ├── VictorianDoor.cs │ │ │ └── VictorianWindow.cs │ │ ├── Step3-Abstract Factories │ │ │ └── IHouseFactory.cs │ │ ├── Step4-Concrete Factories │ │ │ ├── ModernHouseFactory.cs │ │ │ └── VictorianHouseFactory.cs │ │ └── Step5-Client │ │ │ └── House.cs │ ├── AbstractFactory5Demo │ │ ├── AbstractFactory5Demo.csproj │ │ ├── Explain.md │ │ ├── Program.cs │ │ ├── Step1-Abstract Products │ │ │ ├── IButton .cs │ │ │ └── ITextBox.cs │ │ ├── Step2-Concrete Products │ │ │ ├── DarkButton.cs │ │ │ ├── DarkTextBox.cs │ │ │ ├── LightButton.cs │ │ │ └── LightTextBox.cs │ │ ├── Step3-Abstract Factories │ │ │ └── IThemeFactory.cs │ │ ├── Step4-Concrete Factories │ │ │ ├── DarkThemeFactory.cs │ │ │ └── LightThemeFactory.cs │ │ └── Step5-Client │ │ │ └── Application.cs │ └── AbstractFactory6Demo │ │ ├── AbstractFactory6Demo.csproj │ │ ├── Program.cs │ │ ├── Step2-ConcreteProduct │ │ ├── CitiLoanAccount.cs │ │ ├── CitiSavingAccount.cs │ │ ├── NationalLoanAccount.cs │ │ └── NationalSavingAccount.cs │ │ ├── Step3-Abstract Factories │ │ └── CreditUnionFactory.cs │ │ ├── Step4-Concrete Factories │ │ ├── CitiCreditUnionFactory.cs │ │ └── NationalCreditUnionFactory.cs │ │ ├── Step5-Client │ │ └── CreditUnionFactoryProvider.cs │ │ └── step1-AbstractProduct │ │ ├── ILoanAccount.cs │ │ └── ISavingAccount.cs ├── Builder │ ├── Builder.pdf │ ├── Builder1Demo │ │ ├── Builder1Demo.csproj │ │ ├── Program.cs │ │ ├── Step2-Builder interface │ │ │ └── IToyBuilder.cs │ │ ├── Step3-ConcreteBuilder │ │ │ ├── ToyABuilder.cs │ │ │ └── ToyBBuilder.cs │ │ ├── Step4-Director │ │ │ └── ToyCreator.cs │ │ └── step1-Product │ │ │ └── Toy.cs │ ├── Builder2Demo │ │ ├── Builder2Demo.csproj │ │ ├── Program.cs │ │ ├── Step2-Builder interface │ │ │ └── IVehicleBuilder.cs │ │ ├── Step3-ConcreteBuilder │ │ │ ├── FordBuilder.cs │ │ │ └── HondaBuilder.cs │ │ ├── step1-Product │ │ │ └── Vehical.cs │ │ └── step4-Director │ │ │ └── VehicleCreator.cs │ ├── Builder3Demo │ │ ├── Builder3Demo.csproj │ │ ├── Expalin.md │ │ ├── Program.cs │ │ ├── Step1-Product │ │ │ └── Product.cs │ │ ├── Step2-Builder Interface │ │ │ └── IBuilder.cs │ │ ├── Step3-ConcreteBuilder │ │ │ └── ConcreteBuilder.cs │ │ └── Step4-Director │ │ │ └── Director.cs │ ├── Builder4Demo │ │ ├── Application.cs │ │ ├── Builder4Demo.csproj │ │ ├── Expalin.md │ │ ├── Program.cs │ │ ├── Step1 - Production │ │ │ ├── Car.cs │ │ │ ├── CarType.cs │ │ │ ├── Engine .cs │ │ │ └── Manual.cs │ │ ├── Step2 - Builder Interface │ │ │ └── IBuilder.cs │ │ ├── Step3 - Concrete Builder │ │ │ ├── CarBuilder.cs │ │ │ └── CarManualBuilder.cs │ │ └── Step4 - Directors │ │ │ ├── CarDirector.cs │ │ │ └── CarManualDirector.cs │ ├── Builder5Demo │ │ ├── Builder5Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Production │ │ │ └── Vehicle.cs │ │ ├── Step2 - Builder Interface │ │ │ └── IVehicleBuilder.cs │ │ ├── Step3 - Concrete Builder │ │ │ ├── CarBuilder.cs │ │ │ ├── MotorcycleBuilder.cs │ │ │ └── ScooterBuilder.cs │ │ └── Step4 - Directors │ │ │ └── VehicleDirector.cs │ ├── Builder6Demo │ │ ├── Builder6Demo.csproj │ │ ├── Expalin.md │ │ ├── Program.cs │ │ ├── Step1-Production │ │ │ └── Computer.cs │ │ ├── Step2 - Builder Interface │ │ │ └── IComputerBuilder.cs │ │ ├── Step3 - Concrete Builder │ │ │ ├── DesktopBuilder.cs │ │ │ ├── LaptopBuilder.cs │ │ │ └── ServerBuilder.cs │ │ └── Step4 - Directors │ │ │ └── ComputerDirector.cs │ ├── Builder7Demo │ │ ├── Builder7Demo.csproj │ │ ├── InventoryReport.cs │ │ ├── Program.cs │ │ ├── Step1-Production │ │ │ └── FurnitureItem.cs │ │ ├── Step2 - Builder Interface │ │ │ └── IFurnitureInventoryBuilder.cs │ │ ├── Step3 - Concrete Builder │ │ │ └── DailyReportBuilder.cs │ │ └── Step4 - Directors │ │ │ └── InventoryBuildDirector.cs │ ├── Builder8Demo │ │ ├── Builder8Demo.csproj │ │ ├── Expalin.md │ │ ├── Helper │ │ │ ├── LinuxPlayerUtility.cs │ │ │ └── WindowsPlayerUtility.cs │ │ ├── Program.cs │ │ ├── Step1-Production │ │ │ ├── LinuxPlayButton.cs │ │ │ ├── LinuxStopButton.cs │ │ │ ├── PlayButton.cs │ │ │ ├── Player.cs │ │ │ ├── StopButton.cs │ │ │ ├── WindowsPlayButton.cs │ │ │ └── WindowsStopButton.cs │ │ ├── Step2 - Builder Interface │ │ │ └── IPlayerBuilder.cs │ │ ├── Step3 - Concrete Builder │ │ │ ├── LinuxPlayerBuilder.cs │ │ │ └── WindowsPlayerBuilder.cs │ │ └── Step4 - Directors │ │ │ └── PlayerDirector.cs │ ├── BuilderDescription.md │ └── document.docx ├── Creational.md ├── FactoryMethod │ ├── Factory1Demo │ │ ├── Factory1Demo.csproj │ │ ├── Program.cs │ │ ├── Step1_Product Interface │ │ │ └── IShape.cs │ │ ├── Step2_Product Concretes │ │ │ ├── Circle.cs │ │ │ ├── Rectangle.cs │ │ │ └── Square.cs │ │ ├── Step3_Creator │ │ │ └── CreatorShapeFactory.cs │ │ └── step4_Concrete Creator │ │ │ └── ShapeFactory.cs │ ├── Factory2Demo │ │ ├── Factory2Demo.csproj │ │ ├── Program.cs │ │ ├── Step1_Product Interface │ │ │ └── IVehicle.cs │ │ ├── Step2_Product Concretes │ │ │ ├── Bike.cs │ │ │ └── Scooter.cs │ │ ├── Step3_Creator │ │ │ └── CreatorVehicleFactory.cs │ │ ├── VehicleType.cs │ │ └── step4_Concrete Creator │ │ │ └── ConcreteVehicleFactory.cs │ ├── Factory3Demo │ │ ├── Factory3Demo.csproj │ │ ├── Program.cs │ │ ├── Step1_Product Interface │ │ │ └── Player.cs │ │ ├── Step2_Product Concretes │ │ │ ├── LinuxPlayer.cs │ │ │ └── WindowsPlayer.cs │ │ ├── Step3_Creator │ │ │ └── PlayerCreator.cs │ │ └── step4_Concrete Creator │ │ │ ├── LinuxPlayerCreator.cs │ │ │ └── WindowsPlayerCreator.cs │ ├── Factory4Demo │ │ ├── Factory4Demo.csproj │ │ ├── Program.cs │ │ ├── Step1_Product Interface │ │ │ └── ITransport.cs │ │ ├── Step2_Product Concretes │ │ │ ├── Air.cs │ │ │ ├── Ship.cs │ │ │ └── Truck.cs │ │ ├── Step3_Creator │ │ │ └── LogisticProviderFactory.cs │ │ └── step4_Concrete Creator │ │ │ ├── AirLogisticProviderFactory.cs │ │ │ ├── RoadLogisticProviderFactory.cs │ │ │ └── SeaLogisticProviderFactory.cs │ ├── Factory5Demo │ │ ├── Factory5Demo.csproj │ │ ├── Program.cs │ │ ├── Step1_Product Interface │ │ │ └── SavingsAccount.cs │ │ ├── Step2_Product Concretes │ │ │ ├── CitiSavingsAcct.cs │ │ │ └── NationalSavingAcct.cs │ │ ├── Step3_Creator │ │ │ └── ICreditUnionFactory.cs │ │ └── step4_Concrete Creator │ │ │ └── SavingsAcctFactory.cs │ ├── Factory6Demo │ │ ├── DescriptionFactory6Demo.md │ │ ├── Factory6Demo - Backup.csproj │ │ ├── Factory6Demo.csproj │ │ ├── Forex.cs │ │ ├── Models │ │ │ ├── Exchange.cs │ │ │ ├── Risk.cs │ │ │ └── RiskModel.cs │ │ ├── Program.cs │ │ ├── Step1_Product Interface │ │ │ └── IProcessor.cs │ │ ├── Step2_Product Concretes │ │ │ ├── BitcoinProcessor.cs │ │ │ └── EthereumProcessor.cs │ │ ├── Step3_Creator │ │ │ └── ProcessFactory.cs │ │ └── step4_Concrete Creator │ │ │ └── CryptoCurrencyFactory.cs │ └── FactoryMethodDescripton.md ├── Prototype │ ├── Prototype.docx │ ├── Prototype.pdf │ ├── Prototype1Demo │ │ ├── Prototype1Demo.sln │ │ └── Prototype1Demo │ │ │ ├── Program.cs │ │ │ ├── Prototype1Demo.csproj │ │ │ ├── Step1-Prototype interface │ │ │ └── SandwichPrototype.cs │ │ │ ├── Step2-ConcretePrototypes │ │ │ └── Sandwich.cs │ │ │ └── Step3-Prototype Registry (Client) │ │ │ └── SandwichMenu.cs │ ├── Prototype2Demo │ │ ├── Program.cs │ │ ├── Prototype2Demo.csproj │ │ ├── Step1-Prototype interface │ │ │ └── Cookie.cs │ │ ├── Step2-ConcretePrototypes │ │ │ ├── CircleCookie.cs │ │ │ └── SquareCookie.cs │ │ └── Step3-Prototype Registry (Client) │ │ │ └── Bakery.cs │ ├── Prototype3Demo │ │ ├── Program.cs │ │ ├── Prototype3Demo.csproj │ │ ├── Step1-Prototype interface │ │ │ └── Cookie.cs │ │ ├── Step2-ConcretePrototypes │ │ │ └── Button.cs │ │ └── Step3-Prototype Registry (Client) │ │ │ └── PrototypeRegistry.cs │ ├── Prototype4Demo │ │ ├── Explaination.md │ │ ├── Program.cs │ │ ├── Prototype4Demo.csproj │ │ ├── Step1-Prototype interface │ │ │ └── Cookie.cs │ │ ├── Step2-ConcretePrototypes │ │ │ └── Product.cs │ │ └── Step3-Prototype Registry (Client) │ │ │ └── ECommerceApplication.cs │ ├── Prototype5Demo │ │ ├── Explaination.md │ │ ├── Program.cs │ │ ├── Prototype5Demo.csproj │ │ ├── Step1-Prototype interface │ │ │ └── ICampaign.cs │ │ ├── Step2-ConcretePrototypes │ │ │ ├── TextCampaign.cs │ │ │ └── VideoCampaign.cs │ │ └── Step3-Prototype Registry (Client) │ │ │ └── CampaignManager.cs │ ├── Prototype6Demo │ │ ├── Program.cs │ │ ├── Prototype6Demo.csproj │ │ ├── Step1-Prototype interface │ │ │ └── ICustomCloneable.cs │ │ └── Step2-ConcretePrototypes │ │ │ └── CloneableObject.cs │ └── PrototypeDescription.md └── Singleton │ ├── LazySingletonDescription.md │ ├── Singleton1Demo │ ├── Program.cs │ ├── Singleton.cs │ └── Singleton1Demo.csproj │ ├── Singleton2Demo │ ├── Program.cs │ ├── Singleton.cs │ └── Singleton2Demo.csproj │ ├── Singleton3Demo │ ├── Program.cs │ └── Singleton3Demo.csproj │ ├── Singleton4Demo │ ├── AppConfigurations.cs │ ├── Program.cs │ └── Singleton4Demo.csproj │ ├── Singleton5Demo │ ├── Logger.cs │ ├── Program.cs │ ├── Singleton5Demo.csproj │ └── SomeBusinessLogic.cs │ ├── Singleton6Demo │ ├── Explaination.md │ ├── PaymentService.cs │ ├── Program.cs │ ├── ServiceConfigurationManager.cs │ └── Singleton6Demo.csproj │ ├── Singleton7Demo │ ├── LazySingleton.cs │ ├── Program.cs │ └── Singleton7Demo.csproj │ ├── Singleton8Demo │ ├── Explaination.md │ ├── LazySingleton.cs │ ├── Program.cs │ └── Singleton8Demo.csproj │ ├── Singleton9Demo │ ├── Board.cs │ ├── LockBoard.cs │ ├── Program.cs │ └── Singleton9Demo.csproj │ └── SingletonDescription.md ├── 2_Structural Design Patterns ├── Adapter │ ├── Adapter.md │ ├── Adapter10Demo │ │ ├── Adapter10Demo.csproj │ │ ├── Plugins │ │ │ └── Earth.cs │ │ ├── Program.cs │ │ ├── Spreadsheet.cs │ │ ├── Step3- Adaptee │ │ │ ├── Dashboard.cs │ │ │ └── EarthAdapter.cs │ │ ├── step1- Client Interface │ │ │ └── IGraphic.cs │ │ └── step2-Adapter Class │ │ │ ├── BarChartRace.cs │ │ │ └── PlottingCompetitors.cs │ ├── Adapter1Demo │ │ ├── Adapter1Demo.csproj │ │ ├── Program.cs │ │ ├── Step3- Adaptee │ │ │ └── Adaptee.cs │ │ ├── step1- Client Interface │ │ │ └── Target.cs │ │ └── step2-Adapter Class │ │ │ └── Adapter.cs │ ├── Adapter2Demo │ │ ├── Adapter2Demo.csproj │ │ ├── Program.cs │ │ ├── Step3- Adaptee │ │ │ └── Adaptee.cs │ │ ├── step1- Client Interface │ │ │ └── ITarget.cs │ │ └── step2-Adapter Class │ │ │ └── Adapter.cs │ ├── Adapter3Demo │ │ ├── Adapter3Demo.csproj │ │ ├── Program.cs │ │ ├── Step3- Adaptee │ │ │ └── ChemicalDatabank.cs │ │ ├── step1- Client Interface │ │ │ └── Compound.cs │ │ └── step2-Adapter Class │ │ │ └── RichCompound.cs │ ├── Adapter4Demo │ │ ├── Adapter4Demo.csproj │ │ ├── Expalin.md │ │ ├── Manufacturer.cs │ │ ├── ManufacturerDataProvider.cs │ │ ├── Program.cs │ │ ├── Step1 - Interface │ │ │ └── IXmlToJson.cs │ │ ├── Step3-Client - Adaptee │ │ │ └── XmlConverter.cs │ │ └── step2-Adapter Class │ │ │ ├── JsonConverter.cs │ │ │ └── XmlToJsonAdapter.cs │ ├── Adapter5Demo │ │ ├── Adapter5Demo.csproj │ │ ├── Program.cs │ │ ├── Step1 - Interface │ │ │ └── ITarget.cs │ │ ├── Step3-Client - Adaptee │ │ │ └── HRSystem.cs │ │ ├── ThirdPartyBillingSystem.cs │ │ └── step2-Adapter Class │ │ │ └── EmployeeAdapter.cs │ ├── Adapter6Demo │ │ ├── Adapter6Demo.csproj │ │ └── Program.cs │ ├── Adapter7Demo │ │ ├── Adapter7Demo.csproj │ │ ├── Client.cs │ │ ├── Program.cs │ │ ├── Step1 - Interface │ │ │ └── IAdapter.cs │ │ ├── Step3-Client - Adaptee │ │ │ └── Adaptee.cs │ │ └── step2-Adapter Class │ │ │ └── SpecificAdapter.cs │ ├── Adapter8Demo │ │ ├── Adapter8Demo.csproj │ │ ├── Client.cs │ │ ├── Program.cs │ │ ├── Step1 - Interface │ │ │ └── ITarget.cs │ │ ├── Step3-Client - Adaptee │ │ │ └── Adaptee.cs │ │ └── step2-Adapter Class │ │ │ └── Adapter .cs │ └── Adapter9Demo │ │ ├── Adapter9Demo.csproj │ │ ├── AmericanAppliance.cs │ │ ├── Expalin.md │ │ ├── Program.cs │ │ ├── Step1 - Interface │ │ └── IAmericanSocket.cs │ │ ├── Step3-Client - Adaptee │ │ └── EuropeanPlug.cs │ │ └── step2-Adapter Class │ │ └── PlugAdapter.cs ├── Bridge │ ├── Bridge.md │ ├── Bridge1Demo │ │ ├── 1_Define Implementor Interface │ │ │ └── IDraw.cs │ │ ├── 2_Create Concrete Implementations │ │ │ ├── GreenCircle.cs │ │ │ └── RedCircle.cs │ │ ├── 3_Define Abstraction │ │ │ └── Shape.cs │ │ ├── 4_Create Refined Abstraction │ │ │ └── Circle.cs │ │ ├── Bridge1Demo.csproj │ │ ├── Program.cs │ │ └── explain.md │ ├── Bridge2Demo │ │ ├── 1_Define Implementor Interface │ │ │ └── IWorkshop.cs │ │ ├── 2_Create Concrete Implementations │ │ │ ├── Assemble.cs │ │ │ └── Produce.cs │ │ ├── 3_Define Abstraction │ │ │ └── Vehicle.cs │ │ ├── 4_Create Refined Abstraction │ │ │ ├── Bike.cs │ │ │ └── Car.cs │ │ ├── Bridge2Demo.csproj │ │ └── Program.cs │ ├── Bridge3Demo │ │ ├── 1_Define Implementor Interface │ │ │ └── IColor.cs │ │ ├── 2_Create Concrete Implementations │ │ │ ├── GreenColor.cs │ │ │ └── RedColor.cs │ │ ├── 3_Define Abstraction │ │ │ └── Shape.cs │ │ ├── 4_Create Refined Abstraction │ │ │ ├── Circle.cs │ │ │ ├── Rectangle.cs │ │ │ └── Sequre.cs │ │ ├── Bridge3Demo.csproj │ │ ├── Program.cs │ │ └── explain.md │ ├── Bridge4Demo │ │ ├── 1_Define Implementor Interface │ │ │ └── IAreaCalculator.cs │ │ ├── 2_Create Concrete Implementations │ │ │ ├── CircleAreaCalculator.cs │ │ │ ├── RectangleAreaCalculator.cs │ │ │ └── SquareAreaCalculator.cs │ │ ├── 3_Define Abstraction │ │ │ └── IShape.cs │ │ ├── 4_Create Refined Abstraction │ │ │ ├── Circle.cs │ │ │ ├── Rectangle.cs │ │ │ └── Square.cs │ │ ├── Bridge4Demo.csproj │ │ └── Program.cs │ ├── Bridge5Demo │ │ ├── Bridge5Demo.csproj │ │ ├── Program.cs │ │ └── Services │ │ │ ├── 1_Define Implementor Interface │ │ │ └── ISpeechProvider.cs │ │ │ ├── 2_Create Concrete Implementations │ │ │ ├── AzureProvider.cs │ │ │ └── GoogleProvider.cs │ │ │ ├── 3_Define Abstraction │ │ │ └── PremiumSpeechService.cs │ │ │ └── Refined Abstraction │ │ │ └── SpeechService.cs │ ├── Bridge6Demo │ │ ├── 1_Define Implementor Interface │ │ │ └── IDataService.cs │ │ ├── 3_Define Abstraction │ │ │ └── BridgeInterface.cs │ │ ├── Bridge6Demo.csproj │ │ ├── Program.cs │ │ └── Refined Abstraction │ │ │ └── DataService.cs │ └── Bridge7Demo │ │ ├── 1_Define Implementor Interface │ │ └── IDevice.cs │ │ ├── 2_Create Concrete Implementations │ │ ├── Radio.cs │ │ └── Tv.cs │ │ ├── 3_Define Abstraction │ │ └── RemoteControl.cs │ │ ├── 4_Create Refined Abstraction │ │ ├── AdvancedRemote.cs │ │ └── BasicRemote.cs │ │ ├── Bridge7Demo.csproj │ │ ├── Explain.md │ │ └── Program.cs ├── Composite │ ├── Composite.md │ ├── Composite1Demo │ │ ├── Composite1Demo.csproj │ │ ├── Program.cs │ │ ├── Step1- Component Interface │ │ │ └── Component.cs │ │ ├── Step2 - Composite Class │ │ │ └── Leaf.cs │ │ └── Step3 - Composite Class │ │ │ └── Composite.cs │ ├── Composite2Demo │ │ ├── 1-Component │ │ │ └── DrawingElement.cs │ │ ├── 2-Leaf │ │ │ └── PrimitiveElement.cs │ │ ├── Composite │ │ │ └── CompositeElement.cs │ │ ├── Composite2Demo.csproj │ │ └── Program.cs │ ├── Composite3Demo │ │ ├── 1. Component │ │ │ └── Employee.cs │ │ ├── 2.Leaf │ │ │ └── TeamMember.cs │ │ ├── 3.Composite │ │ │ └── TeamLead.cs │ │ ├── Composite3Demo.csproj │ │ └── Program.cs │ ├── Composite4Demo │ │ ├── 1. Component │ │ │ └── FileSystemItem.cs │ │ ├── 2. Leaf │ │ │ └── File.cs │ │ ├── 3.Composite │ │ │ └── Directory.cs │ │ ├── Composite4Demo.csproj │ │ └── Program.cs │ └── Composite5Demo │ │ ├── 1. Component │ │ └── IComponent.cs │ │ ├── 2. Leaf │ │ └── File.cs │ │ ├── 3.Composite │ │ └── Folder.cs │ │ ├── Composite5Demo.csproj │ │ └── Program.cs ├── Decorator │ ├── Decorate2Demo │ │ ├── 1_Component Interface │ │ │ └── ICar.cs │ │ ├── 2_Create a Concrete Component │ │ │ ├── DeluxCar.cs │ │ │ ├── EconomyCar.cs │ │ │ └── LuxuryCar.cs │ │ ├── 3_ Create an Abstract Decorator │ │ │ └── CarAccessoriesDecorator.cs │ │ ├── 4_Create Concrete Decorator │ │ │ ├── AdvancedAccessories.cs │ │ │ ├── BasicAccessories.cs │ │ │ └── SportAccessories.cs │ │ ├── Decorator2Demo.csproj │ │ └── Program.cs │ ├── Decorator1Demo │ │ ├── 1_Component Interface │ │ │ └── IComponent.cs │ │ ├── 2_Create a Concrete Component │ │ │ └── ConcreteComponent.cs │ │ ├── 3_ Create an Abstract Decorator │ │ │ └── Decorate.cs │ │ ├── 4_Create Concrete Decorator │ │ │ ├── ConcreteDecoratorA.cs │ │ │ └── ConcreteDecoratorB.cs │ │ ├── Decorator1Demo.csproj │ │ └── Program.cs │ ├── Decorator3Demo │ │ ├── 1_Component Interface │ │ │ └── LibraryItem.cs │ │ ├── 2_Create a Concrete Component │ │ │ ├── Book.cs │ │ │ └── Video.cs │ │ ├── 3_ Create an Abstract Decorator │ │ │ └── LibraryDecorator.cs │ │ ├── 4_Create Concrete Decorator │ │ │ └── Borrowable.cs │ │ ├── Decorator3Demo.csproj │ │ └── Program.cs │ ├── Decorator4Demo │ │ ├── 1_Component Interface │ │ │ └── ITextProcessor.cs │ │ ├── 2_Create a Concrete Component │ │ │ ├── JsonTextProcessor.cs │ │ │ └── PlainTextProcessor.cs │ │ ├── 3_ Create an Abstract Decorator │ │ │ └── TextProcessorDecorator.cs │ │ ├── 4_Create Concrete Decorator │ │ │ ├── CompressionDecorator.cs │ │ │ ├── EncryptionDecorator.cs │ │ │ └── HtmlEncodeDecorator.cs │ │ ├── Decorator4Demo.csproj │ │ ├── Program.cs │ │ └── explain.md │ ├── Decorator5Demo │ │ ├── 1_Component Interface │ │ │ └── INotifier.cs │ │ ├── 2_Create a Concrete Component │ │ │ ├── EmailAndSmsNotifiers.cs │ │ │ ├── EmailNotifier.cs │ │ │ └── SmsNotifier.cs │ │ ├── 3_ Create an Abstract Decorator │ │ │ └── NotifierDecorator.cs │ │ ├── 4_Create Concrete Decorator │ │ │ ├── Service1NotifierDecorator.cs │ │ │ └── Service2NotifierDecorator.cs │ │ ├── Decorator5Demo.csproj │ │ └── Program.cs │ ├── Decorator6Demo │ │ ├── 1_Component Interface │ │ │ └── ICoffee.cs │ │ ├── 2_Create a Concrete Component │ │ │ └── Coffee.cs │ │ ├── 3_ Create an Abstract Decorator │ │ │ └── CoffeeDecorator.cs │ │ ├── 4_Create Concrete Decorator │ │ │ ├── WithMilk.cs │ │ │ └── WithSugar.cs │ │ ├── Decorator6Demo.csproj │ │ └── Program.cs │ ├── Decorator7Demo │ │ ├── 1_Component Interface │ │ │ └── Car.cs │ │ ├── 2_Create a Concrete Component │ │ │ ├── CompactCar.cs │ │ │ └── FullSizeCar.cs │ │ ├── 3_ Create an Abstract Decorator │ │ │ └── CarDecorator.cs │ │ ├── 4_Create Concrete Decorator │ │ │ ├── LeatherSeats.cs │ │ │ ├── Navigation.cs │ │ │ └── Sunroof.cs │ │ ├── Decorator7Demo.csproj │ │ └── Program.cs │ └── DecoratorExplain.md ├── Facade │ ├── Facade1Demo │ │ ├── Facade.cs │ │ ├── Facade1Demo.csproj │ │ ├── Program.cs │ │ └── Subsystem Classes │ │ │ ├── SubSystemOne.cs │ │ │ ├── SubSystemThree.cs │ │ │ └── SubSystemTwo.cs │ ├── Facade2Demo │ │ ├── Facade2Demo.csproj │ │ ├── ProcessValidity.cs │ │ ├── Program.cs │ │ └── Subsystem Classes │ │ │ ├── Bank.cs │ │ │ ├── Credit.cs │ │ │ ├── Customer.cs │ │ │ └── Loan.cs │ ├── Facade3Demo │ │ ├── Facade3Demo.csproj │ │ ├── HomeAutomation.cs │ │ ├── Program.cs │ │ └── Subsystem Classes │ │ │ ├── HeatingControl.cs │ │ │ ├── LightingControl.cs │ │ │ └── SecurityControl.cs │ ├── Facade4Demo │ │ ├── Entities │ │ │ ├── City.cs │ │ │ ├── State.cs │ │ │ └── WeatherFacadeResults.cs │ │ ├── Facade4Demo.csproj │ │ ├── IWeatherFacade.cs │ │ ├── Program.cs │ │ ├── Services │ │ │ ├── ConverterService.cs │ │ │ ├── GeoLookupService.cs │ │ │ └── WeatherService.cs │ │ └── WeatherFacade.cs │ ├── Facade5Demo │ │ ├── Facade5Demo - Backup.csproj │ │ ├── Facade5Demo.csproj │ │ ├── IServiceFacade.cs │ │ ├── Program.cs │ │ ├── ServiceFacade.cs │ │ └── Subsystem Classes │ │ │ ├── ServiceA.cs │ │ │ ├── ServiceB.cs │ │ │ └── ServiceC.cs │ ├── Facade6Demo │ │ ├── ComputerFacade.cs │ │ ├── Facade6Demo.csproj │ │ ├── IComputerFacade.cs │ │ ├── Program.cs │ │ ├── Subsystem Classes │ │ │ ├── CPU.cs │ │ │ ├── HardDrive.cs │ │ │ └── Memory.cs │ │ └── explain.md │ ├── Facade7Demo │ │ ├── CollegeLoan.cs │ │ ├── Facade7Demo.csproj │ │ ├── Program.cs │ │ ├── Student.cs │ │ └── Subsystem Classes │ │ │ ├── Bank.cs │ │ │ ├── Credit.cs │ │ │ └── Loan.cs │ ├── Facade8Demo │ │ ├── Account.cs │ │ ├── AccountCategory.cs │ │ ├── Facade8Demo.csproj │ │ ├── Product.cs │ │ ├── ProductsFacade.cs │ │ ├── Program.cs │ │ └── Subsystem Classes │ │ │ ├── AccountCategoryService.cs │ │ │ ├── AccountDataService.cs │ │ │ └── ProductsDataService.cs │ └── facade.md ├── Flyweight │ ├── FlyWeight.md │ ├── Flyweight1Demo │ │ ├── 1_Flyweight Interface │ │ │ └── Flyweight.cs │ │ ├── 2_ Concrete Flyweight │ │ │ ├── ConcreteFlyweight.cs │ │ │ └── UnsharedFlyweight.cs │ │ ├── 3_Flyweight Factory │ │ │ └── FlyweightFactory.cs │ │ ├── Flyweight1Demo.csproj │ │ └── Program.cs │ ├── Flyweight2Demo │ │ ├── 1_Flyweight Interface │ │ │ └── IShape.cs │ │ ├── 2_ Concrete Flyweight │ │ │ ├── Circle.cs │ │ │ └── Rectangle.cs │ │ ├── 3_Flyweight Factory │ │ │ └── ShapeObjectFactory.cs │ │ ├── Flyweight2Demo.csproj │ │ └── Program.cs │ ├── Flyweight3Demo │ │ ├── 1_Flyweight Interface │ │ │ └── Character.cs │ │ ├── 2_ Concrete Flyweight │ │ │ ├── CharacterA.cs │ │ │ ├── CharacterB.cs │ │ │ └── CharacterZ.cs │ │ ├── 3_Flyweight Factory │ │ │ └── CharacterFactory.cs │ │ ├── Flyweight3Demo.csproj │ │ └── Program.cs │ ├── Flyweight4Demo │ │ ├── 1_Flyweight Abastract_Interface │ │ │ └── Flyweight.cs │ │ ├── 2_ Concrete Flyweight │ │ │ └── ParticleType .cs │ │ ├── 3_Flyweight Factory │ │ │ └── ParticleFactory .cs │ │ ├── 4.UnsharedConcreteFlyweight-Optional │ │ │ └── unshared.md │ │ ├── 5.Context │ │ │ └── Particle .cs │ │ ├── 6.Client │ │ │ └── Game.cs │ │ ├── Flyweight4Demo - Backup.csproj │ │ ├── Flyweight4Demo.csproj │ │ └── Program.cs │ ├── Flyweight5Demo │ │ ├── 1.ConcreteFlyweight │ │ │ └── ProductDescription.cs │ │ ├── 2.FlyweightFactory │ │ │ └── ProductFactory.cs │ │ ├── 3.Context │ │ │ └── Product.cs │ │ ├── 4.Client │ │ │ └── InventoryManagement.cs │ │ ├── Flyweight5Demo.csproj │ │ └── Program.cs │ └── FlyweightFactory.txt ├── Proxy │ ├── Proxy.md │ ├── Proxy1Demo │ │ ├── 1. Subject Interface │ │ │ └── ISubject.cs │ │ ├── 2.RealSubject │ │ │ └── RealSubject.cs │ │ ├── 3.Proxy │ │ │ └── Proxy.cs │ │ ├── 4.Client │ │ │ └── Client.cs │ │ ├── Program.cs │ │ ├── Proxy1Demo.csproj │ │ └── explain.md │ ├── Proxy2Demo │ │ ├── 1. Subject Interface │ │ │ └── IPrice.cs │ │ ├── 2.RealSubject │ │ │ └── GoldPrice.cs │ │ ├── 3.Proxy │ │ │ └── ProxyApi.cs │ │ ├── Program.cs │ │ └── Proxy2Demo.csproj │ ├── Proxy3Demo │ │ ├── 1. Subject Interface │ │ │ └── IMath.cs │ │ ├── 2.RealSubject │ │ │ └── Math.cs │ │ ├── 3.Proxy │ │ │ └── MathProxy.cs │ │ ├── Program.cs │ │ └── Proxy3Demo.csproj │ ├── Proxy4Demo │ │ ├── 1. Subject Interface │ │ │ └── IServer.cs │ │ ├── 2.RealSubject │ │ │ └── Server.cs │ │ ├── 3.Proxy │ │ │ └── NewServerProxy.cs │ │ ├── Program.cs │ │ └── Proxy4Demo.csproj │ ├── Proxy5Demo │ │ ├── 1. Subject Interface │ │ │ └── IDocument.cs │ │ ├── 2.RealSubject │ │ │ └── SensitiveDocument.cs │ │ ├── 3.Proxy │ │ │ └── SecureDocumentProxy.cs │ │ ├── Program.cs │ │ └── Proxy5Demo.csproj │ ├── Proxy6Demo │ │ ├── 1. Subject Interface │ │ │ └── ISharedFolder.cs │ │ ├── 2.RealSubject │ │ │ └── SharedFolder.cs │ │ ├── 3.Proxy │ │ │ └── SharedFolderProxy.cs │ │ ├── Employee.cs │ │ ├── Program.cs │ │ └── Proxy6Demo.csproj │ ├── Proxy7Demo │ │ ├── 1.Subject Interface │ │ │ └── IImage.cs │ │ ├── 2.RealSubject │ │ │ └── Image4K.cs │ │ ├── 3.Proxy │ │ │ └── Image4kProxy.cs │ │ ├── CoolImageControl.cs │ │ ├── Program.cs │ │ └── Proxy7Demo.csproj │ ├── Proxy8Demo │ │ ├── 1.Subject Interface │ │ │ └── IDataService.cs │ │ ├── 2.RealSubject │ │ │ └── DataService.cs │ │ ├── 3.Proxy │ │ │ └── DataServiceProxy.cs │ │ ├── Program.cs │ │ └── Proxy8Demo.csproj │ └── Proxy9Demo │ │ ├── 1.Subject Interface │ │ └── IUserRepository.cs │ │ ├── 2.RealSubject │ │ └── UserRepository.cs │ │ ├── 3.Proxy │ │ └── UserRepositoryProxy.cs │ │ ├── Program.cs │ │ └── Proxy9Demo.csproj └── Structural.md ├── 3_Behavioral Design Patterns ├── BehavioralPattern.md ├── ChainOfResponsibility │ ├── ChainOfResponsibility.md │ ├── ChainOfResponsibility0Demo │ │ ├── ChainOfResponsibility0Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Interface │ │ │ └── IHandler.cs │ │ └── step2-Concrete Handlers │ │ │ ├── ConcreteHandler1.cs │ │ │ └── ConcreteHandler2.cs │ ├── ChainOfResponsibility1Demo │ │ ├── ChainOfResponsibility1Demo - Backup.csproj │ │ ├── ChainOfResponsibility1Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Interface │ │ │ └── ChainHandler.cs │ │ └── step2-Concrete Handlers │ │ │ ├── ConcreteHandler1.cs │ │ │ ├── ConcreteHandler2.cs │ │ │ └── ConcreteHandler3.cs │ ├── ChainOfResponsibility2Demo │ │ ├── ChainOfResponsibility2Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Interface │ │ │ ├── AbstractHandler.cs │ │ │ └── IHandler.cs │ │ ├── Step3-Set Up(Client) │ │ │ └── Client.cs │ │ └── step2-Concrete Handlers │ │ │ ├── DogHandler.cs │ │ │ ├── MonkeyHandler.cs │ │ │ └── SquirrelHandler.cs │ ├── ChainOfResponsibility3Demo │ │ ├── ChainOfResponsibility3Demo.csproj │ │ ├── ContextObject.cs │ │ ├── Program.cs │ │ ├── Step1-Interface │ │ │ └── Handlerbase.cs │ │ └── step2-Concrete Handlers │ │ │ ├── TeamOne.cs │ │ │ ├── TeamThree.cs │ │ │ └── TeamTwo.cs │ ├── ChainOfResponsibility4Demo │ │ ├── ChainOfResponsibility4Demo - Backup.csproj │ │ ├── ChainOfResponsibility4Demo.csproj │ │ ├── Program.cs │ │ ├── Purchase.cs │ │ ├── Step1-Interface │ │ │ └── Approver.cs │ │ └── step2-Concrete Handlers │ │ │ ├── Director.cs │ │ │ ├── President.cs │ │ │ └── VicePresident.cs │ ├── ChainOfResponsibility5Demo │ │ ├── ChainOfResponsibility5Demo.csproj │ │ ├── DomainRequest.cs │ │ ├── Program.cs │ │ ├── Step1-Interface │ │ │ └── Handler.cs │ │ ├── Step3-Set Up(Client) │ │ │ └── DomainManager.cs │ │ └── step2-Concrete Handlers │ │ │ ├── AccountVerifier.cs │ │ │ ├── DomainChecker.cs │ │ │ └── PaymentsProcessor.cs │ ├── ChainOfResponsibility6Demo │ │ ├── ChainOfResponsibility6Demo.csproj │ │ ├── Description.md │ │ ├── Program.cs │ │ ├── Request.cs │ │ ├── Response.cs │ │ ├── Step1-Interface │ │ │ └── RequestHandler.cs │ │ └── step2-Concrete Handlers │ │ │ ├── AuthenticationHandler.cs │ │ │ └── AuthorizationHandler.cs │ └── Demo4VsDemo5.md ├── Command │ ├── Command Steps implementation.md │ ├── Command.md │ ├── Command00Demo │ │ ├── 1.Command Interface │ │ │ ├── Command.cs │ │ │ └── ICommand.cs │ │ ├── 2.Concrete Commands │ │ │ ├── DeleteCommand.cs │ │ │ └── UpsertCommand.cs │ │ ├── 3.Receiver │ │ │ └── DataReceiver.cs │ │ ├── 4.Invoker │ │ │ └── DataCommandInvoker.cs │ │ ├── Command00Demo.csproj │ │ ├── Program.cs │ │ └── explain.md │ ├── Command0Demo │ │ ├── 1.Command Interface │ │ │ └── ICommand.cs │ │ ├── 2.Concrete Commands │ │ │ ├── CoolButtonCommand.cs │ │ │ ├── DeleteCommand.cs │ │ │ ├── OpenCommand.cs │ │ │ └── SaveCommand.cs │ │ ├── 3.Receiver │ │ │ └── CoolButton.cs │ │ ├── Command0Demo.csproj │ │ └── Program.cs │ ├── Command1Demo │ │ ├── 1.Command Interface │ │ │ └── ICommand .cs │ │ ├── 2.Concrete Commands │ │ │ └── ProductCommand .cs │ │ ├── 3.Receiver │ │ │ └── Product.cs │ │ ├── 4.Invoker │ │ │ └── ModifyPrice .cs │ │ ├── Command1Demo.csproj │ │ ├── PriceAction.cs │ │ ├── Program.cs │ │ └── explain.md │ ├── Command2Demo │ │ ├── 1.Command Interface │ │ │ └── IOrder .cs │ │ ├── 2.Concrete Commands │ │ │ ├── BuyStock.cs │ │ │ └── SellStock.cs │ │ ├── 3.Receiver │ │ │ └── Stock.cs │ │ ├── 4.Invoker │ │ │ └── Broker .cs │ │ ├── Command2Demo.csproj │ │ └── Program.cs │ ├── Command3Demo │ │ ├── 1.Command Interface │ │ │ └── Command.cs │ │ ├── 2.Concrete Commands │ │ │ ├── AddCommand.cs │ │ │ ├── DivideCommand.cs │ │ │ ├── MultiplyCommand.cs │ │ │ └── SubtractCommand.cs │ │ ├── 3.Receiver │ │ │ └── public class SimpleCalculator.cs │ │ ├── 4.Invoker │ │ │ └── Invoker.cs │ │ ├── Command3Demo.csproj │ │ ├── Program.cs │ │ └── explain.md │ └── Command4Demo │ │ ├── 1.Command Interface │ │ └── ICommand.cs │ │ ├── 2.Concrete Commands │ │ ├── AddToCardCommand.cs │ │ ├── ChangeQuantityCommand.cs │ │ ├── RemoveAllFromCartCommand.cs │ │ └── RemoveFromCartCommand.cs │ │ ├── 3.Receiver │ │ └── Repositories │ │ │ ├── IProductRepository.cs │ │ │ ├── IShoppingCartRepository.cs │ │ │ ├── ProductsRepository.cs │ │ │ └── ShoppingCartRepository.cs │ │ ├── 4.Invoker │ │ └── CommandManager.cs │ │ ├── Command4Demo.csproj │ │ ├── Operation.cs │ │ ├── Product.cs │ │ ├── Program.cs │ │ └── explain.md ├── Iterator │ ├── Iterator.md │ ├── Iterator00Demo │ │ ├── Iterator00Demo.csproj │ │ ├── Node.cs │ │ ├── Program.cs │ │ ├── SortedBinaryTreeCollection.cs │ │ ├── SortedBinaryTreeIterator.cs │ │ ├── Step1-Iterator Interface │ │ │ └── IIterator.cs │ │ ├── Step2-Concrete Iterator │ │ │ └── ListIterator.cs │ │ ├── Step3-Collection Interface │ │ │ └── IAggregate.cs │ │ └── step4-Concrete Collection │ │ │ └── ListAggregate.cs │ ├── Iterator0Demo │ │ ├── Explain.md │ │ ├── Iterator0Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Iterator Interface │ │ │ └── IIterator.cs │ │ ├── Step2-Concrete Iterator │ │ │ └── ConcreteIterator.cs │ │ ├── Step3-Collection Interface │ │ │ └── IAggregate.cs │ │ └── step4-Concrete Collection │ │ │ └── ConcreteAggregate.cs │ ├── Iterator1Demo │ │ ├── Iterator1Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Iterator Interface │ │ │ └── Iterator.cs │ │ ├── Step2-Concrete Iterator │ │ │ └── ConcreteIterator.cs │ │ ├── Step3-Collection Interface │ │ │ └── Aggregate.cs │ │ └── step4-Concrete Collection │ │ │ └── ConcreteAggregate.cs │ ├── Iterator2Demo │ │ ├── Item.cs │ │ ├── Iterator2Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Iterator Interface │ │ │ └── IAbstractIterator.cs │ │ ├── Step2-Concrete Iterator │ │ │ └── Iterator.cs │ │ ├── Step3-Collection Interface │ │ │ └── IAbstractCollection.cs │ │ └── step4-Concrete Collection │ │ │ └── Collection.cs │ ├── Iterator3Demo │ │ ├── Employee.cs │ │ ├── Iterator3Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Iterator Interface │ │ │ └── AbstractIterator.cs │ │ ├── Step2-Concrete Iterator │ │ │ └── Iterator.cs │ │ ├── Step3-Collection Interface │ │ │ └── AbstractCollection.cs │ │ └── step4-Concrete Collection │ │ │ └── EmployeeCollection.cs │ └── Iterator4Demo │ │ ├── Iterator4Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Iterator Interface │ │ └── IIterator.cs │ │ ├── Step2-Concrete Iterator │ │ ├── LosAngelesNewspaperIterator.cs │ │ └── NewYorkNewspaperIterator.cs │ │ ├── Step3-Collection Interface │ │ └── INewspaper.cs │ │ └── step4-Concrete Collection │ │ ├── LosAngelesNewspaper.cs │ │ └── NewYorkNewspaper.cs ├── MediatoR │ ├── Mediator.md │ ├── Mediator0Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IMediator.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── ConcreteMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── BaseComponent.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── Component1.cs │ │ │ └── Component2.cs │ │ ├── Mediator0Demo.csproj │ │ └── Program.cs │ ├── Mediator10Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IMediator.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── HomeAutomationMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── SmartDevice.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── Fan.cs │ │ │ ├── Light.cs │ │ │ └── Thermostat.cs │ │ ├── Mediator10Demo.csproj │ │ └── Program.cs │ ├── Mediator11Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IChatRoomMediator.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── ChatRoomMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── User.cs │ │ ├── 04_CreateConcreteComponents │ │ │ └── ChatUser.cs │ │ ├── Mediator11Demo.csproj │ │ └── Program.cs │ ├── Mediator1Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── Mediator.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── ConcreteMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── Colleague.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── ConcreteColleague1.cs │ │ │ └── ConcreteColleague2.cs │ │ ├── Mediator1Demo.csproj │ │ └── Program.cs │ ├── Mediator2Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IChatRoom.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── Chatroom.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── Participant.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── Group1.cs │ │ │ └── Group2.cs │ │ ├── Mediator2Demo.csproj │ │ └── Program.cs │ ├── Mediator3Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IMediator.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── DialogMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── Control.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── Button.cs │ │ │ └── TextField.cs │ │ ├── Mediator3Demo.csproj │ │ └── Program.cs │ ├── Mediator4Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IMediator.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── ConcreteMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── Colleague.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── Colleague1.cs │ │ │ └── Colleague2.cs │ │ ├── Mediator4Demo.csproj │ │ └── Program.cs │ ├── Mediator5Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── Chatroom.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── TeamChatroom.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── TeamMember.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── Developer.cs │ │ │ └── Tester.cs │ │ ├── Mediator5Demo.csproj │ │ └── Program.cs │ ├── Mediator6Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IWindow.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── OptionsWindow.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── Control.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── Button.cs │ │ │ ├── Entry.cs │ │ │ └── List.cs │ │ ├── Mediator6Demo - Backup.csproj │ │ ├── Mediator6Demo.csproj │ │ └── Program.cs │ ├── Mediator7Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IMediator.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── NetworkMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ ├── IParticipant.cs │ │ │ └── Participant.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── DesktopComputer.cs │ │ │ └── Server.cs │ │ ├── Mediator7Demo.csproj │ │ └── Program.cs │ ├── Mediator8Demo │ │ ├── 01_DefineMediatorInterface │ │ │ └── IMediator.cs │ │ ├── 02_CreateConcreteMediator │ │ │ └── RegistrationFormMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ │ └── Component.cs │ │ ├── 04_CreateConcreteComponents │ │ │ ├── Button.cs │ │ │ ├── Checkbox.cs │ │ │ └── TextBox.cs │ │ ├── Mediator8Demo.csproj │ │ └── Program.cs │ └── Mediator9Demo │ │ ├── 01_DefineMediatorInterface │ │ └── IMediator.cs │ │ ├── 02_CreateConcreteMediator │ │ └── RegistrationFormMediator.cs │ │ ├── 03_DefineComponentBaseClass │ │ └── Component.cs │ │ ├── 04_CreateConcreteComponents │ │ ├── Light.cs │ │ ├── Speaker.cs │ │ └── Thermostat.cs │ │ ├── Mediator9Demo.csproj │ │ └── Program.cs ├── Memento │ ├── Memento.md │ ├── Memento0Demo │ │ ├── Memento0Demo - Backup.csproj │ │ ├── Memento0Demo.csproj │ │ ├── Program.cs │ │ ├── Step1- Create the Memento class │ │ │ └── Memento.cs │ │ ├── Step2- Define the Originator class │ │ │ └── Originator.cs │ │ └── Step3- Implement the Caretaker Class │ │ │ └── Caretaker.cs │ ├── Memento1Demo │ │ ├── Memento1Demo.csproj │ │ ├── Program.cs │ │ ├── Step1- Create the Memento class │ │ │ └── Memento.cs │ │ └── Step2- Define the Originator class │ │ │ └── Calculator.cs │ ├── Memento2Demo │ │ ├── Memento2Demo.csproj │ │ ├── Program.cs │ │ ├── Step1- Create the Memento class │ │ │ ├── ConcreteMemento.cs │ │ │ └── IMemento.cs │ │ ├── Step2- Define the Originator class │ │ │ └── Originator.cs │ │ └── Step3- Implement the Caretaker Class │ │ │ └── Caretaker.cs │ ├── Memento3Demo │ │ ├── Memento3Demo.csproj │ │ ├── Program.cs │ │ ├── Step1- Create the Memento class │ │ │ └── Memento.cs │ │ ├── Step2- Define the Originator class │ │ │ └── Originator.cs │ │ └── Step3- Implement the Caretaker Class │ │ │ └── Caretaker.cs │ ├── Memento4Demo │ │ ├── Memento4Demo.csproj │ │ ├── Program.cs │ │ ├── Step1- Create the Memento class │ │ │ └── Memento.cs │ │ ├── Step2- Define the Originator class │ │ │ └── Editor.cs │ │ ├── Step3- Implement the Caretaker Class │ │ │ └── Caretaker.cs │ │ └── explain.md │ ├── Memento5Demo │ │ ├── Memento5Demo.csproj │ │ ├── Program.cs │ │ ├── Step1- Create the Memento class │ │ │ └── EditorMemento.cs │ │ ├── Step2- Define the Originator class │ │ │ └── Editor.cs │ │ ├── Step3- Implement the Caretaker Class │ │ │ └── History.cs │ │ └── explain.md │ └── Memento6Demo │ │ ├── Memento6Demo.csproj │ │ ├── Program.cs │ │ ├── Step1- Create the Memento class │ │ └── EditorState.cs │ │ ├── Step2- Define the Originator class │ │ └── Editor.cs │ │ └── Step3- Implement the Caretaker Class │ │ └── History.cs ├── Observer │ ├── Observer.md │ ├── Observer0Demo │ │ ├── Observer0Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Define Observer Interface │ │ │ └── IObserver.cs │ │ ├── Step2-Define Subject Interface │ │ │ └── ISubject.cs │ │ ├── Step3-Implement Concrete Subject │ │ │ └── Publisher.cs │ │ ├── Step4-Implement Concrete Observers │ │ │ └── Subscriber.cs │ │ └── explain.md │ ├── Observer1Demo │ │ ├── Observer1Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Define Observer Interface │ │ │ └── Observer.cs │ │ ├── Step2-Define Subject Interface │ │ │ └── Subject.cs │ │ ├── Step3-Implement Concrete Subject │ │ │ └── ConcreteSubject.cs │ │ └── Step4-Implement Concrete Observers │ │ │ └── ConcreteObserver.cs │ ├── Observer2Demo │ │ ├── Explain.md │ │ ├── Observer2Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Define Observer Interface │ │ │ └── IInvestor.cs │ │ ├── Step2-Define Subject Interface │ │ │ └── Stock.cs │ │ ├── Step3-Implement Concrete Subject │ │ │ └── IBM.cs │ │ └── Step4-Implement Concrete Observers │ │ │ └── Investor.cs │ ├── Observer3Demo │ │ ├── Observer3Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Define Observer Interface │ │ │ └── IObserver.cs │ │ ├── Step2-Define Subject Interface │ │ │ └── ISubject.cs │ │ ├── Step3-Implement Concrete Subject │ │ │ └── Subject.cs │ │ └── Step4-Implement Concrete Observers │ │ │ └── Observer.cs │ ├── Observer4Demo │ │ ├── Observer4Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Define Observer Interface │ │ │ └── IRestaurant.cs │ │ ├── Step2-Define Subject Interface │ │ │ └── Vegetable.cs │ │ ├── Step3-Implement Concrete Subject │ │ │ └── Carrots.cs │ │ └── Step4-Implement Concrete Observers │ │ │ └── Restaurant.cs │ ├── Observer5Demo │ │ ├── Observer5Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Define Observer Interface │ │ │ └── IFan.cs │ │ ├── Step2-Define Subject Interface │ │ │ └── ICelebrity.cs │ │ ├── Step3-Implement Concrete Subject │ │ │ ├── GClooney.cs │ │ │ └── TSwift.cs │ │ └── Step4-Implement Concrete Observers │ │ │ └── Fan.cs │ ├── Observer6Demo │ │ ├── Observer6Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Define Observer Interface │ │ │ └── INotifier.cs │ │ ├── Step2-Define Subject Interface or Abstract │ │ │ └── AbstractStockMarket.cs │ │ ├── Step3-Implement Concrete Subject │ │ │ └── StockMarket.cs │ │ └── Step4-Implement Concrete Observers │ │ │ ├── EmailNotification.cs │ │ │ └── PushNotification.cs │ └── Observer7Demo │ │ ├── Observer7Demo.csproj │ │ ├── Program.cs │ │ ├── Step1-Define Observer Interface │ │ └── IObserver.cs │ │ ├── Step2-Define Subject Interface or Abstract │ │ └── ISubject.cs │ │ ├── Step3-Implement Concrete Subject │ │ └── WeatherStation.cs │ │ └── Step4-Implement Concrete Observers │ │ └── CurrentConditionsDisplay.cs ├── State │ ├── State1Demo │ │ ├── 1_CreateStateInterface │ │ │ └── State.cs │ │ ├── 2_ImplementConcreteStates │ │ │ ├── ConcreteStateA.cs │ │ │ └── ConcreteStateB.cs │ │ ├── 3_ContextClass │ │ │ └── Context.cs │ │ ├── Program.cs │ │ └── State1Demo.csproj │ ├── State2Demo │ │ ├── 1_CreateStateInterface │ │ │ └── State.cs │ │ ├── 2_ImplementConcreteStates │ │ │ ├── GoldState.cs │ │ │ ├── RedState.cs │ │ │ └── SilverState.cs │ │ ├── 3_ContextClass │ │ │ └── Account.cs │ │ ├── Program.cs │ │ ├── State2Demo.csproj │ │ └── explain.md │ ├── State3Demo │ │ ├── 1_CreateStateInterface │ │ │ └── IAtmState.cs │ │ ├── 2_ImplementConcreteStates │ │ │ ├── CorrectPinState.cs │ │ │ ├── HasCardState.cs │ │ │ ├── NoCardState.cs │ │ │ └── NoCashState.cs │ │ ├── 3_ContextClass │ │ │ └── AtmMachine.cs │ │ ├── Program.cs │ │ └── State3Demo.csproj │ ├── State4Demo │ │ ├── 1_CreateStateInterface │ │ │ └── IMobilePhoneState.cs │ │ ├── 2_ImplementConcreteStates │ │ │ ├── LockedScreenState.cs │ │ │ └── UnlockedScreenState.cs │ │ ├── 3_ContextClass │ │ │ └── MobilePhoneContext.cs │ │ ├── Program.cs │ │ └── State4Demo.csproj │ ├── State5Demo │ │ ├── 1_CreateStateInterface │ │ │ └── ITrafficLightState.cs │ │ ├── 2_ImplementConcreteStates │ │ │ ├── GreenLight.cs │ │ │ ├── RedLight.cs │ │ │ └── YellowLight.cs │ │ ├── 3_ContextClass │ │ │ └── TrafficLight.cs │ │ ├── Program.cs │ │ ├── State5Demo.csproj │ │ └── explain.md │ ├── State6Demo │ │ ├── 1_CreateStateInterface │ │ │ └── DocumentState.cs │ │ ├── 2_ImplementConcreteStates │ │ │ ├── ApprovedState.cs │ │ │ ├── DraftState.cs │ │ │ ├── PublishedState.cs │ │ │ └── ReviewState.cs │ │ ├── 3_ContextClass │ │ │ └── DocumentContext.cs │ │ ├── Program.cs │ │ └── State6Demo.csproj │ ├── State7Demo │ │ ├── 1_CreateStateInterface │ │ │ └── OrderState.cs │ │ ├── 2_ImplementConcreteStates │ │ │ ├── DeliveredState.cs │ │ │ ├── OrderedState.cs │ │ │ ├── PaidState.cs │ │ │ └── ShippedState.cs │ │ ├── 3_ContextClass │ │ │ └── OrderContext.cs │ │ ├── Program.cs │ │ ├── State7Demo.csproj │ │ └── explain.md │ ├── State8Demo │ │ ├── 1_CreateStateInterface │ │ │ └── PlayerState.cs │ │ ├── 2_ImplementConcreteStates │ │ │ ├── PausedState.cs │ │ │ ├── PlayingState.cs │ │ │ └── StoppedState.cs │ │ ├── 3_ContextClass │ │ │ └── VideoPlayerContext.cs │ │ ├── Program.cs │ │ ├── State8Demo.csproj │ │ └── explain.md │ └── state.md ├── Strategy │ ├── Strategy.md │ ├── Strategy1Demo │ │ ├── 1_Define_Strategy Interface │ │ │ └── Strategy.cs │ │ ├── 2_Concrete_Strategies │ │ │ ├── ConcreteStrategyA.cs │ │ │ ├── ConcreteStrategyB.cs │ │ │ └── ConcreteStrategyC.cs │ │ ├── 3_ContextClass │ │ │ └── Context.cs │ │ ├── Program.cs │ │ └── Strategy1Demo.csproj │ ├── Strategy2Demo │ │ ├── 1_Define_Strategy Interface │ │ │ └── SortStrategy.cs │ │ ├── 2_Concrete_Strategies │ │ │ ├── MergeSort.cs │ │ │ ├── QuickSort.cs │ │ │ └── ShellSort.cs │ │ ├── 3_ContextClass │ │ │ └── SortedList.cs │ │ ├── Program.cs │ │ └── Strategy2Demo.csproj │ ├── Strategy3Demo │ │ ├── 1_Define_Strategy Interface │ │ │ └── IPaymentStrategy.cs │ │ ├── 2_Concrete_Strategies │ │ │ ├── BankTransferPaymentStrategy.cs │ │ │ ├── CreditCardPaymentStrategy.cs │ │ │ └── PayPalPaymentStrategy.cs │ │ ├── 3_ContextClass │ │ │ └── PaymentContext.cs │ │ ├── Program.cs │ │ └── Strategy3Demo.csproj │ ├── Strategy4Demo │ │ ├── 1_Define_Strategy Interface │ │ │ └── ICompressionStrategy.cs │ │ ├── 2_Concrete_Strategies │ │ │ ├── RarCompressionStrategy.cs │ │ │ ├── SevenZipCompressionStrategy.cs │ │ │ └── ZipCompressionStrategy.cs │ │ ├── 3_ContextClass │ │ │ └── CompressionContext.cs │ │ ├── Program.cs │ │ └── Strategy4Demo.csproj │ └── Strategy5Demo │ │ ├── 1_Define_Strategy Interface │ │ └── IDiscountStrategy.cs │ │ ├── 2_Concrete_Strategies │ │ ├── LoyaltyDiscountStrategy.cs │ │ ├── PromotionalDiscountStrategy.cs │ │ └── SeasonalDiscountStrategy.cs │ │ ├── 3_ContextClass │ │ └── DiscountContext.cs │ │ ├── Program.cs │ │ └── Strategy5Demo.csproj ├── Template │ ├── Template1Demo │ │ ├── 1_AbstractClass │ │ │ └── AbstractClass.cs │ │ ├── 2_ConcreteClass │ │ │ ├── ConcreteClassA.cs │ │ │ └── ConcreteClassB.cs │ │ ├── Program.cs │ │ └── Template1Demo.csproj │ ├── Template2Demo │ │ ├── AbstractClass │ │ │ └── DataAccessor.cs │ │ ├── ConcreteClass │ │ │ ├── Categories.cs │ │ │ └── Products.cs │ │ ├── Program.cs │ │ └── Template2Demo.csproj │ ├── Template3Demo │ │ ├── AbstractClass │ │ │ └── DocumentParser.cs │ │ ├── ConcreteClass │ │ │ ├── DocParser.cs │ │ │ └── PdfParser.cs │ │ ├── Program.cs │ │ └── Template3Demo.csproj │ ├── Template4Demo │ │ ├── AbstractClass │ │ │ └── VehicleAssembly.cs │ │ ├── ConcreteClass │ │ │ ├── CarAssembly.cs │ │ │ └── MotorcycleAssembly.cs │ │ ├── Program.cs │ │ └── Template4Demo.csproj │ ├── Template5Demo │ │ ├── AbstractClass │ │ │ └── PaymentProcessor.cs │ │ ├── ConcreteClass │ │ │ ├── BankTransferProcessor .cs │ │ │ ├── CreditCardProcessor.cs │ │ │ └── PayPalProcessor.cs │ │ ├── Program.cs │ │ └── Template5Demo.csproj │ ├── Template6Demo │ │ ├── AbstractClass │ │ │ └── CookieRecipe.cs │ │ ├── ConcreteClass │ │ │ ├── ChocolateChipCookie.cs │ │ │ └── OatmealRaisinCookie.cs │ │ ├── Program.cs │ │ ├── Template6Demo.csproj │ │ └── explain.md │ ├── Template7Demo │ │ ├── AbstractClass │ │ │ ├── PanFood.cs │ │ │ └── PanFoodServiceBase.cs │ │ ├── ColdVeggiePizza.cs │ │ ├── ConcreteClass │ │ │ ├── ColdVeggiePizzaBakingService.cs │ │ │ ├── PieBakingService.cs │ │ │ └── PizzaBakingService.cs │ │ ├── Inheritance │ │ │ ├── Base.cs │ │ │ └── TemplateBase.cs │ │ ├── Pie.cs │ │ ├── Pizza.cs │ │ ├── Program.cs │ │ ├── Template7Demo.csproj │ │ ├── explain.md │ │ └── services │ │ │ └── LoggerAdapter.cs │ └── TemplateDescription.md └── Visitor │ ├── Visitor.md │ ├── Visitor1Demo │ ├── 1_Visitor Interface │ │ └── IVisitor.cs │ ├── 2_Create Concrete Visitors │ │ └── XmlExportVisitor.cs │ ├── 3_Define the Element Interface │ │ └── IElement.cs │ ├── 4_ Implement Concrete Elements │ │ ├── City.cs │ │ ├── Industry.cs │ │ └── SightSeeing.cs │ ├── Program.cs │ ├── Visitor1Demo - Backup (1).csproj │ ├── Visitor1Demo - Backup.csproj │ └── Visitor1Demo.csproj │ ├── Visitor2Demo │ ├── 1_Visitor Interface │ │ └── IVisitor.cs │ ├── 2_Create Concrete Visitors │ │ └── ConcreteVisitor1.cs │ ├── 3_Define the Element Interface │ │ └── IElement.cs │ ├── 4_ Implement Concrete Elements │ │ ├── ConcreteElementA.cs │ │ └── ConcreteElementB.cs │ ├── Program.cs │ └── Visitor2Demo.csproj │ ├── Visitor3Demo │ ├── 1_Visitor Interface │ │ └── IShapeVisitor.cs │ ├── 2_Create Concrete Visitors │ │ ├── RenderVisitor.cs │ │ └── SaveVisitor.cs │ ├── 3_Define the Element Interface │ │ └── IShapeVisitor.cs │ ├── 4_ Implement Concrete Elements │ │ ├── Circle.cs │ │ ├── Line.cs │ │ └── Rectangle.cs │ ├── Program.cs │ └── Visitor3Demo.csproj │ ├── Visitor4Demo │ ├── 1_Visitor Interface │ │ └── IShippingVisitor.cs │ ├── 2_Create Concrete Visitors │ │ └── StandardShippingVisitor.cs │ ├── 3_Define the Element Interface │ │ └── IProduct.cs │ ├── 4_ Implement Concrete Elements │ │ ├── Book.cs │ │ ├── Clothing.cs │ │ └── Electronics.cs │ ├── Program.cs │ └── Visitor4Demo.csproj │ ├── Visitor5Demo │ ├── 1_Visitor Interface │ │ └── IAnimalVisitor.cs │ ├── 2_Create Concrete Visitors │ │ ├── FeedingVisitor.cs │ │ └── GroomingVisitor.cs │ ├── 3_Define the Element Interface │ │ └── IAnimal.cs │ ├── 4_ Implement Concrete Elements │ │ ├── Cat.cs │ │ └── Dog.cs │ ├── Program.cs │ ├── Visitor5Demo.csproj │ └── explain.md │ ├── Visitor6Demo │ ├── 1_Visitor Interface │ │ └── IOperation.cs │ ├── 2_Create Concrete Visitors │ │ ├── DisableOperation.cs │ │ └── EnableOperation.cs │ ├── 3_Define the Element Interface │ │ └── Control.cs │ ├── 4_ Implement Concrete Elements │ │ ├── Button.cs │ │ └── TextBox.cs │ ├── Form.cs │ ├── Program.cs │ └── Visitor6Demo.csproj │ └── Visitor7Demo │ ├── 1_Visitor Interface │ └── IVisitor.cs │ ├── 2_Create Concrete Visitors │ └── MdConverterVisitor.cs │ ├── 3_Define the Element Interface │ └── IComponent.cs │ ├── 4_ Implement Concrete Elements │ ├── HtmlToTextConverter.cs │ └── TextToHtmlConverter.cs │ ├── Program.cs │ └── Visitor7Demo.csproj ├── CSharpDesignPatterns.sln ├── CSharpDesignPatterns.sln.DotSettings └── README.md /1_Creational Design Patterns/AbstractFactory/AbstractFactory1Demo/AbstractFactory1Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory1Demo/Step1-Abstract Products/ProductA.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory1Demo.Step1_Abstract_Products; 2 | 3 | // Step 1: Create abstract products that declare interfaces for a set of distinct but related products. 4 | public abstract class ProductA 5 | { 6 | public abstract string FunctionA(); 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory1Demo/Step1-Abstract Products/ProductB.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory1Demo.Step1_Abstract_Products; 2 | 3 | // Step 1: Create abstract products that declare interfaces for a set of distinct but related products. 4 | public abstract class ProductB 5 | { 6 | public abstract string FunctionB(); 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/AbstractFactory2Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory2Demo.Step4_Concrete_Factories; 2 | using AbstractFactory2Demo.Step5_Client; 3 | 4 | 5 | var store = new FurnitureStore(new ModernFurnitureFactory()); 6 | store.ShowCaseFurniture(); -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step1-AbstractProducts/IChair.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory2Demo.Step1_AbstractProducts; 2 | 3 | // Step 1: Define Abstract Products - Furniture items like Chair and Sofa. 4 | public interface IChair 5 | { 6 | void SitOn(); 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step1-AbstractProducts/ICoffeeTable.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory2Demo.Step1_AbstractProducts; 2 | 3 | public interface ICoffeeTable 4 | { 5 | void Description(); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step1-AbstractProducts/ISofa.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory2Demo.Step1_AbstractProducts; 2 | // Step 1: Define Abstract Products - Furniture items like Chair and Sofa. 3 | 4 | public interface ISofa 5 | { 6 | void RelaxOn(); 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step2-Concrete Products/ModernCoffeeTable.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory2Demo.Step1_AbstractProducts; 2 | 3 | namespace AbstractFactory2Demo.Step2_Concrete_Products; 4 | 5 | public class ModernCoffeeTableL: ICoffeeTable 6 | { 7 | public void Description() 8 | { 9 | Console.WriteLine("we are eating on modern coffee table"); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step2-Concrete Products/ModernSofa.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory2Demo.Step1_AbstractProducts; 2 | 3 | namespace AbstractFactory2Demo.Step2_Concrete_Products; 4 | 5 | public class ModernSofa : ISofa 6 | { 7 | public void RelaxOn() 8 | { 9 | Console.WriteLine("Relaxing on a modern sofa."); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step2-Concrete Products/VictorianChair.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory2Demo.Step1_AbstractProducts; 2 | 3 | namespace AbstractFactory2Demo.Step2_Concrete_Products; 4 | 5 | public class VictorianChair : IChair 6 | { 7 | public void SitOn() 8 | { 9 | Console.WriteLine("Sitting on a Victorian chair."); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step2-Concrete Products/VictorianCoffeeTable.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory2Demo.Step1_AbstractProducts; 2 | 3 | namespace AbstractFactory2Demo.Step2_Concrete_Products; 4 | 5 | public class VictorianCoffeeTable:ICoffeeTable 6 | { 7 | public void Description() 8 | { 9 | Console.WriteLine("we are eating on victorian coffee table"); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step2-Concrete Products/VictorianSofa.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory2Demo.Step1_AbstractProducts; 2 | 3 | namespace AbstractFactory2Demo.Step2_Concrete_Products; 4 | 5 | public class VictorianSofa : ISofa 6 | { 7 | public void RelaxOn() 8 | { 9 | Console.WriteLine("Relaxing on a Victorian sofa."); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory2Demo/Step3-Abstract Factories/IFurnitureFactory.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory2Demo.Step1_AbstractProducts; 2 | 3 | namespace AbstractFactory2Demo.Step3_Abstract_Factories; 4 | 5 | // Step 3: Declare the Abstract Factory Interface. 6 | public interface IFurnitureFactory 7 | { 8 | IChair CreateChair(); 9 | ISofa CreateSofa(); 10 | ICoffeeTable CreateCoffeeTable(); 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory3Demo/AbstractFactory3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory3Demo/Enums/Brands.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory3Demo.Enums; 2 | 3 | public enum Brands 4 | { 5 | Apple, 6 | Dell, 7 | MSI 8 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory3Demo/Enums/ComputerTypes.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory3Demo.Enums; 2 | 3 | public enum ComputerTypes 4 | { 5 | Laptop, 6 | Desktop 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory3Demo/Enums/Processors.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory3Demo.Enums; 2 | 3 | public enum Processors 4 | { 5 | i3, 6 | i5, 7 | i7, 8 | i9 9 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory3Demo/Step1-Abstract Products/IBrand.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory3Demo.Step1_Abstract_Products; 2 | 3 | public interface IBrand 4 | { 5 | string GetBrand(); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory3Demo/Step1-Abstract Products/IComputerType.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory3Demo.Step1_Abstract_Products; 2 | 3 | public interface IComputerType 4 | { 5 | string GetComputerTypes(); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory3Demo/Step1-Abstract Products/IProcessor.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory3Demo.Step1_Abstract_Products; 2 | 3 | public interface IProcessor 4 | { 5 | string GetProcessor(); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory3Demo/Step3-Abstract Factory/IComputerFactory.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory3Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory3Demo.Step3_Abstract_Factory; 4 | 5 | internal interface IComputerFactory 6 | { 7 | IBrand Brand(); 8 | IComputerType ComputerTypes(); 9 | IProcessor Processor(); 10 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/AbstractFactory4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory4Demo.Step4_Concrete_Factories; 2 | using AbstractFactory4Demo.Step5_Client; 3 | 4 | var modernHouse = new House(new ModernHouseFactory()); 5 | modernHouse.DescribeHouse(); 6 | 7 | var victorianHouse = new House(new VictorianHouseFactory()); 8 | victorianHouse.DescribeHouse(); -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/Step1-Abstract Products/IDoor.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory4Demo.Step1_Abstract_Products; 2 | 3 | public interface IDoor 4 | { 5 | void Describe(); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/Step1-Abstract Products/IWindow.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory4Demo.Step1_Abstract_Products; 2 | 3 | public interface IWindow 4 | { 5 | void Describe(); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/Step2-Concrete Products/ModernDoor.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory4Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory4Demo.Step2_Concrete_Products; 4 | 5 | public class ModernDoor : IDoor 6 | { 7 | public void Describe() => Console.WriteLine("I am a Modern style door."); 8 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/Step2-Concrete Products/ModernWindow.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory4Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory4Demo.Step2_Concrete_Products; 4 | 5 | public class ModernWindow : IWindow 6 | { 7 | public void Describe() => Console.WriteLine("I am a Modern style window."); 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/Step2-Concrete Products/VictorianDoor.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory4Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory4Demo.Step2_Concrete_Products; 4 | 5 | // Concrete Products 6 | public class VictorianDoor : IDoor 7 | { 8 | public void Describe() => Console.WriteLine("I am a Victorian style door."); 9 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/Step2-Concrete Products/VictorianWindow.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory4Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory4Demo.Step2_Concrete_Products; 4 | 5 | public class VictorianWindow : IWindow 6 | { 7 | public void Describe() => Console.WriteLine("I am a Victorian style window."); 8 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory4Demo/Step3-Abstract Factories/IHouseFactory.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory4Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory4Demo.Step3_Abstract_Factories; 4 | 5 | public interface IHouseFactory 6 | { 7 | IDoor CreateDoor(); 8 | IWindow CreateWindow(); 9 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory5Demo/AbstractFactory5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory5Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory5Demo.Step4_Concrete_Factories; 2 | using AbstractFactory5Demo.Step5_Client; 3 | 4 | var darkTheme = new Application(new DarkThemeFactory()); 5 | darkTheme.Render(); -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory5Demo/Step1-Abstract Products/IButton .cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory5Demo.Step1_Abstract_Products; 2 | 3 | // Abstract Product Interfaces 4 | public interface IButton 5 | { 6 | void Render(); 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory5Demo/Step1-Abstract Products/ITextBox.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory5Demo.Step1_Abstract_Products; 2 | 3 | public interface ITextBox 4 | { 5 | void Render(); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory5Demo/Step2-Concrete Products/DarkButton.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory5Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory5Demo.Step2_Concrete_Products; 4 | // Concrete Product for Dark Theme 5 | public class DarkButton : IButton 6 | { 7 | public void Render() 8 | { 9 | Console.WriteLine("Rendering a dark-themed button."); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory5Demo/Step2-Concrete Products/DarkTextBox.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory5Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory5Demo.Step2_Concrete_Products; 4 | 5 | public class DarkTextBox : ITextBox 6 | { 7 | public void Render() 8 | { 9 | Console.WriteLine("Rendering a dark-themed text box."); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory5Demo/Step2-Concrete Products/LightTextBox.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory5Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory5Demo.Step2_Concrete_Products; 4 | 5 | public class LightTextBox : ITextBox 6 | { 7 | public void Render() 8 | { 9 | Console.WriteLine("Rendering a light-themed text box."); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory5Demo/Step3-Abstract Factories/IThemeFactory.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory5Demo.Step1_Abstract_Products; 2 | 3 | namespace AbstractFactory5Demo.Step3_Abstract_Factories; 4 | 5 | // Abstract Factory Interface for UI themes 6 | public interface IThemeFactory 7 | { 8 | IButton CreateButton(); 9 | ITextBox CreateTextBox(); 10 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory6Demo/AbstractFactory6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory6Demo/Step2-ConcreteProduct/CitiLoanAccount.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory6Demo.step1_AbstractProduct; 2 | 3 | namespace AbstractFactory6Demo.Step2_ConcreteProduct; 4 | 5 | public class CitiLoanAccount : ILoanAccount 6 | { 7 | public CitiLoanAccount() 8 | { 9 | Console.WriteLine("Returned Citi Loan Account"); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory6Demo/Step2-ConcreteProduct/CitiSavingAccount.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory6Demo.step1_AbstractProduct; 2 | 3 | namespace AbstractFactory6Demo.Step2_ConcreteProduct; 4 | public class CitiSavingAccount:ISavingAccount 5 | { 6 | public CitiSavingAccount() 7 | { 8 | Console.WriteLine("Returned Citi Savings Account"); 9 | } 10 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory6Demo/Step2-ConcreteProduct/NationalLoanAccount.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory6Demo.step1_AbstractProduct; 2 | 3 | namespace AbstractFactory6Demo.Step2_ConcreteProduct; 4 | 5 | public class NationalLoanAccount : ILoanAccount 6 | { 7 | public NationalLoanAccount() 8 | { 9 | Console.WriteLine("Returned National Loans Account"); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory6Demo/Step2-ConcreteProduct/NationalSavingAccount.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory6Demo.step1_AbstractProduct; 2 | 3 | namespace AbstractFactory6Demo.Step2_ConcreteProduct; 4 | 5 | public class NationalSavingAccount : ISavingAccount 6 | { 7 | public NationalSavingAccount() 8 | { 9 | Console.WriteLine("Returned National Savings Account"); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory6Demo/Step3-Abstract Factories/CreditUnionFactory.cs: -------------------------------------------------------------------------------- 1 | using AbstractFactory6Demo.step1_AbstractProduct; 2 | 3 | namespace AbstractFactory6Demo.Step3_Abstract_Factories; 4 | 5 | // step1-Abstract Product 6 | public abstract class CreditUnionFactory 7 | { 8 | public abstract ISavingAccount CreateSavingAccount(); 9 | public abstract ILoanAccount CreateLoanAccount(); 10 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory6Demo/step1-AbstractProduct/ILoanAccount.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory6Demo.step1_AbstractProduct; 2 | 3 | public interface ILoanAccount 4 | { 5 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/AbstractFactory/AbstractFactory6Demo/step1-AbstractProduct/ISavingAccount.cs: -------------------------------------------------------------------------------- 1 | namespace AbstractFactory6Demo.step1_AbstractProduct; 2 | 3 | public interface ISavingAccount 4 | { 5 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karwanessmat/CSharpDesignPatterns/fdf4a5a33a4d11cb0e2f836b4795797b7d0f0e4a/1_Creational Design Patterns/Builder/Builder.pdf -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder1Demo/Builder1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder1Demo/Step2-Builder interface/IToyBuilder.cs: -------------------------------------------------------------------------------- 1 | using Builder1Demo.step1_Product; 2 | 3 | namespace Builder1Demo.Step2_Builder_interface; 4 | 5 | public interface IToyBuilder 6 | { 7 | void SetModel(); 8 | void SetHead(); 9 | void Body(); 10 | void Legs(); 11 | 12 | Toy Toy(); 13 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder2Demo/Builder2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder2Demo/Step2-Builder interface/IVehicleBuilder.cs: -------------------------------------------------------------------------------- 1 | using Builder2Demo.step1_Product; 2 | 3 | namespace Builder2Demo.Step2_Builder_interface; 4 | 5 | public interface IVehicleBuilder 6 | { 7 | void SetModel(); 8 | void SetEngine(); 9 | void SetBody(); 10 | void SetAccessories(); 11 | 12 | Vehicle Vehicle(); 13 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder3Demo/Builder3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder3Demo/Program.cs: -------------------------------------------------------------------------------- 1 | // • Client code associates a builder with a director, then constructs and retrieves the product. 2 | 3 | using Builder3Demo.Step3_ConcreteBuilder; 4 | using Builder3Demo.Step4_Director; 5 | 6 | var director = new Director(new ConcreteBuilder()); 7 | director.Construct(); 8 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder3Demo/Step1-Product/Product.cs: -------------------------------------------------------------------------------- 1 | namespace Builder3Demo.Step1_Product; 2 | 3 | public class Product 4 | { 5 | 6 | public void AddPart(string part) 7 | { 8 | Console.WriteLine($"Part {part} added to the prodcut"); 9 | } 10 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder3Demo/Step2-Builder Interface/IBuilder.cs: -------------------------------------------------------------------------------- 1 | using Builder3Demo.Step1_Product; 2 | 3 | namespace Builder3Demo.Step2_Builder_Interface; 4 | 5 | public interface IBuilder 6 | { 7 | void BuildPartA(); 8 | void BuildPartB(); 9 | 10 | // it can be directly set in concrete builder without definition inside IBuilder 11 | Product GetProduct(); 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder3Demo/Step4-Director/Director.cs: -------------------------------------------------------------------------------- 1 | using Builder3Demo.Step2_Builder_Interface; 2 | 3 | namespace Builder3Demo.Step4_Director; 4 | 5 | public class Director(IBuilder builder) 6 | { 7 | public void Construct() 8 | { 9 | builder.BuildPartA(); 10 | builder.BuildPartB(); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder4Demo/Builder4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder4Demo/Step1 - Production/CarType.cs: -------------------------------------------------------------------------------- 1 | namespace Builder4Demo.Step1___Production; 2 | 3 | public enum CarType 4 | { 5 | SportsCar, 6 | SUV, 7 | Sedan, 8 | Convertible, 9 | Hatchback, 10 | PickupTruck 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder4Demo/Step2 - Builder Interface/IBuilder.cs: -------------------------------------------------------------------------------- 1 | using Builder4Demo.Step1___Production; 2 | 3 | namespace Builder4Demo.Step2___Builder_Interface; 4 | 5 | public interface IBuilder 6 | { 7 | void Reset(); 8 | void SetSeats(int number); 9 | void SetEngine(Engine engine); 10 | void SetTripComputer(bool hasTripComputer); 11 | void SetGps(bool hasGps); 12 | 13 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder5Demo/Builder5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder5Demo/Step2 - Builder Interface/IVehicleBuilder.cs: -------------------------------------------------------------------------------- 1 | using Builder5Demo.Step1_Production; 2 | 3 | namespace Builder5Demo.Step2___Builder_Interface; 4 | 5 | public interface IVehicleBuilder 6 | { 7 | void SetType(); 8 | void SetWheels(); 9 | void SetEngine(); 10 | void SetColor(); 11 | Vehicle Build(); 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder6Demo/Builder6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder6Demo/Step2 - Builder Interface/IComputerBuilder.cs: -------------------------------------------------------------------------------- 1 | using Builder6Demo.Step1_Production; 2 | 3 | namespace Builder6Demo.Step2___Builder_Interface; 4 | 5 | public interface IComputerBuilder 6 | { 7 | void SetType(); 8 | void SetCpu(); 9 | void SetRam(); 10 | void SetStorage(); 11 | void SetGraphicsCard(); 12 | Computer Build(); 13 | } 14 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder7Demo/Builder7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder7Demo/Step2 - Builder Interface/IFurnitureInventoryBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace Builder7Demo.Step2___Builder_Interface; 2 | 3 | public interface IFurnitureInventoryBuilder 4 | { 5 | IFurnitureInventoryBuilder AddTitle(); 6 | IFurnitureInventoryBuilder AddDimensions(); 7 | IFurnitureInventoryBuilder AddLogistics(DateTime dateTime); 8 | InventoryReport GetDailyReport(); 9 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder8Demo/Builder8Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder8Demo/Step1-Production/LinuxPlayButton.cs: -------------------------------------------------------------------------------- 1 | using Builder8Demo.Helper; 2 | 3 | namespace Builder8Demo.Step1_Production; 4 | internal class LinuxPlayButton: PlayButton 5 | { 6 | public override Task Play(string fileName) 7 | { 8 | LinuxPlayerUtility.StartBashProcess($"mpg123 -q '{fileName}'"); 9 | return Task.CompletedTask; 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder8Demo/Step1-Production/PlayButton.cs: -------------------------------------------------------------------------------- 1 | namespace Builder8Demo.Step1_Production; 2 | 3 | 4 | public abstract class PlayButton 5 | { 6 | public abstract Task Play(string fileName); 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder8Demo/Step1-Production/Player.cs: -------------------------------------------------------------------------------- 1 | namespace Builder8Demo.Step1_Production; 2 | 3 | public class Player 4 | { 5 | public PlayButton? PlayButton { get; set; } 6 | public StopButton? StopButton { get; set; } 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder8Demo/Step1-Production/StopButton.cs: -------------------------------------------------------------------------------- 1 | namespace Builder8Demo.Step1_Production; 2 | 3 | public abstract class StopButton 4 | { 5 | public abstract Task Stop(string fileName); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder8Demo/Step1-Production/WindowsPlayButton.cs: -------------------------------------------------------------------------------- 1 | using Builder8Demo.Helper; 2 | 3 | namespace Builder8Demo.Step1_Production; 4 | 5 | internal class WindowsPlayButton : PlayButton 6 | { 7 | public override Task Play(string fileName) 8 | { 9 | WindowsPlayerUtility.ExecuteMciCommand($"Play {fileName}"); 10 | return Task.CompletedTask; 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder8Demo/Step1-Production/WindowsStopButton.cs: -------------------------------------------------------------------------------- 1 | using Builder8Demo.Helper; 2 | 3 | namespace Builder8Demo.Step1_Production; 4 | 5 | internal class WindowsStopButton : StopButton 6 | { 7 | public override Task Stop(string fileName) 8 | { 9 | WindowsPlayerUtility.ExecuteMciCommand($"Stop {fileName}"); 10 | return Task.CompletedTask; 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/Builder8Demo/Step2 - Builder Interface/IPlayerBuilder.cs: -------------------------------------------------------------------------------- 1 | using Builder8Demo.Step1_Production; 2 | 3 | namespace Builder8Demo.Step2___Builder_Interface; 4 | 5 | public interface IPlayerBuilder 6 | { 7 | void AddPlayButton(); 8 | void AddStopButton(); 9 | Player BuildPlayer(); 10 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Builder/document.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karwanessmat/CSharpDesignPatterns/fdf4a5a33a4d11cb0e2f836b4795797b7d0f0e4a/1_Creational Design Patterns/Builder/document.docx -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory1Demo/Factory1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory1Demo/Step1_Product Interface/IShape.cs: -------------------------------------------------------------------------------- 1 | namespace Factory1Demo.Step1_Product_Interface; 2 | 3 | public interface IShape 4 | { 5 | void Draw(); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory1Demo/Step2_Product Concretes/Circle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Factory1Demo.Step1_Product_Interface; 3 | 4 | namespace Factory1Demo.Step2_Product_Concretes; 5 | 6 | public class Circle:IShape 7 | { 8 | public void Draw() 9 | { 10 | Console.WriteLine("Shape of Circle"); 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory1Demo/Step2_Product Concretes/Rectangle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Factory1Demo.Step1_Product_Interface; 3 | 4 | namespace Factory1Demo.Step2_Product_Concretes; 5 | 6 | public class Rectangle:IShape 7 | { 8 | public void Draw() 9 | { 10 | Console.WriteLine("Shape of Rectangle"); 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory1Demo/Step2_Product Concretes/Square.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Factory1Demo.Step1_Product_Interface; 3 | 4 | namespace Factory1Demo.Step2_Product_Concretes; 5 | 6 | public class Square:IShape 7 | { 8 | public void Draw() 9 | { 10 | Console.WriteLine("Shape of Square"); 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory2Demo/Factory2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory2Demo/Step1_Product Interface/IVehicle.cs: -------------------------------------------------------------------------------- 1 | namespace Factory2Demo.Step1_Product_Interface; 2 | 3 | public interface IVehicle 4 | { 5 | void Drive(int km); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory2Demo/Step2_Product Concretes/Bike.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Factory2Demo.Step1_Product_Interface; 3 | 4 | namespace Factory2Demo.Step2_Product_Concretes; 5 | 6 | public class Bike:IVehicle 7 | { 8 | public void Drive(int km) 9 | { 10 | Console.WriteLine($"Drive {km} by bike"); 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory2Demo/Step2_Product Concretes/Scooter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Factory2Demo.Step1_Product_Interface; 3 | 4 | namespace Factory2Demo.Step2_Product_Concretes; 5 | 6 | public class Scooter : IVehicle 7 | { 8 | public void Drive(int km) 9 | { 10 | Console.WriteLine($"Drive {km} by scooter"); 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory2Demo/Step3_Creator/CreatorVehicleFactory.cs: -------------------------------------------------------------------------------- 1 | using Factory2Demo.Step1_Product_Interface; 2 | 3 | namespace Factory2Demo.Step3_Creator; 4 | 5 | // abstract class creator 6 | public abstract class CreatorVehicleFactory 7 | { 8 | public abstract IVehicle GetVehicle(VehicleType vehicleType); 9 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory2Demo/VehicleType.cs: -------------------------------------------------------------------------------- 1 | namespace Factory2Demo; 2 | 3 | public enum VehicleType 4 | { 5 | Bike=1, 6 | Scooter 7 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory3Demo/Factory3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory3Demo/Step1_Product Interface/Player.cs: -------------------------------------------------------------------------------- 1 | namespace Factory3Demo.Step1_Product_Interface; 2 | 3 | public abstract class Player 4 | { 5 | public abstract Task Play(string fileName); 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory3Demo/Step3_Creator/PlayerCreator.cs: -------------------------------------------------------------------------------- 1 | using Factory3Demo.Step1_Product_Interface; 2 | 3 | namespace Factory3Demo.Step3_Creator; 4 | 5 | public abstract class PlayerCreator 6 | { 7 | public abstract Player CreatePlayer(); 8 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory4Demo/Factory4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | Factory4Demo 7 | enable 8 | enable 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory4Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Factory4Demo.Step3_Creator; 2 | using Factory4Demo.step4_Concrete_Creator; 3 | 4 | LogisticProviderFactory logistics = new RoadLogisticProviderFactory(); 5 | logistics.PlanDelivery(); 6 | 7 | logistics = new AirLogisticProviderFactory(); 8 | logistics.PlanDelivery(); 9 | 10 | 11 | logistics = new SeaLogisticProviderFactory(); 12 | logistics.PlanDelivery(); 13 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory4Demo/Step1_Product Interface/ITransport.cs: -------------------------------------------------------------------------------- 1 | namespace Factory4Demo.Step1_Product_Interface; 2 | 3 | /// 4 | /// 1. Make all products follow the same interface. This interface 5 | /// should declare methods that make sense in every product. 6 | /// 7 | public interface ITransport 8 | { 9 | void Deliver(); 10 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory4Demo/Step2_Product Concretes/Ship.cs: -------------------------------------------------------------------------------- 1 | using Factory4Demo.Step1_Product_Interface; 2 | 3 | namespace Factory4Demo.Step2_Product_Concretes; 4 | 5 | public class Ship : ITransport 6 | { 7 | public void Deliver() 8 | { 9 | Console.WriteLine("Delivering by sea in a ship."); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory4Demo/Step2_Product Concretes/Truck.cs: -------------------------------------------------------------------------------- 1 | using Factory4Demo.Step1_Product_Interface; 2 | 3 | namespace Factory4Demo.Step2_Product_Concretes; 4 | 5 | public class Truck : ITransport 6 | { 7 | public void Deliver() 8 | { 9 | Console.WriteLine("Delivering by land in a truck."); 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory5Demo/Factory5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory5Demo/Step1_Product Interface/SavingsAccount.cs: -------------------------------------------------------------------------------- 1 | namespace Factory5Demo.Step1_Product_Interface; 2 | 3 | /// 4 | /// Product (Interface or Abstract) 5 | /// 6 | public abstract class SavingsAccount 7 | { 8 | public decimal Balance { get; set; } 9 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory5Demo/Step2_Product Concretes/CitiSavingsAcct.cs: -------------------------------------------------------------------------------- 1 | using Factory5Demo.Step1_Product_Interface; 2 | 3 | namespace Factory5Demo.Step2_Product_Concretes; 4 | 5 | public class CitiSavingsAcct:SavingsAccount 6 | { 7 | public CitiSavingsAcct() 8 | { 9 | Balance = 5000; 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory5Demo/Step2_Product Concretes/NationalSavingAcct.cs: -------------------------------------------------------------------------------- 1 | using Factory5Demo.Step1_Product_Interface; 2 | 3 | namespace Factory5Demo.Step2_Product_Concretes; 4 | 5 | public class NationalSavingAcct : SavingsAccount 6 | { 7 | public NationalSavingAcct() 8 | { 9 | Balance = 2000; 10 | } 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory5Demo/Step3_Creator/ICreditUnionFactory.cs: -------------------------------------------------------------------------------- 1 | using Factory5Demo.Step1_Product_Interface; 2 | 3 | namespace Factory5Demo.Step3_Creator; 4 | 5 | /// 6 | /// Creator (Interface or Abstract class) 7 | /// 8 | public interface ICreditUnionFactory 9 | { 10 | SavingsAccount GetSavingsAccount(string acctNo); 11 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory6Demo/Factory6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory6Demo/Models/Risk.cs: -------------------------------------------------------------------------------- 1 | namespace Factory6Demo.Models; 2 | 3 | public enum Risk 4 | { 5 | High, 6 | Medium, 7 | Low 8 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory6Demo/Models/RiskModel.cs: -------------------------------------------------------------------------------- 1 | namespace Factory6Demo.Models; 2 | 3 | public class RiskModel 4 | { 5 | public Risk Risk { get; set; } 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/FactoryMethod/Factory6Demo/Step1_Product Interface/IProcessor.cs: -------------------------------------------------------------------------------- 1 | using Factory6Demo.Models; 2 | 3 | namespace Factory6Demo.Step1_Product_Interface; 4 | 5 | public interface IProcessor 6 | { 7 | List Predict(); 8 | Risk Risk { get; set; } 9 | 10 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karwanessmat/CSharpDesignPatterns/fdf4a5a33a4d11cb0e2f836b4795797b7d0f0e4a/1_Creational Design Patterns/Prototype/Prototype.docx -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karwanessmat/CSharpDesignPatterns/fdf4a5a33a4d11cb0e2f836b4795797b7d0f0e4a/1_Creational Design Patterns/Prototype/Prototype.pdf -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype1Demo/Prototype1Demo/Prototype1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype1Demo/Prototype1Demo/Step1-Prototype interface/SandwichPrototype.cs: -------------------------------------------------------------------------------- 1 | namespace Prototype1Demo.Step1_Prototype_interface; 2 | 3 | /// 4 | /// The Prototype abstract class 5 | /// 6 | internal abstract class SandwichPrototype 7 | { 8 | public abstract SandwichPrototype Clone(); 9 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype2Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Prototype2Demo.Step3_Prototype_Registry__Client_; 2 | 3 | var bakery = new Bakery(); 4 | bakery.MakeCookie(); -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype2Demo/Prototype2Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype2Demo/Step1-Prototype interface/Cookie.cs: -------------------------------------------------------------------------------- 1 | namespace Prototype2Demo.Step1_Prototype_interface; 2 | 3 | public abstract class Cookie 4 | { 5 | public abstract Cookie Clone(); 6 | } 7 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype2Demo/Step2-ConcretePrototypes/SquareCookie.cs: -------------------------------------------------------------------------------- 1 | using Prototype2Demo.Step1_Prototype_interface; 2 | 3 | namespace Prototype2Demo.Step2_ConcretePrototypes; 4 | 5 | public class SquareCookie(int sideLength) : Cookie 6 | { 7 | public int SideLength { get; set; } = sideLength; 8 | public override Cookie Clone() 9 | { 10 | return new SquareCookie(SideLength); 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype3Demo/Prototype3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype3Demo/Step1-Prototype interface/Cookie.cs: -------------------------------------------------------------------------------- 1 | namespace Prototype3Demo.Step1_Prototype_interface; 2 | 3 | public interface IPrototype 4 | { 5 | string GetColor(); 6 | IPrototype Clone(); 7 | } 8 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype4Demo/Prototype4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype4Demo/Step1-Prototype interface/Cookie.cs: -------------------------------------------------------------------------------- 1 | namespace Prototype4Demo.Step1_Prototype_interface; 2 | 3 | public interface IProductPrototype 4 | { 5 | IProductPrototype Clone(); 6 | } 7 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype4Demo/Step3-Prototype Registry (Client)/ECommerceApplication.cs: -------------------------------------------------------------------------------- 1 | namespace Prototype4Demo.Step3_Prototype_Registry__Client_; 2 | 3 | public class ECommerceApplication 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype5Demo/Prototype5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype5Demo/Step1-Prototype interface/ICampaign.cs: -------------------------------------------------------------------------------- 1 | namespace Prototype5Demo.Step1_Prototype_interface; 2 | 3 | public interface ICampaign 4 | { 5 | decimal TotalBudget { get; set; } 6 | string CampaignName { get; set; } 7 | 8 | void StartCampaign(); 9 | void PrintData(); 10 | 11 | ICampaign Clone(); 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Prototype/Prototype6Demo/Step1-Prototype interface/ICustomCloneable.cs: -------------------------------------------------------------------------------- 1 | namespace Prototype6Demo.Step1_Prototype_interface; 2 | 3 | public interface ICustomCloneable 4 | { 5 | ICustomCloneable Clone(); 6 | } 7 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton1Demo/Singleton1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton2Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Singleton2Demo; 2 | 3 | var instance =Singleton.GetInstance(); 4 | instance.DoSomething(); -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton2Demo/Singleton2Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton3Demo/Program.cs: -------------------------------------------------------------------------------- 1 | // See https://aka.ms/new-console-template for more information 2 | Console.WriteLine("Hello, World!"); 3 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton3Demo/Singleton3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton4Demo/Program.cs: -------------------------------------------------------------------------------- 1 |  2 | using Singleton4Demo; 3 | 4 | AppConfigurations? appSettings = AppConfigurations.Instance; 5 | Console.WriteLine(appSettings.GetSetting("ConnectionString")); 6 | Console.WriteLine(appSettings.GetSetting("ApiKeyName")); 7 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton4Demo/Singleton4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton5Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Singleton5Demo; 2 | 3 | var bl = new SomeBusinessLogic(); 4 | bl.Process(); -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton5Demo/Singleton5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton5Demo/SomeBusinessLogic.cs: -------------------------------------------------------------------------------- 1 | namespace Singleton5Demo; 2 | 3 | public class SomeBusinessLogic 4 | { 5 | public void Process() 6 | { 7 | var logger =Logger.Instance; 8 | logger.Log("Process started"); 9 | Console.WriteLine("process is running"); 10 | Logger.Instance.Log("Process finished successfully."); 11 | } 12 | } -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton6Demo/Singleton6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton7Demo/Singleton7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton8Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Singleton8Demo; 2 | 3 | LazySingleton.Instance.DoAction(); -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton8Demo/Singleton8Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /1_Creational Design Patterns/Singleton/Singleton9Demo/Singleton9Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/Adapter10Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/Plugins/Earth.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter10Demo.Plugins 2 | { 3 | public class Earth 4 | { 5 | public void Render(Spreadsheet _document) 6 | { 7 | Console.WriteLine("Rendering Earth visualization"); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Adapter10Demo.Framework; 2 | using Adapter10Demo.Plugins; 3 | 4 | var dashboard = new Dashboard(new Spreadsheet()); 5 | dashboard.Render(new EarthAdapter(new Earth())); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/Spreadsheet.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter10Demo 2 | { 3 | public class Spreadsheet 4 | { 5 | public int Id { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/Step3- Adaptee/Dashboard.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter10Demo.Framework 2 | { 3 | public class Dashboard(Spreadsheet document) 4 | { 5 | public void Render(IGraphic graphic) 6 | { 7 | graphic.Generate(document); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/Step3- Adaptee/EarthAdapter.cs: -------------------------------------------------------------------------------- 1 | using Adapter10Demo.Plugins; 2 | 3 | namespace Adapter10Demo.Framework 4 | { 5 | public class EarthAdapter(Earth earth) : IGraphic 6 | { 7 | public void Generate(Spreadsheet doc) 8 | { 9 | earth.Render(doc); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/step1- Client Interface/IGraphic.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter10Demo.Framework 2 | { 3 | public interface IGraphic 4 | { 5 | void Generate(Spreadsheet doc); 6 | } 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/step2-Adapter Class/BarChartRace.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter10Demo.Framework 2 | { 3 | public class BarChartRace : IGraphic 4 | { 5 | public void Generate(Spreadsheet doc) 6 | { 7 | Console.WriteLine("Showing Bar Chart graphic"); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter10Demo/step2-Adapter Class/PlottingCompetitors.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter10Demo.Framework 2 | { 3 | public class PlottingCompetitors : IGraphic 4 | { 5 | public void Generate(Spreadsheet doc) 6 | { 7 | Console.WriteLine("Showing Plotting Competitors graphic"); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter1Demo/Adapter1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter1Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adapter1Demo; 4 | 5 | internal class Program 6 | { 7 | private static void Main(string[] args) 8 | { 9 | Console.WriteLine(""); 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter1Demo/Step3- Adaptee/Adaptee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adapter1Demo.Step3__Adaptee; 4 | 5 | internal class Adaptee 6 | { 7 | public void SpecificRequest() 8 | { 9 | Console.WriteLine("Inside Adaptee:SpecificRequest() "); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter1Demo/step1- Client Interface/Target.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter1Demo.step1___Client_Interface; 2 | 3 | internal abstract class Target 4 | { 5 | public abstract void Request(); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter2Demo/Adapter2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter2Demo/Step3- Adaptee/Adaptee.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter2Demo.Step3__Adaptee; 2 | 3 | public class Adaptee 4 | { 5 | public string SpecificRequest() 6 | { 7 | return "Method inside Adaptee Class"; 8 | } 9 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter2Demo/step1- Client Interface/ITarget.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter2Demo.step1___Client_Interface; 2 | 3 | public interface ITarget 4 | { 5 | string Request(); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter2Demo/step2-Adapter Class/Adapter.cs: -------------------------------------------------------------------------------- 1 | using Adapter2Demo.step1___Client_Interface; 2 | using Adapter2Demo.Step3__Adaptee; 3 | 4 | namespace Adapter2Demo.step2_Adapter_Class; 5 | 6 | public class Adapter(Adaptee adaptee) : ITarget 7 | { 8 | //public Adapter() 9 | public string Request() 10 | { 11 | return $"this is from {adaptee.SpecificRequest()}"; 12 | } 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter3Demo/Adapter3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter4Demo/Adapter4Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter4Demo/Manufacturer.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter4Demo; 2 | 3 | public class Manufacturer 4 | { 5 | public string Name { get; set; } 6 | public string City { get; set; } 7 | public int Year { get; set; } 8 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter4Demo/Step1 - Interface/IXmlToJson.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter4Demo.Step1___Interface; 2 | 3 | /// 4 | /// Target 5 | /// 6 | public interface IXmlToJson 7 | { 8 | void ConvertXmlToJson(); 9 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter5Demo/Adapter5Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter5Demo/Step1 - Interface/ITarget.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Adapter5Demo.Step1___Interface; 4 | 5 | /// 6 | /// The 'ITarget' interface 7 | /// 8 | public interface ITarget 9 | { 10 | List GetEmployeeList(); 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter6Demo/Program.cs: -------------------------------------------------------------------------------- 1 | Console.WriteLine(""); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter7Demo/Adapter7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter7Demo/Client.cs: -------------------------------------------------------------------------------- 1 | using Adapter7Demo.Step1___Interface; 2 | 3 | namespace Adapter7Demo; 4 | 5 | // Client code 6 | internal class Client(IAdapter adapter) 7 | { 8 | public void DoWork() 9 | { 10 | adapter.SomeMethod(); 11 | } 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter7Demo/Step1 - Interface/IAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter7Demo.Step1___Interface; 2 | 3 | // Adapter interface 4 | public interface IAdapter 5 | { 6 | void SomeMethod(); 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter7Demo/Step3-Client - Adaptee/Adaptee.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter7Demo.Step3_Client___Adaptee; 2 | 3 | // Adaptee code 4 | public class Adaptee 5 | { 6 | public void IncompatibleMethod() 7 | { 8 | Console.WriteLine("Adaptee - IncompatibleMethod"); 9 | } 10 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter8Demo/Adapter8Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter8Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Adapter8Demo; 2 | using Adapter8Demo.Step1___Interface; 3 | using Adapter8Demo.step2_Adapter_Class; 4 | 5 | ITarget target = new Adapter(); 6 | var client = new Client(target); 7 | client.DoWork(); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter8Demo/Step1 - Interface/ITarget.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter8Demo.Step1___Interface; 2 | 3 | public interface ITarget 4 | { 5 | void SomeMethod(); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter8Demo/Step3-Client - Adaptee/Adaptee.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter8Demo.Step3_Client___Adaptee; 2 | 3 | public class Adaptee 4 | { 5 | public void IncompatibleMethod() 6 | { 7 | // Some incompatible behavior 8 | } 9 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter8Demo/step2-Adapter Class/Adapter .cs: -------------------------------------------------------------------------------- 1 | using Adapter8Demo.Step1___Interface; 2 | using Adapter8Demo.Step3_Client___Adaptee; 3 | 4 | namespace Adapter8Demo.step2_Adapter_Class; 5 | 6 | public class Adapter:Adaptee, ITarget 7 | { 8 | public void SomeMethod() 9 | { 10 | // Translate the method call to the incompatible method 11 | IncompatibleMethod(); 12 | } 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter9Demo/Adapter9Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter9Demo/AmericanAppliance.cs: -------------------------------------------------------------------------------- 1 | using Adapter9Demo.Step1___Interface; 2 | 3 | namespace Adapter9Demo; 4 | 5 | public class AmericanAppliance(IAmericanSocket socket) 6 | { 7 | public void PlugIn() 8 | { 9 | Console.WriteLine(socket.PlugIn()); 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter9Demo/Step1 - Interface/IAmericanSocket.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter9Demo.Step1___Interface; 2 | 3 | public interface IAmericanSocket 4 | { 5 | string PlugIn(); 6 | } 7 | 8 | // Adapter -------------------------------------------------------------------------------- /2_Structural Design Patterns/Adapter/Adapter9Demo/Step3-Client - Adaptee/EuropeanPlug.cs: -------------------------------------------------------------------------------- 1 | namespace Adapter9Demo.Step3_Client___Adaptee; 2 | 3 | // Incompatible Plug (Adaptee) 4 | public class EuropeanPlug 5 | { 6 | public string GetElectricity() 7 | { 8 | return "Getting 220V from European Plug"; 9 | } 10 | } 11 | 12 | // Incompatible Socket (Client's expectation) -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge1Demo/1_Define Implementor Interface/IDraw.cs: -------------------------------------------------------------------------------- 1 | namespace Bridge1Demo._1_Define_Implementor_Interface; 2 | 3 | public interface IDraw 4 | { 5 | public void DrawCircle(int radius, int x, int y); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge1Demo/3_Define Abstraction/Shape.cs: -------------------------------------------------------------------------------- 1 | using Bridge1Demo._1_Define_Implementor_Interface; 2 | 3 | namespace Bridge1Demo._3_Define_Abstraction; 4 | 5 | public abstract class Shape(IDraw draw) 6 | { 7 | 8 | /// 9 | /// this is a bridge 10 | /// 11 | protected IDraw DrawApi = draw; 12 | 13 | public abstract void Draw(); 14 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge1Demo/Bridge1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge2Demo/1_Define Implementor Interface/IWorkshop.cs: -------------------------------------------------------------------------------- 1 | namespace Bridge2Demo._1_Define_Implementor_Interface; 2 | 3 | // Implementor for bridge pattern 4 | public interface IWorkshop 5 | { 6 | public void Work(); 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge2Demo/2_Create Concrete Implementations/Assemble.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Bridge2Demo._1_Define_Implementor_Interface; 3 | 4 | namespace Bridge2Demo._2_Create_Concrete_Implementations; 5 | 6 | internal class Assemble:IWorkshop 7 | 8 | { 9 | public void Work() 10 | { 11 | Console.Write(" and "); 12 | Console.WriteLine("Assembled"); 13 | } 14 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge2Demo/2_Create Concrete Implementations/Produce.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Bridge2Demo._1_Define_Implementor_Interface; 3 | 4 | namespace Bridge2Demo._2_Create_Concrete_Implementations; 5 | 6 | // Concrete implementation 1 for bridge pattern 7 | public class Produce:IWorkshop 8 | { 9 | public void Work() 10 | { 11 | Console.Write("Produced"); 12 | } 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge2Demo/Bridge2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge3Demo/1_Define Implementor Interface/IColor.cs: -------------------------------------------------------------------------------- 1 | namespace Bridge3Demo._1_Define_Implementor_Interface; 2 | 3 | public interface IColor 4 | { 5 | void Color(); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge3Demo/2_Create Concrete Implementations/GreenColor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Bridge3Demo._1_Define_Implementor_Interface; 3 | 4 | namespace Bridge3Demo._2_Create_Concrete_Implementations; 5 | 6 | internal class GreenColor:IColor 7 | { 8 | public void Color() 9 | { 10 | Console.Write("Green "); 11 | } 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge3Demo/2_Create Concrete Implementations/RedColor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Bridge3Demo._1_Define_Implementor_Interface; 3 | 4 | namespace Bridge3Demo._2_Create_Concrete_Implementations; 5 | 6 | internal class RedColor:IColor 7 | { 8 | public void Color() 9 | { 10 | Console.Write("Red "); 11 | } 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge3Demo/3_Define Abstraction/Shape.cs: -------------------------------------------------------------------------------- 1 | using Bridge3Demo._1_Define_Implementor_Interface; 2 | 3 | namespace Bridge3Demo._3_Define_Abstraction; 4 | 5 | public abstract class Shape(IColor color) 6 | { 7 | /// 8 | /// it is bridge 9 | /// 10 | protected IColor Color = color; 11 | 12 | public abstract void SetColor(); 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge3Demo/Bridge3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge4Demo/1_Define Implementor Interface/IAreaCalculator.cs: -------------------------------------------------------------------------------- 1 | namespace Bridge4Demo._1_Define_Implementor_Interface; 2 | 3 | // Implementation 4 | public interface IAreaCalculator 5 | { 6 | double CalculateArea(params double[] dimensions); 7 | } 8 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge4Demo/3_Define Abstraction/IShape.cs: -------------------------------------------------------------------------------- 1 | namespace Bridge4Demo._3_Define_Abstraction; 2 | 3 | //Abstraction 4 | public interface IShape 5 | { 6 | double CalculateArea(); 7 | } 8 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge4Demo/Bridge4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge5Demo/Bridge5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge5Demo/Services/1_Define Implementor Interface/ISpeechProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Bridge5Demo.Services._1_Define_Implementor_Interface; 2 | 3 | // Implementation 4 | public interface ISpeechProvider 5 | { 6 | void TextToSpeechStandard(); 7 | void SpeechToTextStandard(); 8 | void SpeechToTextAI(); 9 | void TextToSpeechNeural(); 10 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge6Demo/1_Define Implementor Interface/IDataService.cs: -------------------------------------------------------------------------------- 1 | namespace Bridge6Demo._1_Define_Implementor_Interface; 2 | 3 | public interface IDataService 4 | { 5 | List GetData(); 6 | void InsertData(string item); 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge7Demo/1_Define Implementor Interface/IDevice.cs: -------------------------------------------------------------------------------- 1 | namespace Bridge7Demo._1_Define_Implementor_Interface; 2 | 3 | // Implementation 4 | // Implementor 5 | public interface IDevice 6 | { 7 | void TurnOn(); 8 | void TurnOff(); 9 | void SetVolume(int volume); 10 | } 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Bridge/Bridge7Demo/Bridge7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite1Demo/Composite1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite2Demo/Composite2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite3Demo/Composite3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite4Demo/1. Component/FileSystemItem.cs: -------------------------------------------------------------------------------- 1 | namespace Composite4Demo._1._Component; 2 | public abstract class FileSystemItem(string name) 3 | { 4 | public string Name { get; protected set; } = name; 5 | public abstract void Display(int depth); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite4Demo/2. Leaf/File.cs: -------------------------------------------------------------------------------- 1 | using Composite4Demo._1._Component; 2 | 3 | namespace Composite4Demo._2._Leaf; 4 | 5 | public class FileSystem(string name):FileSystemItem(name) 6 | { 7 | public override void Display(int depth) 8 | { 9 | Console.WriteLine(new string('-', depth) + Name); 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite4Demo/Composite4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite5Demo/1. Component/IComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Composite5Demo._1._Component; 2 | 3 | internal interface IComponent 4 | { 5 | string Name { get; } 6 | void Display(string currentPath); 7 | } 8 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite5Demo/2. Leaf/File.cs: -------------------------------------------------------------------------------- 1 | using Composite5Demo._1._Component; 2 | 3 | namespace Composite5Demo._2._Leaf; 4 | 5 | internal class FileItem(string name) : IComponent 6 | { 7 | public string Name { get; } = name; 8 | 9 | public void Display(string currentPath) 10 | { 11 | Console.WriteLine(currentPath + Name); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Composite/Composite5Demo/Composite5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorate2Demo/1_Component Interface/ICar.cs: -------------------------------------------------------------------------------- 1 | namespace Decorator2Demo._1_Component_Interface; 2 | 3 | public interface ICar 4 | { 5 | string GetDescription(); 6 | double GetCost(); 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorate2Demo/2_Create a Concrete Component/LuxuryCar.cs: -------------------------------------------------------------------------------- 1 | using Decorator2Demo._1_Component_Interface; 2 | 3 | namespace Decorator2Demo._2_Create_a_Concrete_Component; 4 | 5 | class LuxuryCar:ICar 6 | { 7 | public string GetDescription() 8 | { 9 | return "Luxury Car"; 10 | } 11 | public double GetCost() 12 | { 13 | return 1000 - 000.0; 14 | } 15 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorate2Demo/Decorator2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator1Demo/1_Component Interface/IComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Decorator1Demo._1_Component_Interface; 2 | 3 | public interface IComponent 4 | { 5 | string Operation(); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator1Demo/2_Create a Concrete Component/ConcreteComponent.cs: -------------------------------------------------------------------------------- 1 | using Decorator1Demo._1_Component_Interface; 2 | 3 | namespace Decorator1Demo._2_Create_a_Concrete_Component; 4 | 5 | public class ConcreteComponent:IComponent 6 | { 7 | public string Operation() 8 | { 9 | return "ConcreteComponent"; 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator1Demo/3_ Create an Abstract Decorator/Decorate.cs: -------------------------------------------------------------------------------- 1 | using Decorator1Demo._1_Component_Interface; 2 | 3 | namespace Decorator1Demo._3__Create_an_Abstract_Decorator; 4 | public abstract class Decorate(IComponent component):IComponent 5 | { 6 | public virtual string Operation() 7 | { 8 | return component.Operation(); 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator1Demo/Decorator1Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator3Demo/1_Component Interface/LibraryItem.cs: -------------------------------------------------------------------------------- 1 | namespace Decorator3Demo._1_Component_Interface; 2 | 3 | /// 4 | /// The 'Component' abstract class 5 | /// 6 | public abstract class LibraryItem 7 | { 8 | public int NumCopies { get; set; } 9 | public abstract void Display(); 10 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator3Demo/Decorator3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator4Demo/1_Component Interface/ITextProcessor.cs: -------------------------------------------------------------------------------- 1 | namespace Decorator4Demo._1_Component_Interface; 2 | 3 | public interface ITextProcessor 4 | { 5 | string? Process(string? input); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator4Demo/2_Create a Concrete Component/JsonTextProcessor.cs: -------------------------------------------------------------------------------- 1 | using Decorator4Demo._1_Component_Interface; 2 | 3 | namespace Decorator4Demo._2_Create_a_Concrete_Component; 4 | 5 | public class JsonTextProcessor:ITextProcessor 6 | { 7 | public string? Process(string? input) 8 | { 9 | // Simulate JSON processing 10 | return $"{{\"data\":\"{input}\"}}"; 11 | } 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator4Demo/2_Create a Concrete Component/PlainTextProcessor.cs: -------------------------------------------------------------------------------- 1 | using Decorator4Demo._1_Component_Interface; 2 | 3 | namespace Decorator4Demo._2_Create_a_Concrete_Component; 4 | public class PlainTextProcessor:ITextProcessor 5 | { 6 | public string? Process(string? input) 7 | { 8 | return input; 9 | } 10 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator4Demo/Decorator4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator5Demo/1_Component Interface/INotifier.cs: -------------------------------------------------------------------------------- 1 | namespace Decorator5Demo._1_Component_Interface; 2 | 3 | public interface INotifier 4 | { 5 | void Send(string message); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator5Demo/2_Create a Concrete Component/EmailNotifier.cs: -------------------------------------------------------------------------------- 1 | using Decorator5Demo._1_Component_Interface; 2 | 3 | namespace Decorator5Demo._2_Create_a_Concrete_Component; 4 | 5 | public class EmailNotifier:INotifier 6 | { 7 | public void Send(string message) 8 | { 9 | Console.WriteLine($"Email: {message}"); 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator5Demo/2_Create a Concrete Component/SmsNotifier.cs: -------------------------------------------------------------------------------- 1 | using Decorator5Demo._1_Component_Interface; 2 | 3 | namespace Decorator5Demo._2_Create_a_Concrete_Component; 4 | public class SmsNotifier:INotifier 5 | { 6 | 7 | public void Send(string message) 8 | { 9 | Console.WriteLine($"Sms: {message}"); 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator5Demo/3_ Create an Abstract Decorator/NotifierDecorator.cs: -------------------------------------------------------------------------------- 1 | using Decorator5Demo._1_Component_Interface; 2 | 3 | namespace Decorator5Demo._3__Create_an_Abstract_Decorator; 4 | 5 | public abstract class NotifierDecorator(INotifier notifier):INotifier 6 | { 7 | public virtual void Send(string message) 8 | { 9 | notifier.Send(message); 10 | } 11 | 12 | 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator5Demo/Decorator5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator6Demo/1_Component Interface/ICoffee.cs: -------------------------------------------------------------------------------- 1 | namespace Decorator6Demo._1_Component_Interface; 2 | 3 | public interface ICoffee 4 | { 5 | string Serve(); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator6Demo/2_Create a Concrete Component/Coffee.cs: -------------------------------------------------------------------------------- 1 | using Decorator6Demo._1_Component_Interface; 2 | 3 | namespace Decorator6Demo._2_Create_a_Concrete_Component; 4 | 5 | public class Coffee:ICoffee 6 | { 7 | public string Serve() 8 | { 9 | return "Coffee"; 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator6Demo/Decorator6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator7Demo/1_Component Interface/Car.cs: -------------------------------------------------------------------------------- 1 | namespace Decorator7Demo._1_Component_Interface; 2 | 3 | public abstract class Car 4 | { 5 | public string Description { get; set; } 6 | public abstract string GetDescription(); 7 | public abstract double GetCarPrice(); 8 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Decorator/Decorator7Demo/Decorator7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade1Demo/Facade1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade1Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Facade1Demo; 2 | using System; 3 | 4 | var facade = new Facade(); 5 | 6 | facade.CallSubSystemsMethod(); 7 | 8 | // Wait for user 9 | Console.ReadKey(); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade1Demo/Subsystem Classes/SubSystemOne.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facade1Demo.Subsystem_Classes; 4 | 5 | public class SubSystemOne 6 | { 7 | public void SystemOneMethodOne() 8 | { 9 | Console.WriteLine("System One Method One"); 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade1Demo/Subsystem Classes/SubSystemThree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facade1Demo.Subsystem_Classes; 4 | 5 | public class SubSystemThree 6 | { 7 | public void SystemOneMethodThree() 8 | { 9 | Console.WriteLine("System Three Method one"); 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade1Demo/Subsystem Classes/SubSystemTwo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facade1Demo.Subsystem_Classes; 4 | 5 | public class SubSystemTwo 6 | { 7 | public void SystemOneMethodTow() 8 | { 9 | Console.WriteLine("System Two Method One"); 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade2Demo/Facade2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade2Demo/Subsystem Classes/Bank.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facade2Demo.Subsystem_Classes; 4 | 5 | /// 6 | /// The 'Subsystem ClassA' class 7 | /// 8 | public class Bank 9 | 10 | { 11 | public bool HasSufficientSavings(Customer c, int amount) 12 | { 13 | Console.WriteLine("Check bank for " + c.Name); 14 | return amount>2500; 15 | } 16 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade2Demo/Subsystem Classes/Credit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facade2Demo.Subsystem_Classes; 4 | 5 | /// 6 | /// The 'Subsystem ClassB' class 7 | /// 8 | public class Credit 9 | { 10 | public bool HasGoodCredit(Customer c,decimal amount) 11 | { 12 | Console.WriteLine("Check credit for " + c.Name); 13 | return amount > 2500; 14 | } 15 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade2Demo/Subsystem Classes/Customer.cs: -------------------------------------------------------------------------------- 1 | namespace Facade2Demo.Subsystem_Classes; 2 | 3 | /// 4 | /// Customer class 5 | /// 6 | public class Customer(string name) 7 | { 8 | 9 | // Gets the name 10 | public string Name { get; } = name; 11 | 12 | // Constructor 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade2Demo/Subsystem Classes/Loan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facade2Demo.Subsystem_Classes; 4 | 5 | /// 6 | /// The 'Subsystem ClassC' class 7 | /// 8 | public class Loan 9 | 10 | { 11 | public bool HasNoBadLoans(Customer c) 12 | { 13 | Console.WriteLine("Check loans for " + c.Name); 14 | return true; 15 | } 16 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade3Demo/Facade3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade3Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Facade3Demo; 2 | 3 | var homeAutomation = new HomeAutomation(); 4 | 5 | // Simulating leaving the home 6 | Console.WriteLine("Leaving the home..."); 7 | homeAutomation.DepartHome(); 8 | 9 | Console.WriteLine(); 10 | 11 | // Simulating arriving home 12 | Console.WriteLine("Arriving home..."); 13 | homeAutomation.ArriveHome(); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade3Demo/Subsystem Classes/HeatingControl.cs: -------------------------------------------------------------------------------- 1 | namespace Facade3Demo.Subsystem_Classes; 2 | 3 | public class HeatingControl 4 | { 5 | public void IncreaseTemperature() 6 | { 7 | Console.WriteLine("Temperature increased"); 8 | } 9 | 10 | public void DecreaseTemperature() 11 | { 12 | Console.WriteLine("Temperature decreased"); 13 | } 14 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade3Demo/Subsystem Classes/LightingControl.cs: -------------------------------------------------------------------------------- 1 | namespace Facade3Demo.Subsystem_Classes; 2 | public class LightingControl 3 | { 4 | public void TurnOnLights() 5 | { 6 | Console.WriteLine("Lights turned on"); 7 | } 8 | 9 | public void TurnOffLights() 10 | { 11 | Console.WriteLine("Lights turned off"); 12 | } 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade3Demo/Subsystem Classes/SecurityControl.cs: -------------------------------------------------------------------------------- 1 | namespace Facade3Demo.Subsystem_Classes; 2 | 3 | public class SecurityControl 4 | { 5 | public void ActivateAlarm() 6 | { 7 | Console.WriteLine("Alarm activated"); 8 | } 9 | 10 | public void DeactivateAlarm() 11 | { 12 | Console.WriteLine("Alarm deactivated"); 13 | } 14 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade4Demo/Entities/City.cs: -------------------------------------------------------------------------------- 1 | namespace Facade4Demo.Entities; 2 | 3 | public class City 4 | { 5 | public City GetCityForZipCode(string zipCode) 6 | { 7 | // service or db lookup would go here 8 | return new City(); 9 | } 10 | 11 | public string Name => "Redmond"; 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade4Demo/Entities/State.cs: -------------------------------------------------------------------------------- 1 | namespace Facade4Demo.Entities; 2 | 3 | public class State 4 | { 5 | public State GetStateForZipCode(string zipCode) 6 | { 7 | // service or db lookup would go here 8 | return new State(); 9 | } 10 | 11 | public string Name => "Washington"; 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade4Demo/Entities/WeatherFacadeResults.cs: -------------------------------------------------------------------------------- 1 | namespace Facade4Demo.Entities; 2 | 3 | public class WeatherFacadeResults 4 | { 5 | public int Fahrenheit { get; set; } 6 | public int Celsius { get; set; } 7 | public City City { get; set; } 8 | public State State { get; set; } 9 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade4Demo/IWeatherFacade.cs: -------------------------------------------------------------------------------- 1 | using Facade4Demo.Entities; 2 | 3 | namespace Facade4Demo; 4 | 5 | public interface IWeatherFacade 6 | { 7 | WeatherFacadeResults GetTempInCity(string zipCode); 8 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade4Demo/Services/WeatherService.cs: -------------------------------------------------------------------------------- 1 | using Facade4Demo.Entities; 2 | 3 | namespace Facade4Demo.Services; 4 | 5 | public class WeatherService 6 | { 7 | public int GetTempFahrenheit(City city, State state) 8 | { 9 | // call to service or db would go here 10 | 11 | return 53; 12 | } 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade5Demo/Facade5Demo - Backup.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade5Demo/Facade5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade5Demo/IServiceFacade.cs: -------------------------------------------------------------------------------- 1 | namespace Facade5Demo; 2 | 3 | public interface IServiceFacade 4 | { 5 | Tuple CallFacade(); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade5Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Facade5Demo; 2 | 3 | IServiceFacade facade = new ServiceFacade(); 4 | 5 | Tuple result = facade.CallFacade(); 6 | 7 | Console.WriteLine(result.Item1 + " - " + result.Item2 + " - " + result.Item3); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade5Demo/Subsystem Classes/ServiceA.cs: -------------------------------------------------------------------------------- 1 | namespace Facade5Demo.Subsystem_Classes; 2 | 3 | public class ServiceA 4 | { 5 | public void Method1() 6 | { 7 | // do some work 8 | } 9 | 10 | public int Method2() 11 | { 12 | // do some work 13 | return 0; 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade5Demo/Subsystem Classes/ServiceB.cs: -------------------------------------------------------------------------------- 1 | namespace Facade5Demo.Subsystem_Classes; 2 | 3 | public class ServiceB 4 | { 5 | public void Method1() 6 | { 7 | // do some work 8 | } 9 | 10 | public string Method2() 11 | { 12 | // do some work 13 | 14 | return "ServiceB"; 15 | } 16 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade5Demo/Subsystem Classes/ServiceC.cs: -------------------------------------------------------------------------------- 1 | namespace Facade5Demo.Subsystem_Classes; 2 | 3 | public class ServiceC 4 | { 5 | public double Method1() 6 | { 7 | // do some work 8 | 9 | return 1.01; 10 | } 11 | 12 | public string Method2() 13 | { 14 | // do some work 15 | 16 | return "ServiceC string"; 17 | } 18 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade6Demo/Facade6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade6Demo/IComputerFacade.cs: -------------------------------------------------------------------------------- 1 | namespace Facade6Demo; 2 | 3 | public interface IComputerFacade 4 | { 5 | void Start(); 6 | void ShutDown(); 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade6Demo/Program.cs: -------------------------------------------------------------------------------- 1 |  2 | using Facade6Demo; 3 | 4 | IComputerFacade computer = new ComputerFacade(); 5 | 6 | // Start the computer 7 | computer.Start(); 8 | 9 | // Perform other operations... 10 | 11 | // Shut down the computer 12 | computer.ShutDown(); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade6Demo/Subsystem Classes/CPU.cs: -------------------------------------------------------------------------------- 1 | namespace Facade6Demo.Subsystem_Classes; 2 | 3 | public class CPU 4 | { 5 | public void Boot() 6 | { 7 | Console.WriteLine("Cpu booting up"); 8 | } 9 | 10 | public void ShutDown() 11 | { 12 | Console.WriteLine("Cpu shutting down"); 13 | } 14 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade6Demo/Subsystem Classes/HardDrive.cs: -------------------------------------------------------------------------------- 1 | namespace Facade6Demo.Subsystem_Classes; 2 | 3 | public class HardDrive 4 | { 5 | public byte[] Read(long lba, int size) 6 | { 7 | Console.WriteLine($"Reading {size} bytes from LBA {lba}..."); 8 | return new byte[size]; // Dummy data 9 | } 10 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade6Demo/Subsystem Classes/Memory.cs: -------------------------------------------------------------------------------- 1 | namespace Facade6Demo.Subsystem_Classes; 2 | 3 | public class Memory 4 | { 5 | public void Load(long position, byte[] data) 6 | { 7 | Console.WriteLine($"Loading data to position {position}..."); 8 | } 9 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade7Demo/Facade7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade7Demo/Student.cs: -------------------------------------------------------------------------------- 1 | namespace Facade7Demo; 2 | 3 | public class Student(string name) 4 | { 5 | public string Name { get; set; } = name; 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade7Demo/Subsystem Classes/Bank.cs: -------------------------------------------------------------------------------- 1 | namespace Facade7Demo.Subsystem_Classes; 2 | 3 | public class Bank 4 | { 5 | public bool HasSufficientSavings(Student stud, int amount) 6 | { 7 | 8 | Console.WriteLine("Verify bank for "+stud.Name); 9 | return true; 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade7Demo/Subsystem Classes/Credit.cs: -------------------------------------------------------------------------------- 1 | namespace Facade7Demo.Subsystem_Classes; 2 | 3 | public class Credit 4 | { 5 | public bool HasGoodCredit(Student stud) 6 | { 7 | 8 | Console.WriteLine($"Verify credit for {stud.Name}"); 9 | return true; 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade7Demo/Subsystem Classes/Loan.cs: -------------------------------------------------------------------------------- 1 | namespace Facade7Demo.Subsystem_Classes; 2 | 3 | public class Loan 4 | { 5 | public bool HasNoBadLoans(Student stud) 6 | { 7 | 8 | Console.WriteLine($"Verify loan for {stud.Name}"); 9 | return true; 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade8Demo/Account.cs: -------------------------------------------------------------------------------- 1 | namespace Facade8Demo; 2 | 3 | internal record Account(int Id, string Name); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade8Demo/AccountCategory.cs: -------------------------------------------------------------------------------- 1 | namespace Facade8Demo; 2 | 3 | internal enum AccountCategory 4 | { 5 | Buyer = 1, 6 | Reseller = 2 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade8Demo/Facade8Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade8Demo/Product.cs: -------------------------------------------------------------------------------- 1 | namespace Facade8Demo; 2 | 3 | internal record Product(string Name, double Price); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Facade/Facade8Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Facade8Demo; 2 | 3 | var facade = new ProductsFacade(); 4 | 5 | foreach (Product? product in facade.GetProductListForAccount("John Smith")) 6 | { 7 | Console.WriteLine($"Product name: {product.Name}"); 8 | Console.WriteLine($"Product price: {product.Price}"); 9 | } 10 | 11 | Console.ReadKey(); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight1Demo/1_Flyweight Interface/Flyweight.cs: -------------------------------------------------------------------------------- 1 | namespace Flyweight1Demo._1_Flyweight_Interface; 2 | 3 | public interface IFlyweight 4 | { 5 | void StatefulOperation(object o); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight1Demo/2_ Concrete Flyweight/ConcreteFlyweight.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Flyweight1Demo._1_Flyweight_Interface; 3 | 4 | namespace Flyweight1Demo._2__Concrete_Flyweight; 5 | 6 | internal class ConcreteFlyweight:IFlyweight 7 | { 8 | public void StatefulOperation(object o) 9 | { 10 | Console.WriteLine(o); 11 | } 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight1Demo/2_ Concrete Flyweight/UnsharedFlyweight.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Flyweight1Demo._1_Flyweight_Interface; 3 | 4 | namespace Flyweight1Demo._2__Concrete_Flyweight; 5 | 6 | public class UnsharedFlyweight:IFlyweight 7 | { 8 | private object _state; 9 | public void StatefulOperation(object o) 10 | { 11 | _state = o; 12 | Console.WriteLine(o); 13 | } 14 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight1Demo/Flyweight1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight1Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Flyweight1Demo; 4 | 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight2Demo/1_Flyweight Interface/IShape.cs: -------------------------------------------------------------------------------- 1 | namespace Flyweight2Demo._1_Flyweight_Interface; 2 | 3 | /// 4 | /// the flyweight interface 5 | /// 6 | public interface IShape 7 | { 8 | void Print(); 9 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight2Demo/2_ Concrete Flyweight/Circle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Flyweight2Demo._1_Flyweight_Interface; 3 | 4 | namespace Flyweight2Demo._2__Concrete_Flyweight; 5 | 6 | /// 7 | /// ConcreteFlyweight class 8 | /// 9 | internal class Circle:IShape 10 | { 11 | public void Print() 12 | { 13 | Console.WriteLine("Printing Circle"); 14 | } 15 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight2Demo/2_ Concrete Flyweight/Rectangle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Flyweight2Demo._1_Flyweight_Interface; 3 | 4 | namespace Flyweight2Demo._2__Concrete_Flyweight; 5 | 6 | /// 7 | /// ConcreteFlyweight class 8 | /// 9 | internal class Rectangle:IShape 10 | { 11 | public void Print() 12 | { 13 | Console.WriteLine("Printing Rectangle"); 14 | } 15 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight2Demo/Flyweight2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight3Demo/Flyweight3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight4Demo/1_Flyweight Abastract_Interface/Flyweight.cs: -------------------------------------------------------------------------------- 1 | namespace Flyweight4Demo._1_Flyweight_Abastract_Interface; 2 | public abstract class Flyweight 3 | { 4 | public abstract void Draw(string coordinates, string vector, string speed); 5 | } 6 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight4Demo/4.UnsharedConcreteFlyweight-Optional/unshared.md: -------------------------------------------------------------------------------- 1 | # In some cases, if there are flyweight objects that cannot be shared because their state cannot be externalized completely, you would implement an UnsharedConcreteFlyweight. In our game example, we don't have such a case since all Particle objects can be shared. -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight4Demo/Flyweight4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/Flyweight5Demo/Flyweight5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Flyweight/FlyweightFactory.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karwanessmat/CSharpDesignPatterns/fdf4a5a33a4d11cb0e2f836b4795797b7d0f0e4a/2_Structural Design Patterns/Flyweight/FlyweightFactory.txt -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy1Demo/1. Subject Interface/ISubject.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy1Demo._1._Subject_Interface; 2 | 3 | // The Subject interface declares common operations for both RealSubject and 4 | // the Proxy. As long as the client works with RealSubject using this 5 | // interface, you'll be able to pass it a proxy instead of a real subject. 6 | public interface ISubject 7 | { 8 | void Request(); 9 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy1Demo/Proxy1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy2Demo/1. Subject Interface/IPrice.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy2Demo._1._Subject_Interface; 2 | 3 | public interface IPrice 4 | { 5 | int GetPrice(); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy2Demo/2.RealSubject/GoldPrice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Proxy2Demo._1._Subject_Interface; 3 | 4 | namespace Proxy2Demo._2.RealSubject; 5 | 6 | public class GoldPrice:IPrice 7 | { 8 | public int GetPrice() 9 | { 10 | var rand = new Random(); 11 | return rand.Next(1, 99); 12 | } 13 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy2Demo/Proxy2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy3Demo/1. Subject Interface/IMath.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy3Demo._1._Subject_Interface; 2 | 3 | /// 4 | /// The 'Subject interface 5 | /// 6 | public interface IMath 7 | { 8 | double Add(double x, double y); 9 | double Sub(double x, double y); 10 | double Mul(double x, double y); 11 | double Div(double x, double y); 12 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy3Demo/Proxy3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy4Demo/1. Subject Interface/IServer.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy4Demo._1._Subject_Interface; 2 | 3 | /// 4 | /// The Subject interface which both the RealSubject and proxy will need to implement 5 | /// 6 | public interface IServer 7 | { 8 | void TakeOrder(string order); 9 | string DeliverOrder(); 10 | void ProcessPayment(string payment); 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy4Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Proxy4Demo._3.Proxy; 2 | using System; 3 | 4 | var proxy = new NewServerProxy(); 5 | 6 | proxy.TakeOrder("121"); 7 | Console.ReadLine(); -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy4Demo/Proxy4Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy5Demo/1. Subject Interface/IDocument.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy5Demo._1._Subject_Interface; 2 | public interface IDocument 3 | { 4 | string GetContent(); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy5Demo/2.RealSubject/SensitiveDocument.cs: -------------------------------------------------------------------------------- 1 | using Proxy5Demo._1._Subject_Interface; 2 | 3 | namespace Proxy5Demo._2.RealSubject; 4 | 5 | public class SensitiveDocument(string content) : IDocument 6 | { 7 | public string GetContent() 8 | { 9 | return content; 10 | } 11 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy5Demo/Proxy5Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy6Demo/1. Subject Interface/ISharedFolder.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy6Demo._1._Subject_Interface; 2 | 3 | public interface ISharedFolder 4 | { 5 | void PerformReadWriteOperations(); 6 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy6Demo/Employee.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy6Demo; 2 | 3 | public class Employee(string username, string password, string role) 4 | { 5 | public string Username { get; set; } = username; 6 | public string Password { get; set; } = password; 7 | public string Role { get; set; } = role; 8 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy6Demo/Proxy6Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy7Demo/1.Subject Interface/IImage.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy7Demo._1.Subject_Interface; 2 | 3 | public interface IImage 4 | { 5 | string FileName { get; } 6 | 7 | void ShowImage(); 8 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy7Demo/Proxy7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy8Demo/1.Subject Interface/IDataService.cs: -------------------------------------------------------------------------------- 1 | namespace Proxy8Demo._1.Subject_Interface; 2 | 3 | internal interface IDataService 4 | { 5 | Task> GetData(); 6 | void InsertData(string item); 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy8Demo/Proxy8Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy9Demo/1.Subject Interface/IUserRepository.cs: -------------------------------------------------------------------------------- 1 | // Define the common interface for RealSubject and Proxy to ensure interchangeability 2 | namespace Proxy9Demo._1.Subject_Interface; 3 | 4 | public interface IUserRepository 5 | { 6 | string GetData(); 7 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy9Demo/2.RealSubject/UserRepository.cs: -------------------------------------------------------------------------------- 1 | // RealSubject class 2 | 3 | using Proxy9Demo._1.Subject_Interface; 4 | 5 | namespace Proxy9Demo._2.RealSubject; 6 | 7 | public class UserRepository : IUserRepository 8 | { 9 | public string GetData() 10 | { 11 | // Simulate fetching sensitive data 12 | return "Sensitive user data"; 13 | } 14 | } -------------------------------------------------------------------------------- /2_Structural Design Patterns/Proxy/Proxy9Demo/Proxy9Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility0Demo/Step1-Interface/IHandler.cs: -------------------------------------------------------------------------------- 1 | namespace ChainOfResponsibility0Demo.Step1_Interface; 2 | 3 | public interface IHandler 4 | { 5 | IHandler SetNext(IHandler handler); 6 | void HandleRequest(string request); 7 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility1Demo/ChainOfResponsibility1Demo - Backup.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility1Demo/ChainOfResponsibility1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility1Demo/Step1-Interface/ChainHandler.cs: -------------------------------------------------------------------------------- 1 | namespace ChainOfResponsibility1Demo.Step1_Interface; 2 | 3 | public abstract class ChainHandler 4 | { 5 | public ChainHandler Successor; 6 | public void SetSuccessor(ChainHandler successor) 7 | { 8 | Successor = successor; 9 | } 10 | public abstract void HandlerRequest(int request); 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility2Demo/ChainOfResponsibility2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility2Demo/Step1-Interface/IHandler.cs: -------------------------------------------------------------------------------- 1 | namespace ChainOfResponsibility2Demo.Step1_Interface; 2 | 3 | // The Handler interface declares a method for building the chain of 4 | // handlers. It also declares a method for executing a request. 5 | public interface IHandler 6 | { 7 | IHandler SetNext(IHandler handler); 8 | object Handle(object request); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility3Demo/ChainOfResponsibility3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility3Demo/ContextObject.cs: -------------------------------------------------------------------------------- 1 | namespace ChainOfResponsibility3Demo; 2 | 3 | public class ContextObject 4 | { 5 | public string Question { get; set; } 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility4Demo/ChainOfResponsibility4Demo - Backup.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility4Demo/Step1-Interface/Approver.cs: -------------------------------------------------------------------------------- 1 | namespace ChainOfResponsibility4Demo.Step1_Interface; 2 | 3 | /// 4 | /// The 'Handler' abstract class 5 | /// 6 | public abstract class Approver(Approver successor) 7 | { 8 | protected Approver Successor = successor; 9 | 10 | 11 | public abstract void ProcessRequest(Purchase purchase); 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility5Demo/ChainOfResponsibility5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility6Demo/Request.cs: -------------------------------------------------------------------------------- 1 | namespace ChainOfResponsibility6Demo; 2 | 3 | internal class Request 4 | { 5 | public string? Username { get; set; } 6 | public string? Password { get; set; } 7 | public string? Role { get; set; } 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/ChainOfResponsibility/ChainOfResponsibility6Demo/Response.cs: -------------------------------------------------------------------------------- 1 | namespace ChainOfResponsibility6Demo; 2 | 3 | internal class Response(bool success, string message) 4 | { 5 | public bool Success { get; } = success; 6 | public string? Message { get; } = message; 7 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command00Demo/1.Command Interface/Command.cs: -------------------------------------------------------------------------------- 1 | using Command00Demo._3.Receiver; 2 | 3 | namespace Command00Demo._1.Command_Interface; 4 | 5 | internal abstract class Command(DataReceiver receiver) : ICommand 6 | { 7 | protected DataReceiver Receiver = receiver; 8 | 9 | public abstract void Execute(); 10 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command00Demo/1.Command Interface/ICommand.cs: -------------------------------------------------------------------------------- 1 | namespace Command00Demo._1.Command_Interface; 2 | 3 | internal interface ICommand 4 | { 5 | void Execute(); 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command00Demo/2.Concrete Commands/DeleteCommand.cs: -------------------------------------------------------------------------------- 1 | using Command00Demo._1.Command_Interface; 2 | using Command00Demo._3.Receiver; 3 | 4 | namespace Command00Demo._2.Concrete_Commands; 5 | 6 | internal class DeleteCommand(string key,DataReceiver receiver) : Command(receiver) 7 | { 8 | public override void Execute() 9 | { 10 | Receiver.Delete(key); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command00Demo/Command00Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command0Demo/1.Command Interface/ICommand.cs: -------------------------------------------------------------------------------- 1 | namespace Command0Demo._1.Command_Interface; 2 | 3 | public interface ICommand 4 | { 5 | void Execute(); 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command0Demo/2.Concrete Commands/DeleteCommand.cs: -------------------------------------------------------------------------------- 1 | using Command0Demo._1.Command_Interface; 2 | 3 | namespace Command0Demo._2.Concrete_Commands; 4 | 5 | public class DeleteCommand : ICommand 6 | { 7 | public void Execute() 8 | { 9 | Console.WriteLine("Delete command"); 10 | } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command0Demo/2.Concrete Commands/OpenCommand.cs: -------------------------------------------------------------------------------- 1 | using Command0Demo._1.Command_Interface; 2 | 3 | namespace Command0Demo._2.Concrete_Commands; 4 | 5 | public class OpenCommand:ICommand 6 | { 7 | public void Execute() 8 | { 9 | Console.WriteLine("Open command"); 10 | } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command0Demo/2.Concrete Commands/SaveCommand.cs: -------------------------------------------------------------------------------- 1 | using Command0Demo._1.Command_Interface; 2 | 3 | namespace Command0Demo._2.Concrete_Commands; 4 | 5 | internal class SaveCommand : ICommand 6 | { 7 | public void Execute() 8 | { 9 | // logic 10 | Console.WriteLine("Save command"); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command0Demo/3.Receiver/CoolButton.cs: -------------------------------------------------------------------------------- 1 | using Command0Demo._1.Command_Interface; 2 | 3 | namespace Command0Demo._3.Receiver; 4 | 5 | public class CoolButton(ICommand command) 6 | { 7 | 8 | public string Text { get; set; } 9 | public string Name { get; set; } 10 | 11 | public void Click() 12 | { 13 | command.Execute(); 14 | } 15 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command1Demo/1.Command Interface/ICommand .cs: -------------------------------------------------------------------------------- 1 | namespace Command1Demo._1.Command_Interface; 2 | 3 | public interface ICommand 4 | { 5 | void ExecuteAction(); 6 | void UndoAction(); 7 | 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command1Demo/Command1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command1Demo/PriceAction.cs: -------------------------------------------------------------------------------- 1 | namespace Command1Demo; 2 | 3 | public enum PriceAction 4 | { 5 | Increase, 6 | Decrease 7 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command2Demo/1.Command Interface/IOrder .cs: -------------------------------------------------------------------------------- 1 | namespace Command2Demo._1.Command_Interface; 2 | 3 | public interface IOrder 4 | { 5 | void Execute(int value); 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command2Demo/2.Concrete Commands/SellStock.cs: -------------------------------------------------------------------------------- 1 | using Command2Demo._1.Command_Interface; 2 | using Command2Demo._3.Receiver; 3 | 4 | namespace Command2Demo._2.Concrete_Commands; 5 | 6 | public class SellStock(Stock stock) : IOrder 7 | { 8 | public void Execute(int value) 9 | { 10 | stock.Sell(value); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command2Demo/Command2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command3Demo/1.Command Interface/Command.cs: -------------------------------------------------------------------------------- 1 | using Command3Demo._3.Receiver; 2 | 3 | namespace Command3Demo._1.Command_Interface; 4 | 5 | public abstract class Command(SimpleCalculator receiver) 6 | { 7 | protected SimpleCalculator Receiver = receiver; 8 | 9 | public abstract int Execute(); 10 | } 11 | 12 | public enum CommandOption 13 | { 14 | Add, Subtract, Multiply, Divide 15 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command3Demo/Command3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command4Demo/1.Command Interface/ICommand.cs: -------------------------------------------------------------------------------- 1 | namespace Command4Demo._1.Command_Interface; 2 | 3 | public interface ICommand 4 | { 5 | void Execute(); 6 | bool CanExecute(); 7 | void Undo(); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command4Demo/3.Receiver/Repositories/IProductRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Command4Demo._3.Receiver.Repositories; 2 | 3 | public interface IProductRepository 4 | { 5 | Product? FindBy(string articleId); 6 | int GetStockFor(string articleId); 7 | IEnumerable All(); 8 | void DecreaseStockBy(string articleId, int amount); 9 | void IncreaseStockBy(string articleId, int amount); 10 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command4Demo/Command4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command4Demo/Operation.cs: -------------------------------------------------------------------------------- 1 | namespace Command4Demo; 2 | 3 | 4 | public enum Operation 5 | { 6 | Increase, 7 | Decrease 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Command/Command4Demo/Product.cs: -------------------------------------------------------------------------------- 1 | namespace Command4Demo; 2 | 3 | public class Product(string articleId, string name, decimal price) 4 | { 5 | public string ArticleId { get; set; } = articleId; 6 | public string Name { get; set; } = name; 7 | public decimal Price { get; set; } = price; 8 | } 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator00Demo/Iterator00Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator00Demo/Node.cs: -------------------------------------------------------------------------------- 1 | namespace Iterator00Demo; 2 | 3 | internal class Node 4 | { 5 | public Node(int value) 6 | { 7 | Value = value; 8 | } 9 | 10 | public int Value { get; set; } 11 | public Node Left { get; set; } 12 | public Node Right { get; set; } 13 | public Node Parent { get; set; } 14 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator00Demo/Step1-Iterator Interface/IIterator.cs: -------------------------------------------------------------------------------- 1 | namespace Iterator00Demo.Step1_Iterator_Interface; 2 | 3 | internal interface IIterator 4 | { 5 | bool MoveNext(); 6 | int GetCurrent(); 7 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator00Demo/Step3-Collection Interface/IAggregate.cs: -------------------------------------------------------------------------------- 1 | using Iterator00Demo.Step1_Iterator_Interface; 2 | 3 | namespace Iterator00Demo.Step3_Collection_Interface; 4 | 5 | internal interface IAggregate 6 | { 7 | IIterator CreateIterator(); 8 | void Insert(int value); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator0Demo/Iterator0Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator0Demo/Step1-Iterator Interface/IIterator.cs: -------------------------------------------------------------------------------- 1 | namespace Iterator0Demo.Step1_Iterator_Interface; 2 | 3 | public interface IIterator 4 | { 5 | bool HasNext(); 6 | object? Next(); 7 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator0Demo/Step3-Collection Interface/IAggregate.cs: -------------------------------------------------------------------------------- 1 | using Iterator0Demo.Step1_Iterator_Interface; 2 | 3 | namespace Iterator0Demo.Step3_Collection_Interface; 4 | 5 | internal interface IAggregate 6 | { 7 | IIterator CreateIterator(); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator1Demo/Iterator1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator1Demo/Step3-Collection Interface/Aggregate.cs: -------------------------------------------------------------------------------- 1 | using Iterator1Demo.Step1_Iterator_Interface; 2 | 3 | namespace Iterator1Demo.Step3_Collection_Interface; 4 | 5 | /// 6 | /// The 'Aggregate' abstract class 7 | /// 8 | internal abstract class Aggregate 9 | { 10 | public abstract Iterator CreateIterator(); 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator2Demo/Item.cs: -------------------------------------------------------------------------------- 1 | namespace Iterator2Demo; 2 | 3 | public class Item(string name) 4 | { 5 | // Constructor 6 | 7 | // Gets name 8 | public string Name { get; } = name; 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator2Demo/Iterator2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator2Demo/Step1-Iterator Interface/IAbstractIterator.cs: -------------------------------------------------------------------------------- 1 | namespace Iterator2Demo.Step1_Iterator_Interface; 2 | 3 | /// 4 | /// The 'Iterator' interface 5 | /// 6 | internal interface IAbstractIterator 7 | 8 | { 9 | Item First(); 10 | Item Next(); 11 | bool IsDone { get; } 12 | Item CurrentItem { get; } 13 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator2Demo/Step3-Collection Interface/IAbstractCollection.cs: -------------------------------------------------------------------------------- 1 | using Iterator2Demo.Step2_Concrete_Iterator; 2 | 3 | namespace Iterator2Demo.Step3_Collection_Interface; 4 | 5 | /// 6 | /// The 'Aggregate' interface 7 | /// 8 | internal interface IAbstractCollection 9 | 10 | { 11 | Iterator CreateIterator(); 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator3Demo/Employee.cs: -------------------------------------------------------------------------------- 1 | namespace Iterator3Demo; 2 | 3 | public class Employee(string name, int id) 4 | { 5 | public int Id { get; set; } = id; 6 | public string Name { get; set; } = name; 7 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator3Demo/Iterator3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator3Demo/Step1-Iterator Interface/AbstractIterator.cs: -------------------------------------------------------------------------------- 1 | namespace Iterator3Demo.Step1_Iterator_Interface 2 | { 3 | namespace IteratorDesignPattern 4 | { 5 | public interface IAbstractIterator 6 | { 7 | Employee First(); 8 | Employee Next(); 9 | bool IsCompleted { get; } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator3Demo/Step3-Collection Interface/AbstractCollection.cs: -------------------------------------------------------------------------------- 1 | using Iterator3Demo.Step1_Iterator_Interface.IteratorDesignPattern; 2 | 3 | namespace Iterator3Demo.Step3_Collection_Interface; 4 | 5 | public interface IAbstractCollection 6 | { 7 | IAbstractIterator CreateIterator(); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator4Demo/Iterator4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Iterator/Iterator4Demo/Step3-Collection Interface/INewspaper.cs: -------------------------------------------------------------------------------- 1 | using Iterator4Demo.Step1_Iterator_Interface; 2 | 3 | namespace Iterator4Demo.Step3_Collection_Interface; 4 | 5 | // Aggregate 6 | public interface INewspaper 7 | { 8 | IIterator CreateIterator(); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator0Demo/01_DefineMediatorInterface/IMediator.cs: -------------------------------------------------------------------------------- 1 | namespace Mediator0Demo._01_DefineMediatorInterface; 2 | public interface IMediator 3 | { 4 | void Notify(object sender, string eventMessage); 5 | } 6 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator0Demo/03_DefineComponentBaseClass/BaseComponent.cs: -------------------------------------------------------------------------------- 1 | using Mediator0Demo._01_DefineMediatorInterface; 2 | 3 | namespace Mediator0Demo._03_DefineComponentBaseClass; 4 | public abstract class BaseComponent(IMediator mediator) 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator10Demo/01_DefineMediatorInterface/IMediator.cs: -------------------------------------------------------------------------------- 1 | namespace Mediator10Demo._01_DefineMediatorInterface; 2 | 3 | public interface IMediator 4 | { 5 | void Notify(object sender, string eventMessage); 6 | } 7 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator10Demo/03_DefineComponentBaseClass/SmartDevice.cs: -------------------------------------------------------------------------------- 1 | using Mediator10Demo._01_DefineMediatorInterface; 2 | 3 | namespace Mediator10Demo._03_DefineComponentBaseClass; 4 | 5 | public abstract class SmartDevice(IMediator mediator) 6 | { 7 | protected IMediator Mediator = mediator; 8 | } 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator10Demo/Mediator10Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator11Demo/01_DefineMediatorInterface/IChatRoomMediator.cs: -------------------------------------------------------------------------------- 1 | using Mediator11Demo._03_DefineComponentBaseClass; 2 | 3 | namespace Mediator11Demo._01_DefineMediatorInterface; 4 | 5 | public interface IChatRoomMediator 6 | { 7 | void RegisterUser(User user); 8 | void SendMessage(string message, string sender, string receiver); 9 | } 10 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator11Demo/Mediator11Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator1Demo/01_DefineMediatorInterface/Mediator.cs: -------------------------------------------------------------------------------- 1 | using Mediator1Demo._03_DefineComponentBaseClass; 2 | 3 | namespace Mediator1Demo._01_DefineMediatorInterface; 4 | 5 | /// 6 | /// The 'Mediator' abstract class 7 | /// 8 | public abstract class Mediator 9 | { 10 | public abstract void Send(string message, Colleague colleague); 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator1Demo/03_DefineComponentBaseClass/Colleague.cs: -------------------------------------------------------------------------------- 1 | using Mediator1Demo._01_DefineMediatorInterface; 2 | 3 | namespace Mediator1Demo._03_DefineComponentBaseClass; 4 | 5 | /// 6 | /// The 'Colleague' abstract class 7 | /// 8 | public abstract class Colleague(Mediator mediator) 9 | { 10 | public Mediator Mediator { get; } = mediator; 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator1Demo/Mediator1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator2Demo/Mediator2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator3Demo/01_DefineMediatorInterface/IMediator.cs: -------------------------------------------------------------------------------- 1 | using Mediator3Demo._03_DefineComponentBaseClass; 2 | 3 | namespace Mediator3Demo._01_DefineMediatorInterface; 4 | 5 | public interface IMediator 6 | { 7 | void Notify(Control sender, string @event); 8 | } 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator3Demo/03_DefineComponentBaseClass/Control.cs: -------------------------------------------------------------------------------- 1 | using Mediator3Demo._01_DefineMediatorInterface; 2 | 3 | namespace Mediator3Demo._03_DefineComponentBaseClass; 4 | 5 | public abstract class Control(IMediator mediator) 6 | { 7 | protected IMediator Mediator = mediator; 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator4Demo/01_DefineMediatorInterface/IMediator.cs: -------------------------------------------------------------------------------- 1 | using Mediator4Demo._03_DefineComponentBaseClass; 2 | 3 | namespace Mediator4Demo._01_DefineMediatorInterface; 4 | 5 | public abstract class Mediator 6 | { 7 | public abstract void Send(string message,Colleague colleague); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator4Demo/04_CreateConcreteComponents/Colleague2.cs: -------------------------------------------------------------------------------- 1 | using Mediator4Demo._03_DefineComponentBaseClass; 2 | 3 | namespace Mediator4Demo._04_CreateConcreteComponents; 4 | 5 | public class Colleague2:Colleague 6 | { 7 | public override void HandleNotification(string message) 8 | { 9 | Console.WriteLine($"Colleague2 receives notification message: {message}"); 10 | } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator6Demo/01_DefineMediatorInterface/IWindow.cs: -------------------------------------------------------------------------------- 1 | using Mediator6Demo._03_DefineComponentBaseClass; 2 | 3 | namespace Mediator6Demo._01_DefineMediatorInterface; 4 | 5 | public interface IWindow 6 | { 7 | void Changed(Control control); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator6Demo/03_DefineComponentBaseClass/Control.cs: -------------------------------------------------------------------------------- 1 | using Mediator6Demo._01_DefineMediatorInterface; 2 | 3 | namespace Mediator6Demo._03_DefineComponentBaseClass; 4 | 5 | public class Control(IWindow owner) 6 | { 7 | protected IWindow owner = owner; 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator6Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Mediator6Demo._02_CreateConcreteMediator; 2 | 3 | var window = new OptionsWindow(); 4 | window.Test(); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator7Demo/01_DefineMediatorInterface/IMediator.cs: -------------------------------------------------------------------------------- 1 | using Mediator7Demo._03_DefineComponentBaseClass; 2 | 3 | namespace Mediator7Demo._01_DefineMediatorInterface; 4 | 5 | internal interface IMediator 6 | { 7 | void Register(string key, IParticipant participant); 8 | void SendCommand(string receiver, string sender, string command); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator7Demo/03_DefineComponentBaseClass/IParticipant.cs: -------------------------------------------------------------------------------- 1 | namespace Mediator7Demo._03_DefineComponentBaseClass; 2 | 3 | internal interface IParticipant 4 | { 5 | void SendCommand(string receiver, string command); 6 | void ReceiveCommand(string sender, string command); 7 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator7Demo/Mediator7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator8Demo/01_DefineMediatorInterface/IMediator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Mediator8Demo._01_DefineMediatorInterface; 8 | 9 | public interface IMediator 10 | { 11 | void Notify(object sender, string event_); 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator8Demo/04_CreateConcreteComponents/Button.cs: -------------------------------------------------------------------------------- 1 | using Mediator8Demo._01_DefineMediatorInterface; 2 | using Mediator8Demo._03_DefineComponentBaseClass; 3 | 4 | namespace Mediator8Demo._04_CreateConcreteComponents; 5 | 6 | public class Button(IMediator mediator) : Component(mediator) 7 | { 8 | public bool IsEnabled { get; set; } 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator8Demo/Mediator8Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator9Demo/01_DefineMediatorInterface/IMediator.cs: -------------------------------------------------------------------------------- 1 | namespace Mediator9Demo._01_DefineMediatorInterface; 2 | 3 | public interface ISmartHomeMediator 4 | { 5 | void Notify(string sender, string eventMessage); 6 | } 7 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator9Demo/03_DefineComponentBaseClass/Component.cs: -------------------------------------------------------------------------------- 1 | using Mediator9Demo._01_DefineMediatorInterface; 2 | 3 | namespace Mediator9Demo._03_DefineComponentBaseClass; 4 | 5 | public abstract class SmartDevice 6 | { 7 | protected ISmartHomeMediator Mediator; 8 | 9 | public SmartDevice(ISmartHomeMediator mediator) 10 | { 11 | Mediator = mediator; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/MediatoR/Mediator9Demo/Mediator9Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net9.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento0Demo/Memento0Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento0Demo/Step1- Create the Memento class/Memento.cs: -------------------------------------------------------------------------------- 1 | namespace Memento0Demo.Step1__Create_the_Memento_class; 2 | 3 | // Memento class 4 | public class Memento(string? state) 5 | { 6 | public string? GetState() 7 | { 8 | return state; 9 | } 10 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento1Demo/Memento1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento1Demo/Step1- Create the Memento class/Memento.cs: -------------------------------------------------------------------------------- 1 | namespace Memento1Demo.Step1__Create_the_Memento_class; 2 | 3 | public class Memento 4 | { 5 | private int _state; 6 | 7 | public int GetState() 8 | { 9 | return _state; 10 | } 11 | 12 | public void SetState(int state) 13 | { 14 | _state = state; 15 | } 16 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento2Demo/Memento2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento3Demo/Memento3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento4Demo/Memento4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento5Demo/Memento5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento5Demo/Step1- Create the Memento class/EditorMemento.cs: -------------------------------------------------------------------------------- 1 | namespace Memento5Demo.Step1__Create_the_Memento_class; 2 | 3 | public class EditorMemento(string content) 4 | { 5 | 6 | 7 | public string GetContent() // Accessor to get the state 8 | { 9 | return content; 10 | } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento6Demo/Memento6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Memento/Memento6Demo/Step1- Create the Memento class/EditorState.cs: -------------------------------------------------------------------------------- 1 | namespace Memento6Demo.Step1__Create_the_Memento_class; 2 | 3 | public class EditorState( 4 | string text, 5 | string font, 6 | int fontSize) 7 | { 8 | public readonly string Text = text; 9 | public readonly string Font = font; 10 | public readonly int FontSize = fontSize; 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer0Demo/Observer0Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer0Demo/Step1-Define Observer Interface/IObserver.cs: -------------------------------------------------------------------------------- 1 | using Observer0Demo.Step2_Define_Subject_Interface; 2 | 3 | namespace Observer0Demo.Step1_Define_Observer_Interface; 4 | 5 | internal interface IObserver 6 | { 7 | void Update(ISubject subject, string message); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer0Demo/Step2-Define Subject Interface/ISubject.cs: -------------------------------------------------------------------------------- 1 | using Observer0Demo.Step1_Define_Observer_Interface; 2 | 3 | namespace Observer0Demo.Step2_Define_Subject_Interface; 4 | 5 | internal interface ISubject 6 | { 7 | string Name { get; } 8 | void Subscribe(IObserver observer); 9 | void Unsubscribe(IObserver observer); 10 | void Notify(string message); 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer1Demo/Observer1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer1Demo/Step1-Define Observer Interface/Observer.cs: -------------------------------------------------------------------------------- 1 | namespace Observer1Demo.Step1_Define_Observer_Interface; 2 | 3 | /// 4 | /// 1. Define the Observer Interface: This interface allows the Subject to communicate with its observers when its state changes. 5 | /// 6 | public abstract class Observer 7 | { 8 | public abstract void Update(); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer2Demo/Observer2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer2Demo/Step1-Define Observer Interface/IInvestor.cs: -------------------------------------------------------------------------------- 1 | using Observer2Demo.Step2_Define_Subject_Interface; 2 | 3 | namespace Observer2Demo.Step1_Define_Observer_Interface; 4 | 5 | public interface IInvestor 6 | { 7 | void Update(Stock stock); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer2Demo/Step3-Implement Concrete Subject/IBM.cs: -------------------------------------------------------------------------------- 1 |  2 | using Observer2Demo.Step2_Define_Subject_Interface; 3 | 4 | namespace Observer2Demo.Step3_Implement_Concrete_Subject; 5 | 6 | public class Ibm(string symbol, double price) : Stock(symbol, price); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer3Demo/Observer3Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer3Demo/Step1-Define Observer Interface/IObserver.cs: -------------------------------------------------------------------------------- 1 | namespace Observer3Demo.Step1_Define_Observer_Interface; 2 | 3 | public interface IObserver 4 | { 5 | void Update(string availability); 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer3Demo/Step2-Define Subject Interface/ISubject.cs: -------------------------------------------------------------------------------- 1 | using Observer3Demo.Step1_Define_Observer_Interface; 2 | 3 | namespace Observer3Demo.Step2_Define_Subject_Interface; 4 | 5 | public interface ISubject 6 | { 7 | void RegisterObserver(IObserver observer); 8 | void RemoveObserver(IObserver observer); 9 | void NotifyObserver(); 10 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer4Demo/Observer4Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer4Demo/Step1-Define Observer Interface/IRestaurant.cs: -------------------------------------------------------------------------------- 1 | using Observer4Demo.Step2_Define_Subject_Interface; 2 | 3 | namespace Observer4Demo.Step1_Define_Observer_Interface; 4 | 5 | public interface IRestaurant 6 | { 7 | void Update(Vegetable vegetable); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer4Demo/Step3-Implement Concrete Subject/Carrots.cs: -------------------------------------------------------------------------------- 1 | using Observer4Demo.Step2_Define_Subject_Interface; 2 | 3 | namespace Observer4Demo.Step3_Implement_Concrete_Subject; 4 | 5 | public class Carrots(double pricePerProduct) : Vegetable(pricePerProduct); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer5Demo/Observer5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer5Demo/Step1-Define Observer Interface/IFan.cs: -------------------------------------------------------------------------------- 1 | using Observer5Demo.Step2_Define_Subject_Interface; 2 | 3 | namespace Observer5Demo.Step1_Define_Observer_Interface; 4 | 5 | public interface IFan 6 | { 7 | void Update(ICelebrity celebrity); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer5Demo/Step2-Define Subject Interface/ICelebrity.cs: -------------------------------------------------------------------------------- 1 | using Observer5Demo.Step1_Define_Observer_Interface; 2 | 3 | namespace Observer5Demo.Step2_Define_Subject_Interface; 4 | 5 | public interface ICelebrity 6 | { 7 | string FullName { get; } 8 | string Tweet { get; set; } 9 | void Notify(string tweet); 10 | void AddFollower(IFan fan); 11 | void RemoveFollower(IFan fan); 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer6Demo/Observer6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer6Demo/Step1-Define Observer Interface/INotifier.cs: -------------------------------------------------------------------------------- 1 | namespace Observer6Demo.Step1_Define_Observer_Interface; 2 | 3 | public interface INotifier 4 | { 5 | void Notify(Dictionary stockList); 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer7Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Observer7Demo.Step3_Implement_Concrete_Subject; 2 | using Observer7Demo.Step4_Implement_Concrete_Observers; 3 | 4 | var weatherStation = new WeatherStation(); 5 | 6 | var currentDisplay = new CurrentConditionsDisplay(weatherStation); 7 | 8 | weatherStation.Temperature = 70; // All observers are notified 9 | weatherStation.Temperature = 75; -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer7Demo/Step1-Define Observer Interface/IObserver.cs: -------------------------------------------------------------------------------- 1 | namespace Observer7Demo.Step1_Define_Observer_Interface; 2 | 3 | public interface IObserver 4 | { 5 | void Update(); 6 | } 7 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Observer/Observer7Demo/Step2-Define Subject Interface or Abstract/ISubject.cs: -------------------------------------------------------------------------------- 1 | using Observer7Demo.Step1_Define_Observer_Interface; 2 | 3 | namespace Observer7Demo.Step2_Define_Subject_Interface_or_Abstract; 4 | 5 | public interface ISubject 6 | { 7 | void Attach(IObserver observer); 8 | void Detach(IObserver observer); 9 | void Notify(); 10 | } 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State1Demo/1_CreateStateInterface/State.cs: -------------------------------------------------------------------------------- 1 | using State1Demo._3_ContextClass; 2 | 3 | namespace State1Demo._1_CreateStateInterface; 4 | 5 | /// 6 | /// the 'State' abstract class 7 | /// 8 | public abstract class State 9 | { 10 | public abstract void Handler(Context context); 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State1Demo/2_ImplementConcreteStates/ConcreteStateA.cs: -------------------------------------------------------------------------------- 1 | using State1Demo._1_CreateStateInterface; 2 | using State1Demo._3_ContextClass; 3 | 4 | namespace State1Demo._2_ImplementConcreteStates; 5 | 6 | public class ConcreteStateA:State 7 | { 8 | public override void Handler(Context context) 9 | { 10 | context.State = new ConcreteStateB(); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State1Demo/2_ImplementConcreteStates/ConcreteStateB.cs: -------------------------------------------------------------------------------- 1 | using State1Demo._1_CreateStateInterface; 2 | using State1Demo._3_ContextClass; 3 | 4 | namespace State1Demo._2_ImplementConcreteStates; 5 | 6 | public class ConcreteStateB:State 7 | { 8 | public override void Handler(Context context) 9 | { 10 | context.State = new ConcreteStateA(); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State1Demo/State1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State2Demo/Program.cs: -------------------------------------------------------------------------------- 1 | // Open a new account 2 | using State2Demo._3_ContextClass; 3 | using System; 4 | 5 | var account = new Account("Jim Johnson"); 6 | // Apply financial transactions 7 | account.Deposit(500.0); 8 | account.Deposit(300.0); 9 | account.Deposit(550.0); 10 | account.PayInterest(); 11 | account.Withdraw(2000.00); 12 | account.Withdraw(1100.00); 13 | // Wait for user 14 | Console.ReadKey(); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State2Demo/State2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State3Demo/1_CreateStateInterface/IAtmState.cs: -------------------------------------------------------------------------------- 1 | namespace State3Demo._1_CreateStateInterface; 2 | 3 | public interface IAtmState 4 | { 5 | public void InsertCard(); 6 | public void EjectCard(); 7 | public void InsertPin(int pin); 8 | public void RequestCash(int cashToWithdraw); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State3Demo/State3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State4Demo/1_CreateStateInterface/IMobilePhoneState.cs: -------------------------------------------------------------------------------- 1 | namespace State4Demo._1_CreateStateInterface; 2 | 3 | internal interface IMobilePhoneState 4 | { 5 | void PressHomeButton(); 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State4Demo/2_ImplementConcreteStates/LockedScreenState.cs: -------------------------------------------------------------------------------- 1 | using State4Demo._1_CreateStateInterface; 2 | 3 | namespace State4Demo._2_ImplementConcreteStates; 4 | 5 | internal class LockedScreenState : IMobilePhoneState 6 | { 7 | public void PressHomeButton() 8 | { 9 | Console.WriteLine("Please enter screen unlock PIN."); 10 | } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State4Demo/2_ImplementConcreteStates/UnlockedScreenState.cs: -------------------------------------------------------------------------------- 1 | using State4Demo._1_CreateStateInterface; 2 | 3 | namespace State4Demo._2_ImplementConcreteStates; 4 | 5 | internal class UnlockedScreenState : IMobilePhoneState 6 | { 7 | public void PressHomeButton() 8 | { 9 | Console.WriteLine("Home screen has been opened."); 10 | } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State4Demo/State4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State5Demo/1_CreateStateInterface/ITrafficLightState.cs: -------------------------------------------------------------------------------- 1 | using State5Demo._3_ContextClass; 2 | 3 | namespace State5Demo._1_CreateStateInterface; 4 | public interface ITrafficLightState 5 | { 6 | void Handle(TrafficLight context); 7 | } 8 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State5Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using State5Demo._3_ContextClass; 2 | 3 | var trafficLight = new TrafficLight(); 4 | 5 | 6 | // Status is changed 4 times 7 | trafficLight.Change(); 8 | trafficLight.Change(); 9 | trafficLight.Change(); 10 | trafficLight.Change(); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State5Demo/State5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State6Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using State6Demo._2_ImplementConcreteStates; 2 | using State6Demo._3_ContextClass; 3 | 4 | var document = new DocumentContext(new DraftState()); 5 | document.Review(); // Sends for review 6 | document.Approve(); // Approves the document 7 | document.Publish(); // Publishes the document -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State6Demo/State6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State7Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using State7Demo._2_ImplementConcreteStates; 2 | using State7Demo._3_ContextClass; 3 | 4 | var order = new OrderContext(new OrderedState()); 5 | order.Pay(); // Pay for the order 6 | order.Ship(); // Attempt to ship, will transition to ShippedState 7 | order.Deliver(); // Finally, mark the order as delivered -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State7Demo/State7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State8Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using State8Demo._2_ImplementConcreteStates; 2 | using State8Demo._3_ContextClass; 3 | 4 | var player = new VideoPlayerContext(new StoppedState()); 5 | player.Play(); // Starts the video 6 | player.Pause(); // Pauses the video 7 | player.Play(); // Resumes the video 8 | player.Stop(); // Stops the video -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/State/State8Demo/State8Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy1Demo/1_Define_Strategy Interface/Strategy.cs: -------------------------------------------------------------------------------- 1 | namespace Strategy1Demo._1_Define_Strategy_Interface; 2 | 3 | /// 4 | /// The 'Strategy' abstract class 5 | /// 6 | public abstract class Strategy 7 | { 8 | public abstract void AlgorithmInterface(); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy1Demo/2_Concrete_Strategies/ConcreteStrategyA.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Strategy1Demo._1_Define_Strategy_Interface; 3 | 4 | namespace Strategy1Demo._2_Concrete_Strategies; 5 | 6 | class ConcreteStrategyA: Strategy 7 | { 8 | public override void AlgorithmInterface() 9 | { 10 | Console.WriteLine("Called ConcreteStrategyA.AlgorithmInterface"); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy1Demo/3_ContextClass/Context.cs: -------------------------------------------------------------------------------- 1 | using Strategy1Demo._1_Define_Strategy_Interface; 2 | 3 | namespace Strategy1Demo._3_ContextClass; 4 | 5 | public class Context(Strategy strategy) 6 | { 7 | public void ContextInterface() 8 | { 9 | strategy.AlgorithmInterface(); 10 | } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy1Demo/Strategy1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy2Demo/1_Define_Strategy Interface/SortStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Strategy2Demo._1_Define_Strategy_Interface; 4 | 5 | /// 6 | /// The 'Strategy' abstract class 7 | /// 8 | public abstract class SortStrategy 9 | { 10 | public abstract void Sort(List list); 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy2Demo/2_Concrete_Strategies/ShellSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Strategy2Demo._1_Define_Strategy_Interface; 4 | 5 | namespace Strategy2Demo._2_Concrete_Strategies; 6 | 7 | class ShellSort:SortStrategy 8 | { 9 | public override void Sort(List list) 10 | { 11 | Console.WriteLine("Shell Sorted List"); 12 | } 13 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy2Demo/Strategy2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy3Demo/1_Define_Strategy Interface/IPaymentStrategy.cs: -------------------------------------------------------------------------------- 1 | namespace Strategy3Demo._1_Define_Strategy_Interface; 2 | 3 | public interface IPaymentStrategy 4 | { 5 | bool ProcessPayment(double amount); 6 | } 7 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy3Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Strategy3Demo._2_Concrete_Strategies; 2 | using Strategy3Demo._3_ContextClass; 3 | 4 | var pc =new PaymentContext(new CreditCardPaymentStrategy()); 5 | pc.ExecutePayment(200); 6 | 7 | pc.SetPaymentStrategy(new PayPalPaymentStrategy()); 8 | pc.ExecutePayment(300); 9 | 10 | pc.SetPaymentStrategy(new BankTransferPaymentStrategy()); 11 | pc.ExecutePayment(400); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy3Demo/Strategy3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy4Demo/1_Define_Strategy Interface/ICompressionStrategy.cs: -------------------------------------------------------------------------------- 1 | namespace Strategy4Demo._1_Define_Strategy_Interface; 2 | 3 | public interface ICompressionStrategy 4 | { 5 | void CompressFolder(string compressedArchiveFileName); 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy4Demo/Strategy4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy5Demo/1_Define_Strategy Interface/IDiscountStrategy.cs: -------------------------------------------------------------------------------- 1 | namespace Strategy5Demo._1_Define_Strategy_Interface; 2 | public interface IDiscountStrategy 3 | { 4 | double CalculateDiscount(double saleAmount); 5 | } 6 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Strategy/Strategy5Demo/Strategy5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template1Demo/Template1Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template2Demo/Template2Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template3Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Template3Demo.AbstractClass; 2 | using Template3Demo.ConcreteClass; 3 | 4 | DocumentParser dp = new PdfParser(); 5 | dp.ParseDocument(); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template3Demo/Template3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template4Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Template4Demo.AbstractClass; 2 | using Template4Demo.ConcreteClass; 3 | 4 | VehicleAssembly vehicle; 5 | 6 | Console.WriteLine("Assembling a car:"); 7 | vehicle = new CarAssembly(); 8 | vehicle.AssembleVehicle(); 9 | 10 | Console.WriteLine(); 11 | Console.WriteLine("\nAssembling a motorcycle:"); 12 | vehicle = new MotorcycleAssembly(); 13 | vehicle.AssembleVehicle(); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template4Demo/Template4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template5Demo/Template5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template6Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Template6Demo.AbstractClass; 2 | using Template6Demo.ConcreteClass; 3 | 4 | CookieRecipe chocolateChip = new ChocolateChipCookie(); 5 | chocolateChip.MakeCookie(); 6 | 7 | Console.WriteLine(); 8 | 9 | CookieRecipe oatmealRaisin = new OatmealRaisinCookie(); 10 | oatmealRaisin.MakeCookie(); -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template6Demo/Template6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template7Demo/AbstractClass/PanFood.cs: -------------------------------------------------------------------------------- 1 | namespace Template7Demo.AbstractClass; 2 | 3 | public abstract class PanFood 4 | { 5 | public bool RequiresBaking { get; set; } = true; 6 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template7Demo/ColdVeggiePizza.cs: -------------------------------------------------------------------------------- 1 | using Template7Demo.AbstractClass; 2 | 3 | namespace Template7Demo; 4 | 5 | public class ColdVeggiePizza : PanFood 6 | { 7 | public ColdVeggiePizza() 8 | { 9 | RequiresBaking = false; 10 | } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template7Demo/Pie.cs: -------------------------------------------------------------------------------- 1 | using Template7Demo.AbstractClass; 2 | 3 | namespace Template7Demo; 4 | 5 | public class Pie : PanFood { } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template7Demo/Pizza.cs: -------------------------------------------------------------------------------- 1 | using Template7Demo.AbstractClass; 2 | 3 | namespace Template7Demo; 4 | 5 | public class Pizza : PanFood 6 | { 7 | public string CrustType { get; set; } = "no crust"; 8 | public int NumSlices { get; set; } = 1; 9 | public List Toppings { get; private set; } = new List(); 10 | public bool WasBaked { get; set; } 11 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Template/Template7Demo/services/LoggerAdapter.cs: -------------------------------------------------------------------------------- 1 | namespace Template7Demo.services; 2 | 3 | public class LoggerAdapter 4 | { 5 | private readonly List _messages = []; 6 | public void Log(string message) 7 | { 8 | _messages.Add(message); 9 | } 10 | 11 | public string Dump() 12 | { 13 | return string.Join(Environment.NewLine, _messages); 14 | } 15 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor1Demo/1_Visitor Interface/IVisitor.cs: -------------------------------------------------------------------------------- 1 | using Visitor1Demo._4__Implement_Concrete_Elements; 2 | 3 | namespace Visitor1Demo._1_Visitor_Interface; 4 | 5 | public interface IVisitor 6 | { 7 | void VisitCity(City city); 8 | void VisitIndustry(Industry industry); 9 | void VisitSightSeeing(SightSeeing sightSeeing); 10 | } 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor1Demo/3_Define the Element Interface/IElement.cs: -------------------------------------------------------------------------------- 1 | using Visitor1Demo._1_Visitor_Interface; 2 | 3 | namespace Visitor1Demo._3_Define_the_Element_Interface; 4 | public interface IElement 5 | { 6 | void Accept(IVisitor visitor); 7 | } 8 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor1Demo/Visitor1Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor2Demo/1_Visitor Interface/IVisitor.cs: -------------------------------------------------------------------------------- 1 | using Visitor2Demo._4__Implement_Concrete_Elements; 2 | 3 | namespace Visitor2Demo._1_Visitor_Interface; 4 | 5 | public interface IVisitor 6 | { 7 | void VisitConcreteElementA(ConcreteElementA elementA); 8 | void VisitConcreteElementB(ConcreteElementB elementB); 9 | } 10 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor2Demo/3_Define the Element Interface/IElement.cs: -------------------------------------------------------------------------------- 1 | using Visitor2Demo._1_Visitor_Interface; 2 | 3 | namespace Visitor2Demo._3_Define_the_Element_Interface; 4 | public interface IElement 5 | { 6 | void Accept(IVisitor visitor); 7 | } 8 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor2Demo/Visitor2Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor3Demo/1_Visitor Interface/IShapeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Visitor3Demo._4__Implement_Concrete_Elements; 2 | 3 | namespace Visitor3Demo._1_Visitor_Interface; 4 | public interface IShapeVisitor 5 | { 6 | void VisitCircle(Circle circle); 7 | void VisitRectangle(Rectangle rectangle); 8 | void VisitLine(Line line); 9 | } 10 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor3Demo/3_Define the Element Interface/IShapeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Visitor3Demo._1_Visitor_Interface; 2 | 3 | namespace Visitor3Demo._3_Define_the_Element_Interface; 4 | 5 | public interface IShape 6 | { 7 | void Accept(IShapeVisitor visitor); 8 | } 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor3Demo/4_ Implement Concrete Elements/Circle.cs: -------------------------------------------------------------------------------- 1 | using Visitor3Demo._1_Visitor_Interface; 2 | using Visitor3Demo._3_Define_the_Element_Interface; 3 | 4 | namespace Visitor3Demo._4__Implement_Concrete_Elements; 5 | 6 | public class Circle : IShape 7 | { 8 | public void Accept(IShapeVisitor visitor) 9 | { 10 | visitor.VisitCircle(this); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor3Demo/4_ Implement Concrete Elements/Line.cs: -------------------------------------------------------------------------------- 1 | using Visitor3Demo._1_Visitor_Interface; 2 | using Visitor3Demo._3_Define_the_Element_Interface; 3 | 4 | namespace Visitor3Demo._4__Implement_Concrete_Elements; 5 | 6 | public class Line : IShape 7 | { 8 | public void Accept(IShapeVisitor visitor) 9 | { 10 | visitor.VisitLine(this); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor3Demo/4_ Implement Concrete Elements/Rectangle.cs: -------------------------------------------------------------------------------- 1 | using Visitor3Demo._1_Visitor_Interface; 2 | using Visitor3Demo._3_Define_the_Element_Interface; 3 | 4 | namespace Visitor3Demo._4__Implement_Concrete_Elements; 5 | 6 | public class Rectangle : IShape 7 | { 8 | public void Accept(IShapeVisitor visitor) 9 | { 10 | visitor.VisitRectangle(this); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor3Demo/Visitor3Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor4Demo/1_Visitor Interface/IShippingVisitor.cs: -------------------------------------------------------------------------------- 1 | using Visitor4Demo._4__Implement_Concrete_Elements; 2 | 3 | namespace Visitor4Demo._1_Visitor_Interface; 4 | public interface IShippingVisitor 5 | { 6 | double VisitBook(Book book); 7 | double VisitElectronics(Electronics electronics); 8 | double VisitClothing(Clothing clothing); 9 | } 10 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor4Demo/3_Define the Element Interface/IProduct.cs: -------------------------------------------------------------------------------- 1 | using Visitor4Demo._1_Visitor_Interface; 2 | 3 | namespace Visitor4Demo._3_Define_the_Element_Interface; 4 | 5 | public interface IProduct 6 | { 7 | double Accept(IShippingVisitor visitor); 8 | } 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor4Demo/Visitor4Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor5Demo/1_Visitor Interface/IAnimalVisitor.cs: -------------------------------------------------------------------------------- 1 | using Visitor5Demo._4__Implement_Concrete_Elements; 2 | 3 | namespace Visitor5Demo._1_Visitor_Interface; 4 | public interface IAnimalVisitor 5 | { 6 | void VisitDog(Dog dog); 7 | void VisitCat(Cat cat); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor5Demo/3_Define the Element Interface/IAnimal.cs: -------------------------------------------------------------------------------- 1 | using Visitor5Demo._1_Visitor_Interface; 2 | 3 | namespace Visitor5Demo._3_Define_the_Element_Interface; 4 | 5 | public interface IAnimal 6 | { 7 | void Accept(IAnimalVisitor visitor); 8 | } 9 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor5Demo/Visitor5Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor6Demo/1_Visitor Interface/IOperation.cs: -------------------------------------------------------------------------------- 1 | using Visitor6Demo._4__Implement_Concrete_Elements; 2 | 3 | namespace Visitor6Demo._1_Visitor_Interface; 4 | 5 | public interface IOperation 6 | { 7 | void Apply(Button button); 8 | void Apply(TextBox textBox); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor6Demo/3_Define the Element Interface/Control.cs: -------------------------------------------------------------------------------- 1 | using Visitor6Demo._1_Visitor_Interface; 2 | 3 | namespace Visitor6Demo._3_Define_the_Element_Interface; 4 | 5 | public abstract class Control(string name) 6 | { 7 | public string Name { get; set; } = name; 8 | public abstract void Execute(IOperation operation); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor6Demo/4_ Implement Concrete Elements/Button.cs: -------------------------------------------------------------------------------- 1 | using Visitor6Demo._1_Visitor_Interface; 2 | using Visitor6Demo._3_Define_the_Element_Interface; 3 | 4 | namespace Visitor6Demo._4__Implement_Concrete_Elements; 5 | 6 | public class Button(string name) : Control(name) 7 | { 8 | public override void Execute(IOperation operation) 9 | { 10 | operation.Apply(this); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor6Demo/4_ Implement Concrete Elements/TextBox.cs: -------------------------------------------------------------------------------- 1 | using Visitor6Demo._1_Visitor_Interface; 2 | using Visitor6Demo._3_Define_the_Element_Interface; 3 | 4 | namespace Visitor6Demo._4__Implement_Concrete_Elements; 5 | 6 | public class TextBox(string name) : Control(name) 7 | { 8 | public override void Execute(IOperation operation) 9 | { 10 | operation.Apply(this); 11 | } 12 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor6Demo/Visitor6Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor7Demo/1_Visitor Interface/IVisitor.cs: -------------------------------------------------------------------------------- 1 | using Visitor7Demo._4__Implement_Concrete_Elements; 2 | 3 | namespace Visitor7Demo._1_Visitor_Interface; 4 | 5 | internal interface IVisitor 6 | { 7 | string VisitTextToHtmlConverter(TextToHtmlConverter component, string text); 8 | string VisitHtmlToTextConverter(HtmlToTextConverter component, string text); 9 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor7Demo/3_Define the Element Interface/IComponent.cs: -------------------------------------------------------------------------------- 1 | using Visitor7Demo._1_Visitor_Interface; 2 | 3 | namespace Visitor7Demo._3_Define_the_Element_Interface; 4 | 5 | internal interface IComponent 6 | { 7 | string Accept(IVisitor visitor, string text); 8 | } -------------------------------------------------------------------------------- /3_Behavioral Design Patterns/Visitor/Visitor7Demo/Visitor7Demo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CSharpDesignPatterns.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True --------------------------------------------------------------------------------