├── .gitignore
├── LICENSE
├── README.md
├── images
├── AbstractFactory.png
├── Adapter.png
├── Bridge.png
├── ChainofResponsibility.png
├── Facade.png
├── FactoryPattern.png
├── Filter.png
├── Flyweight.png
├── Interpreter.png
├── Iterator.png
├── Mediator.png
├── Memento.png
├── Observer.png
├── ProtoType.png
├── Strategy.png
├── Template.png
├── Visitor.png
├── builder.png
├── command.png
├── decorator.png
├── factory_pattern_uml_diagram.jpg
├── null_pattern_uml_diagram.jpg
├── proxy.png
├── state_pattern_uml_diagram.png
└── the-relationship-between-design-patterns.jpg
├── jksj
├── README.html
├── README.md
└── images
│ └── 00.png
└── src
├── DesignPattern.AbstractFactory
├── Colors
│ ├── Blue.cs
│ ├── Green.cs
│ └── Red.cs
├── DesignPattern.AbstractFactory.csproj
├── Enums
│ ├── ColorType.cs
│ ├── ProducerType.cs
│ └── ShapeType.cs
├── Factories
│ ├── AbstractFactory.cs
│ ├── ColorFactory.cs
│ └── ShapeFactory.cs
├── FactoryProducer.cs
├── Interfaces
│ ├── IColor.cs
│ └── IShape.cs
├── Program.cs
├── Shapes
│ ├── Circle.cs
│ ├── Rectangle.cs
│ └── Square.cs
├── obj
│ ├── Debug
│ │ └── netcoreapp2.1
│ │ │ ├── DesignPattern.AbstractFactory.AssemblyInfo.cs
│ │ │ ├── DesignPattern.AbstractFactory.AssemblyInfoInputs.cache
│ │ │ ├── DesignPattern.AbstractFactory.assets.cache
│ │ │ ├── DesignPattern.AbstractFactory.csproj.CoreCompileInputs.cache
│ │ │ ├── DesignPattern.AbstractFactory.csprojAssemblyReference.cache
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPattern.AbstractFactory.csproj.nuget.cache
│ ├── DesignPattern.AbstractFactory.csproj.nuget.g.props
│ ├── DesignPattern.AbstractFactory.csproj.nuget.g.targets
│ └── project.assets.json
└── readme.md
├── DesignPattern.Builder
├── Bottle.cs
├── Burger.cs
├── ChickenBurger.cs
├── Coke.cs
├── ColdDrink.cs
├── DesignPattern.Builder.csproj
├── Interfaces
│ ├── IItem.cs
│ └── IPacking.cs
├── Meal.cs
├── MealBuilder.cs
├── Pepsi.cs
├── Program.cs
├── VegBurger.cs
├── Wrapper.cs
├── obj
│ ├── Debug
│ │ └── netcoreapp2.1
│ │ │ ├── DesignPattern.Builder.AssemblyInfo.cs
│ │ │ ├── DesignPattern.Builder.AssemblyInfoInputs.cache
│ │ │ ├── DesignPattern.Builder.assets.cache
│ │ │ ├── DesignPattern.Builder.csproj.CoreCompileInputs.cache
│ │ │ ├── DesignPattern.Builder.csprojAssemblyReference.cache
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPattern.Builder.csproj.nuget.cache
│ ├── DesignPattern.Builder.csproj.nuget.g.props
│ ├── DesignPattern.Builder.csproj.nuget.g.targets
│ └── project.assets.json
└── readme.md
├── DesignPattern.FactoryPattern
├── Circle.cs
├── DesignPattern.FactoryPattern.csproj
├── IShape.cs
├── Program.cs
├── Rectangle.cs
├── ShapeFactory.cs
├── Square.cs
├── obj
│ ├── Debug
│ │ └── netcoreapp2.1
│ │ │ ├── DesignPattern.FactoryPattern.AssemblyInfo.cs
│ │ │ ├── DesignPattern.FactoryPattern.AssemblyInfoInputs.cache
│ │ │ ├── DesignPattern.FactoryPattern.assets.cache
│ │ │ ├── DesignPattern.FactoryPattern.csproj.CoreCompileInputs.cache
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPattern.FactoryPattern.csproj.nuget.cache
│ ├── DesignPattern.FactoryPattern.csproj.nuget.g.props
│ ├── DesignPattern.FactoryPattern.csproj.nuget.g.targets
│ └── project.assets.json
└── readme.md
├── DesignPatterns.Adapter
├── AudioPlayer.cs
├── AudioType.cs
├── DesignPatterns.Adapter.csproj
├── IAdvancedMediaPlayer.cs
├── IMediaPlayer.cs
├── MediaAdapter.cs
├── Mp4Player.cs
├── Program.cs
├── VlcPlayer.cs
├── obj
│ ├── Debug
│ │ └── netcoreapp2.1
│ │ │ ├── DesignPatterns.Adapter.AssemblyInfo.cs
│ │ │ ├── DesignPatterns.Adapter.AssemblyInfoInputs.cache
│ │ │ ├── DesignPatterns.Adapter.assets.cache
│ │ │ ├── DesignPatterns.Adapter.csproj.CoreCompileInputs.cache
│ │ │ ├── DesignPatterns.Adapter.csprojAssemblyReference.cache
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Adapter.csproj.nuget.cache
│ ├── DesignPatterns.Adapter.csproj.nuget.g.props
│ ├── DesignPatterns.Adapter.csproj.nuget.g.targets
│ └── project.assets.json
└── readme.md
├── DesignPatterns.Bridge
├── Circle.cs
├── DesignPatterns.Bridge.csproj
├── GreenCircle.cs
├── IDrawAPI.cs
├── Program.cs
├── RedCircle.cs
├── Shape.cs
├── obj
│ ├── Debug
│ │ └── netcoreapp2.1
│ │ │ ├── DesignPatterns.Bridge.AssemblyInfo.cs
│ │ │ ├── DesignPatterns.Bridge.AssemblyInfoInputs.cache
│ │ │ ├── DesignPatterns.Bridge.assets.cache
│ │ │ ├── DesignPatterns.Bridge.csproj.CoreCompileInputs.cache
│ │ │ ├── DesignPatterns.Bridge.csprojAssemblyReference.cache
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Bridge.csproj.nuget.cache
│ ├── DesignPatterns.Bridge.csproj.nuget.g.props
│ ├── DesignPatterns.Bridge.csproj.nuget.g.targets
│ └── project.assets.json
└── readme.md
├── DesignPatterns.ChainofResponsibility
├── AbstractLogger.cs
├── ConsoleLogger.cs
├── DesignPatterns.ChainofResponsibility.csproj
├── ErrorLogger.cs
├── FileLogger.cs
├── Program.cs
├── README.md
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.ChainofResponsibility.AssemblyInfo.cs
│ │ ├── DesignPatterns.ChainofResponsibility.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.ChainofResponsibility.assets.cache
│ │ ├── DesignPatterns.ChainofResponsibility.csproj.CoreCompileInputs.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.ChainofResponsibility.csproj.nuget.cache
│ ├── DesignPatterns.ChainofResponsibility.csproj.nuget.g.props
│ ├── DesignPatterns.ChainofResponsibility.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.Command
├── Broker.cs
├── BuyStock.cs
├── DesignPatterns.Command.csproj
├── IOrder.cs
├── Program.cs
├── README.md
├── SellStock.cs
└── Stock.cs
├── DesignPatterns.Composite
├── DesignPatterns.Composite.csproj
├── Employee.cs
├── Program.cs
├── README.md
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.Composite.AssemblyInfo.cs
│ │ ├── DesignPatterns.Composite.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.Composite.assets.cache
│ │ ├── DesignPatterns.Composite.csproj.CoreCompileInputs.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Composite.csproj.nuget.cache
│ ├── DesignPatterns.Composite.csproj.nuget.g.props
│ ├── DesignPatterns.Composite.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.Decorator
├── Circle.cs
├── DesignPatterns.Decorator.csproj
├── IShape.cs
├── Program.cs
├── README.md
├── Rectangle.cs
├── RedShapleDecorator.cs
├── ShapeDecorator.cs
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.Decorator.AssemblyInfo.cs
│ │ ├── DesignPatterns.Decorator.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.Decorator.assets.cache
│ │ ├── DesignPatterns.Decorator.csproj.CoreCompileInputs.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Decorator.csproj.nuget.cache
│ ├── DesignPatterns.Decorator.csproj.nuget.g.props
│ ├── DesignPatterns.Decorator.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.Facade
├── Circle.cs
├── DesignPatterns.Facade.csproj
├── IShape.cs
├── Program.cs
├── README.md
├── Rectangle.cs
├── ShapeMarker.cs
└── Square.cs
├── DesignPatterns.Filter
├── AndCriteria.cs
├── CriteriaFemale.cs
├── CriteriaMale.cs
├── CriteriaSingle.cs
├── DesignPatterns.Filter.csproj
├── ICriteria.cs
├── OrCriteria.cs
├── Person.cs
├── Program.cs
└── readme.md
├── DesignPatterns.Flyweight
├── Circle.cs
├── DesignPatterns.Flyweight.csproj
├── IShape.cs
├── Program.cs
├── README.md
└── ShapeFactory.cs
├── DesignPatterns.Interpreter
├── AndExpression.cs
├── DesignPatterns.Interpreter.csproj
├── IExpression.cs
├── OrExpression.cs
├── Program.cs
├── README.md
├── TerminalExpression.cs
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.Interpreter.AssemblyInfo.cs
│ │ ├── DesignPatterns.Interpreter.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.Interpreter.assets.cache
│ │ ├── DesignPatterns.Interpreter.csproj.CoreCompileInputs.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Interpreter.csproj.nuget.cache
│ ├── DesignPatterns.Interpreter.csproj.nuget.g.props
│ ├── DesignPatterns.Interpreter.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.Iterator
├── Container.cs
├── DesignPatterns.Iterator.csproj
├── Program.cs
├── README.md
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.Iterator.AssemblyInfo.cs
│ │ ├── DesignPatterns.Iterator.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.Iterator.assets.cache
│ │ ├── DesignPatterns.Iterator.csproj.CoreCompileInputs.cache
│ │ ├── DesignPatterns.Iterator.csprojAssemblyReference.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Iterator.csproj.nuget.cache
│ ├── DesignPatterns.Iterator.csproj.nuget.g.props
│ ├── DesignPatterns.Iterator.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.Mediator
├── ChatRoom.cs
├── DesignPatterns.Mediator.csproj
├── Program.cs
├── READMD.md
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.Mediator.AssemblyInfo.cs
│ │ ├── DesignPatterns.Mediator.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.Mediator.assets.cache
│ │ ├── DesignPatterns.Mediator.csproj.CoreCompileInputs.cache
│ │ ├── DesignPatterns.Mediator.csprojAssemblyReference.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Mediator.csproj.nuget.cache
│ ├── DesignPatterns.Mediator.csproj.nuget.g.props
│ ├── DesignPatterns.Mediator.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.Memento
├── CareTaker.cs
├── DesignPatterns.Memento.csproj
├── Memento.cs
├── Originator.cs
├── Program.cs
├── README.md
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.Memento.AssemblyInfo.cs
│ │ ├── DesignPatterns.Memento.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.Memento.assets.cache
│ │ ├── DesignPatterns.Memento.csproj.CoreCompileInputs.cache
│ │ ├── DesignPatterns.Memento.csprojAssemblyReference.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Memento.csproj.nuget.cache
│ ├── DesignPatterns.Memento.csproj.nuget.g.props
│ ├── DesignPatterns.Memento.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.NullObject
├── AbstractCustomer.cs
├── CustomerFactory.cs
├── DesignPatterns.NullObject.csproj
├── NullCustomer.cs
├── Program.cs
├── README.md
└── RealCustomer.cs
├── DesignPatterns.Observer
├── BinaryObserver.cs
├── DesignPatterns.Observer.csproj
├── HexaObserver.cs
├── Observer.cs
├── OctalObserver.cs
├── Program.cs
├── README.md
├── Subject.cs
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.Observer.AssemblyInfo.cs
│ │ ├── DesignPatterns.Observer.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.Observer.assets.cache
│ │ ├── DesignPatterns.Observer.csproj.CoreCompileInputs.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Observer.csproj.nuget.cache
│ ├── DesignPatterns.Observer.csproj.nuget.g.props
│ ├── DesignPatterns.Observer.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.ProtoType
├── DesignPatterns.ProtoType.csproj
├── Program.cs
├── ShapeCache.cs
├── obj
│ ├── Debug
│ │ └── netcoreapp2.1
│ │ │ ├── DesignPatterns.ProtoType.AssemblyInfo.cs
│ │ │ ├── DesignPatterns.ProtoType.AssemblyInfoInputs.cache
│ │ │ ├── DesignPatterns.ProtoType.assets.cache
│ │ │ ├── DesignPatterns.ProtoType.csproj.CoreCompileInputs.cache
│ │ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.ProtoType.csproj.nuget.cache
│ ├── DesignPatterns.ProtoType.csproj.nuget.g.props
│ ├── DesignPatterns.ProtoType.csproj.nuget.g.targets
│ └── project.assets.json
└── readme.md
├── DesignPatterns.Proxy
├── DesignPatterns.Proxy.csproj
├── IImage.cs
├── Program.cs
├── ProxyImage.cs
├── README.md
├── RealImage.cs
└── obj
│ ├── Debug
│ └── netcoreapp2.1
│ │ ├── DesignPatterns.Proxy.AssemblyInfo.cs
│ │ ├── DesignPatterns.Proxy.AssemblyInfoInputs.cache
│ │ ├── DesignPatterns.Proxy.assets.cache
│ │ ├── DesignPatterns.Proxy.csproj.CoreCompileInputs.cache
│ │ ├── TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ ├── TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ └── TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ ├── DesignPatterns.Proxy.csproj.nuget.cache
│ ├── DesignPatterns.Proxy.csproj.nuget.g.props
│ ├── DesignPatterns.Proxy.csproj.nuget.g.targets
│ └── project.assets.json
├── DesignPatterns.Singleton
├── DesignPatterns.Singleton.csproj
├── Program.cs
└── readme.md
├── DesignPatterns.State
├── Context.cs
├── DesignPatterns.State.csproj
├── IState.cs
├── Program.cs
├── README.md
├── StartState.cs
└── StopState.cs
├── DesignPatterns.Strategy
├── Context.cs
├── DesignPatterns.Strategy.csproj
├── IStrategy.cs
├── OperationAdd.cs
├── OperationMultiply.cs
├── OperationSubstract.cs
├── Program.cs
└── README.md
├── DesignPatterns.Template
├── Cricket.cs
├── DesignPatterns.Template.csproj
├── Football.cs
├── Game.cs
├── Program.cs
└── README.md
└── DesignPatterns.Visitor
├── Computer.cs
├── ComputerPartDisplayVisitor.cs
├── ComputerPartVisitor.cs
├── DesignPatterns.Visitor.csproj
├── IComputerPart.cs
├── Keyboard.cs
├── Monitor.cs
├── Mouse.cs
├── Program.cs
└── README.md
/images/AbstractFactory.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/AbstractFactory.png
--------------------------------------------------------------------------------
/images/Adapter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Adapter.png
--------------------------------------------------------------------------------
/images/Bridge.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Bridge.png
--------------------------------------------------------------------------------
/images/ChainofResponsibility.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/ChainofResponsibility.png
--------------------------------------------------------------------------------
/images/Facade.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Facade.png
--------------------------------------------------------------------------------
/images/FactoryPattern.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/FactoryPattern.png
--------------------------------------------------------------------------------
/images/Filter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Filter.png
--------------------------------------------------------------------------------
/images/Flyweight.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Flyweight.png
--------------------------------------------------------------------------------
/images/Interpreter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Interpreter.png
--------------------------------------------------------------------------------
/images/Iterator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Iterator.png
--------------------------------------------------------------------------------
/images/Mediator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Mediator.png
--------------------------------------------------------------------------------
/images/Memento.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Memento.png
--------------------------------------------------------------------------------
/images/Observer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Observer.png
--------------------------------------------------------------------------------
/images/ProtoType.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/ProtoType.png
--------------------------------------------------------------------------------
/images/Strategy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Strategy.png
--------------------------------------------------------------------------------
/images/Template.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Template.png
--------------------------------------------------------------------------------
/images/Visitor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/Visitor.png
--------------------------------------------------------------------------------
/images/builder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/builder.png
--------------------------------------------------------------------------------
/images/command.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/command.png
--------------------------------------------------------------------------------
/images/decorator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/decorator.png
--------------------------------------------------------------------------------
/images/factory_pattern_uml_diagram.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/factory_pattern_uml_diagram.jpg
--------------------------------------------------------------------------------
/images/null_pattern_uml_diagram.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/null_pattern_uml_diagram.jpg
--------------------------------------------------------------------------------
/images/proxy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/proxy.png
--------------------------------------------------------------------------------
/images/state_pattern_uml_diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/state_pattern_uml_diagram.png
--------------------------------------------------------------------------------
/images/the-relationship-between-design-patterns.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/images/the-relationship-between-design-patterns.jpg
--------------------------------------------------------------------------------
/jksj/README.md:
--------------------------------------------------------------------------------
1 | # 设计模式之美
2 |
3 |
4 |
5 | 
6 |
7 |
8 |
9 | ## 最常见的评价标准
10 |
11 | - 可维护性(maintainability)
12 | - 可读性(readability)
13 | - 可扩展性(extensibility)
14 | - 灵活性(flexibility)
15 | - 简洁性(simplicity)
16 | - 可复用性(reusability)
17 | - 可测试性(testability)
18 |
19 | ## 面向对象
20 |
21 | - 四大特性:继承、封装、多态、抽象
22 | - 面向对象编程与面向过程编程的区别和联系
23 | - 面向对象分享、面向对象设计、面向对象编程
24 | - 接口和抽象类的区别以及各自的应用场景
25 | - 基于接口而非实现编程的设计思想
26 | - 多用组合少用继承的设计思想
27 | - 面向过程的贫血模型和面向对象的充血模型
28 |
29 | ## 设计原则(SOLID 原则)
30 |
31 | - SRP 单一职责原则
32 | - OCP 开闭原则
33 | - LSP 里氏替换原则
34 | - ISP 接口隔离原则
35 | - DIP 依赖倒置原则
36 | - DRY 原则、KISS 原则、YAGNI 原则、LOD 法则
37 |
38 | ## 设计模式
39 |
40 | - 创建型
41 | - 常用:单例模式、工厂模式(工厂方法和抽象工厂)、创建者模式
42 | - 不常用:原型模式
43 | - 结构型
44 | - 常用:代理模式、桥接模式、装饰者模式、适配器模式
45 | - 不常用:门面模式、组合模式、享元模式
46 | - 行为型
47 | - 常用:观察者模式、模板模式、策略模式、职责链模式、迭代器模式、状态模式
48 | - 不常用:访问者模式、备忘录模式、命令模式、解释器模式、中介模式
49 |
50 | ## 编程规范
51 |
52 | ## 代码重构
53 |
54 | - 重构的目的(Why)、对象(What)、时机(When)、方法(How);
55 | - 保证重构不出错的技术手段:单元测试和代码的可测试性;
56 | - 两种不同规模的重构:
57 | - 大重构(大规模高层次)
58 | - 小重构(小规模低层次)
59 |
60 | ## 抽象类和接口区别
61 |
62 | - 抽象类(is-A)
63 | - 特点:
64 | - 不允许被实例化,只能被继承
65 | - 可以包含属性和方法
66 | - 子类继承抽象类,必须实现抽象类中的所有抽象方法
67 | - 作用:
68 | - 代码复用
69 | - 接口(has-A)
70 | - 特点:
71 | - 接口不能包含属性(也就是成员变量)
72 | - 只能声明方法,方法不能包含代码实现
73 | - 类实现接口的时候,必须实现接口中声明的所有方法
74 | - 作用:
75 | - 解耦
--------------------------------------------------------------------------------
/jksj/images/00.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/jksj/images/00.png
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Colors/Blue.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.interfaces;
3 |
4 | namespace DesignPattern.AbstractFactory.Colors
5 | {
6 | public class Blue:IColor
7 | {
8 | public void Fill()
9 | {
10 | Console.WriteLine("Filled with blue");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Colors/Green.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.interfaces;
3 |
4 | namespace DesignPattern.AbstractFactory.Colors
5 | {
6 | public class Green : IColor
7 | {
8 | public void Fill()
9 | {
10 | Console.WriteLine("Filled with green");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Colors/Red.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.interfaces;
3 |
4 | namespace DesignPattern.AbstractFactory.Colors
5 | {
6 | class Red:IColor
7 | {
8 | public void Fill()
9 | {
10 | Console.WriteLine("Filled with red");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/DesignPattern.AbstractFactory.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Enums/ColorType.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.AbstractFactory.Enums
2 | {
3 | public enum ColorType
4 | {
5 | Blue,
6 | Green,
7 | Red
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Enums/ProducerType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPattern.AbstractFactory.Enums
6 | {
7 | public enum ProducerType
8 | {
9 | Shape,
10 | Color
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Enums/ShapeType.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.AbstractFactory.Enums
2 | {
3 | public enum ShapeType
4 | {
5 | Circle,
6 | Rectangle,
7 | Square
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Factories/AbstractFactory.cs:
--------------------------------------------------------------------------------
1 | using DesignPattern.AbstractFactory.Enums;
2 | using DesignPattern.AbstractFactory.interfaces;
3 |
4 | namespace DesignPattern.AbstractFactory.Factories
5 | {
6 | public abstract class AbstractFactory
7 | {
8 | public abstract IColor GetColor(ColorType colorType);
9 |
10 | public abstract IShape GetShape(ShapeType shapeType);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Factories/ColorFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.Colors;
3 | using DesignPattern.AbstractFactory.Enums;
4 | using DesignPattern.AbstractFactory.interfaces;
5 |
6 | namespace DesignPattern.AbstractFactory.Factories
7 | {
8 | public class ColorFactory:AbstractFactory
9 | {
10 | public override IColor GetColor(ColorType colorType)
11 | {
12 | IColor color = null;
13 | switch (colorType)
14 | {
15 | case ColorType.Blue:
16 | color= new Blue();
17 | break;
18 | case ColorType.Green:
19 | color =new Green();
20 | break;
21 | case ColorType.Red:
22 | color = new Red();
23 | break;
24 | default:
25 | throw new ArgumentOutOfRangeException(nameof(colorType), colorType, null);
26 | }
27 |
28 | return color;
29 | }
30 |
31 | public override IShape GetShape(ShapeType shapeType)
32 | {
33 | return null;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Factories/ShapeFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.Enums;
3 | using DesignPattern.AbstractFactory.interfaces;
4 | using DesignPattern.AbstractFactory.Shapes;
5 |
6 | namespace DesignPattern.AbstractFactory.Factories
7 | {
8 | public class ShapeFactory:AbstractFactory
9 | {
10 | public override IColor GetColor(ColorType colorType)
11 | {
12 | return null;
13 | }
14 |
15 | public override IShape GetShape(ShapeType shapeType)
16 | {
17 | IShape shape = null;
18 | switch (shapeType)
19 | {
20 | case ShapeType.Circle:
21 | shape = new Circle();
22 | break;
23 | case ShapeType.Rectangle:
24 | shape = new Rectangle();
25 | break;
26 | case ShapeType.Square:
27 | shape = new Square();
28 | break;
29 | default:
30 | throw new ArgumentOutOfRangeException(nameof(shapeType), shapeType, null);
31 | }
32 | return shape;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/FactoryProducer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.Enums;
3 | using DesignPattern.AbstractFactory.Factories;
4 |
5 | namespace DesignPattern.AbstractFactory
6 | {
7 | public class FactoryProducer
8 | {
9 | public static Factories.AbstractFactory GetFactory(ProducerType producerType)
10 | {
11 | switch (producerType)
12 | {
13 | case ProducerType.Shape:
14 | return new ShapeFactory();
15 | case ProducerType.Color:
16 | return new ColorFactory();
17 | default:
18 | throw new ArgumentOutOfRangeException(nameof(producerType), producerType, null);
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Interfaces/IColor.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.AbstractFactory.interfaces
2 | {
3 | public interface IColor
4 | {
5 | void Fill();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Interfaces/IShape.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.AbstractFactory.interfaces
2 | {
3 | public interface IShape
4 | {
5 | void Draw();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.Enums;
3 | using DesignPattern.AbstractFactory.interfaces;
4 |
5 | namespace DesignPattern.AbstractFactory
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | Factories.AbstractFactory shapeFactory = FactoryProducer.GetFactory(ProducerType.Shape);
12 | IShape shape = shapeFactory.GetShape(ShapeType.Circle);
13 | shape.Draw();
14 |
15 | Factories.AbstractFactory colorFactory = FactoryProducer.GetFactory(ProducerType.Color);
16 | IColor color = colorFactory.GetColor(ColorType.Red);
17 | color.Fill();
18 |
19 | Console.ReadKey();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Shapes/Circle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.interfaces;
3 |
4 | namespace DesignPattern.AbstractFactory.Shapes
5 | {
6 | public class Circle:IShape
7 | {
8 | public void Draw()
9 | {
10 | Console.WriteLine("I am a Circle");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Shapes/Rectangle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.interfaces;
3 |
4 | namespace DesignPattern.AbstractFactory.Shapes
5 | {
6 | public class Rectangle:IShape
7 | {
8 | public void Draw()
9 | {
10 | Console.WriteLine("I am a Rectangle");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/Shapes/Square.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DesignPattern.AbstractFactory.interfaces;
3 |
4 | namespace DesignPattern.AbstractFactory.Shapes
5 | {
6 | public class Square : IShape
7 | {
8 | public void Draw()
9 | {
10 | Console.WriteLine("I am a Square");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/DesignPattern.AbstractFactory.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPattern.AbstractFactory")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPattern.AbstractFactory")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPattern.AbstractFactory")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/DesignPattern.AbstractFactory.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 331ce9a1a97c20eac885da6fb911596266a2b6e0
2 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/DesignPattern.AbstractFactory.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/DesignPattern.AbstractFactory.assets.cache
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/DesignPattern.AbstractFactory.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 8a63a90c80b3fcdb052fd690886f784e4890405f
2 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/DesignPattern.AbstractFactory.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/DesignPattern.AbstractFactory.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.AbstractFactory/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/DesignPattern.AbstractFactory.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "7B2CIstqbm5eWoeNFLAlqKnkVP10VyGpwYvGI3PG73mG+SB2il+G553skh5VfL/wWBm4LRpJd9Nbg187g0d8FQ==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/DesignPattern.AbstractFactory.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPattern.AbstractFactory/obj/DesignPattern.AbstractFactory.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Bottle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using DesignPattern.Builder.Interfaces;
5 |
6 | namespace DesignPattern.Builder
7 | {
8 | class Bottle:IPacking
9 | {
10 | public string Pack() => "Bottle";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Burger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using DesignPattern.Builder.Interfaces;
5 |
6 | namespace DesignPattern.Builder
7 | {
8 | public abstract class Burger:IItem
9 | {
10 | public abstract string Name();
11 |
12 | public IPacking Packing()
13 | {
14 | return new Wrapper();
15 | }
16 |
17 | public abstract float Price();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/ChickenBurger.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.Builder
2 | {
3 | public class ChickenBurger: Burger
4 | {
5 | public override string Name() => "Chicken Burger";
6 |
7 | public override float Price() => 50.5f;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Coke.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.Builder
2 | {
3 | public class Coke : ColdDrink
4 | {
5 | public override float Price() => 30.0f;
6 |
7 | public override string Name() => "Coke";
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/ColdDrink.cs:
--------------------------------------------------------------------------------
1 | using DesignPattern.Builder.Interfaces;
2 |
3 | namespace DesignPattern.Builder
4 | {
5 | public abstract class ColdDrink:IItem
6 | {
7 | public abstract string Name();
8 |
9 | public IPacking Packing()
10 | {
11 | return new Bottle();
12 | }
13 |
14 | public abstract float Price();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/DesignPattern.Builder.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Interfaces/IItem.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.Builder.Interfaces
2 | {
3 | public interface IItem
4 | {
5 | string Name();
6 | IPacking Packing();
7 | float Price();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Interfaces/IPacking.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPattern.Builder.Interfaces
6 | {
7 | public interface IPacking
8 | {
9 | string Pack();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Meal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using DesignPattern.Builder.Interfaces;
4 |
5 | namespace DesignPattern.Builder
6 | {
7 | public class Meal
8 | {
9 | private List items = new List();
10 |
11 | public void AddItem(IItem item)
12 | {
13 | if (item != null) items.Add(item);
14 | }
15 |
16 | public float GetCost()
17 | {
18 | float cost = 0.0f;
19 | foreach (IItem item in items)
20 | {
21 | cost += item.Price();
22 | }
23 |
24 | return cost;
25 | }
26 |
27 | public void ShowItems()
28 | {
29 | foreach (IItem item in items)
30 | {
31 | Console.WriteLine($"Name:{item.Name()}");
32 | Console.WriteLine($"Packing:{item.Packing()}");
33 | Console.WriteLine($"Price:{item.Price()}");
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/MealBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPattern.Builder
6 | {
7 | public class MealBuilder
8 | {
9 | public Meal PrepareVegMeal()
10 | {
11 | Meal meal = new Meal();
12 | meal.AddItem(new VegBurger());
13 | meal.AddItem(new Coke());
14 | return meal;
15 | }
16 |
17 | public Meal PrepareNonMeal()
18 | {
19 | Meal meal = new Meal();
20 | meal.AddItem(new ChickenBurger());
21 | meal.AddItem(new Pepsi());
22 | return meal;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Pepsi.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.Builder
2 | {
3 | public class Pepsi : ColdDrink
4 | {
5 | public override string Name() => "Pepsi";
6 |
7 | public override float Price() => 35.0f;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPattern.Builder
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | MealBuilder builder = new MealBuilder();
10 |
11 | Meal vegMeal = builder.PrepareVegMeal();
12 | Console.WriteLine("Veg Meal");
13 | vegMeal.ShowItems();
14 | Console.WriteLine($"Total Cost:{vegMeal.GetCost()}");
15 |
16 | Console.WriteLine("-----------------");
17 |
18 | Meal nonVegMeal = builder.PrepareNonMeal();
19 | Console.WriteLine("Non-Veg Meal");
20 | nonVegMeal.ShowItems();
21 | Console.WriteLine($"Total Cost:{nonVegMeal.GetCost()}");
22 |
23 | Console.ReadKey();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/VegBurger.cs:
--------------------------------------------------------------------------------
1 | namespace DesignPattern.Builder
2 | {
3 | public class VegBurger:Burger
4 | {
5 | public override string Name() => "Veg Burger";
6 |
7 | public override float Price() => 25.0f;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/Wrapper.cs:
--------------------------------------------------------------------------------
1 | using DesignPattern.Builder.Interfaces;
2 |
3 | namespace DesignPattern.Builder
4 | {
5 | public class Wrapper : IPacking
6 | {
7 | public string Pack() => "Wrapper";
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/DesignPattern.Builder.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPattern.Builder")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPattern.Builder")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPattern.Builder")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // 由 MSBuild WriteCodeFragment 类生成。
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/DesignPattern.Builder.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 94727106fb7dc3a027ffd4aab9107890f6fb66b8
2 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/DesignPattern.Builder.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/DesignPattern.Builder.assets.cache
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/DesignPattern.Builder.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 477e4e029d89430e1a7c92b7573e31f4ee3e5636
2 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/DesignPattern.Builder.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/DesignPattern.Builder.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.Builder/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/DesignPattern.Builder.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "KiYjePi/IxYOXSyYEdUOVWRsvEzAokEw047YTIV6UT/8VAYV+OIhHjpW5Bixv5k58m7LoLB3hZb0qkDpBOpzCQ==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/DesignPattern.Builder.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPattern.Builder/obj/DesignPattern.Builder.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/Circle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPattern.FactoryPattern
6 | {
7 | public class Circle:IShape
8 | {
9 | public void Draw()
10 | {
11 | Console.WriteLine("I am a Circle");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/DesignPattern.FactoryPattern.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/IShape.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPattern.FactoryPattern
6 | {
7 | public interface IShape
8 | {
9 | void Draw();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPattern.FactoryPattern
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | var factory = new ShapeFactory();
10 | IShape shape = factory.GetShape(ShapeType.Rectangle);
11 | shape.Draw();
12 |
13 | Console.ReadKey();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/Rectangle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPattern.FactoryPattern
6 | {
7 | public class Rectangle:IShape
8 | {
9 | public void Draw()
10 | {
11 | Console.WriteLine("I am a Rectangle");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/ShapeFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using DesignPattern.FactoryPattern;
5 |
6 | namespace DesignPattern.FactoryPattern
7 | {
8 | public enum ShapeType
9 | {
10 | Circle,
11 | Rectangle,
12 | Square,
13 | }
14 |
15 | public class ShapeFactory
16 | {
17 | public IShape GetShape(ShapeType shapeType)
18 | {
19 | IShape shape = null;
20 | switch (shapeType)
21 | {
22 | case ShapeType.Circle:
23 | shape = new Circle();
24 | break;
25 | case ShapeType.Rectangle:
26 | shape = new Rectangle();
27 | break;
28 | case ShapeType.Square:
29 | shape = new Square();
30 | break;
31 | }
32 | return shape;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/Square.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPattern.FactoryPattern
6 | {
7 | public class Square:IShape
8 | {
9 | public void Draw()
10 | {
11 | Console.WriteLine("I am a Square");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/DesignPattern.FactoryPattern.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPattern.FactoryPattern")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPattern.FactoryPattern")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPattern.FactoryPattern")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/DesignPattern.FactoryPattern.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 639bc7a379e98260807491b5d3fd957d181514b9
2 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/DesignPattern.FactoryPattern.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/DesignPattern.FactoryPattern.assets.cache
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/DesignPattern.FactoryPattern.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | aa3271ae251cf1e85a322b055356308f840a4a38
2 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPattern.FactoryPattern/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/DesignPattern.FactoryPattern.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "iQagWzFEx9sH+cpz/Iw28CBrb3DG+/oyKhIdSYsEUd+ujhWtx9MYKeUi5bMH1Lk8SFeFZYE9rcQwKhMowvD+zA==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/DesignPattern.FactoryPattern.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPattern.FactoryPattern/obj/DesignPattern.FactoryPattern.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/AudioPlayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Text;
5 |
6 | namespace DesignPatterns.Adapter
7 | {
8 | public class AudioPlayer:IMediaPlayer
9 | {
10 | private IMediaPlayer mediaAdapter;
11 | public void Play(AudioType audioType, string fileName)
12 | {
13 | switch (audioType)
14 | {
15 | case AudioType.MP3:
16 | Console.WriteLine($"Playing mp3 file. Name:{fileName}");
17 | break;
18 | case AudioType.VLC:
19 | case AudioType.MP4:
20 | mediaAdapter = new MediaAdapter(audioType);
21 | mediaAdapter.Play(audioType, fileName);
22 | break;
23 | default:
24 | Console.WriteLine($"Invalid media.{audioType} format not supported");
25 | break;
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/AudioType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Adapter
6 | {
7 | public enum AudioType
8 | {
9 | VLC,
10 | MP3,
11 | MP4,
12 | Unknown
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/DesignPatterns.Adapter.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/IAdvancedMediaPlayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Adapter
6 | {
7 | public interface IAdvancedMediaPlayer
8 | {
9 | void PlayVlc(string fileNmae);
10 | void PlayMp4(string fileNmae);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/IMediaPlayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Adapter
6 | {
7 | public interface IMediaPlayer
8 | {
9 | void Play(AudioType audioType, string fileName);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/MediaAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Text;
5 |
6 | namespace DesignPatterns.Adapter
7 | {
8 | public class MediaAdapter:IMediaPlayer
9 | {
10 | private IAdvancedMediaPlayer advancedMediaPlayer;
11 |
12 | public MediaAdapter(AudioType audioType)
13 | {
14 | switch (audioType)
15 | {
16 | case AudioType.VLC:
17 | advancedMediaPlayer = new VlcPlayer();
18 | break;
19 | case AudioType.MP4:
20 | advancedMediaPlayer = new Mp4Player();
21 | break;
22 | default:
23 | throw new ArgumentOutOfRangeException(nameof(audioType), audioType, null);
24 | }
25 | }
26 |
27 | public void Play(AudioType audioType, string fileName)
28 | {
29 | switch (audioType)
30 | {
31 | case AudioType.VLC:
32 | advancedMediaPlayer.PlayVlc(fileName);
33 | break;
34 | case AudioType.MP4:
35 | advancedMediaPlayer.PlayMp4(fileName);
36 | break;
37 | default:
38 | throw new ArgumentOutOfRangeException(nameof(audioType), audioType, null);
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/Mp4Player.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Adapter
6 | {
7 | public class Mp4Player:IAdvancedMediaPlayer
8 | {
9 | public void PlayVlc(string fileNmae)
10 | {
11 | }
12 |
13 | public void PlayMp4(string fileNmae)
14 | {
15 | Console.WriteLine($"Playing mp4 file.Name:{fileNmae}");
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Adapter
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | IMediaPlayer audioPlayer = new AudioPlayer();
10 | audioPlayer.Play(AudioType.MP3, "beyond the horizon.mp3");
11 | audioPlayer.Play(AudioType.MP4, "alone.mp4");
12 | audioPlayer.Play(AudioType.VLC, "far far away.vlc");
13 | audioPlayer.Play(AudioType.Unknown, "mind me.avi");
14 |
15 | Console.ReadKey();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/VlcPlayer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Adapter
6 | {
7 | public class VlcPlayer:IAdvancedMediaPlayer
8 | {
9 | public void PlayVlc(string fileNmae)
10 | {
11 | Console.WriteLine($"Playing vlc file.Name:{fileNmae}");
12 | }
13 |
14 | public void PlayMp4(string fileNmae)
15 | {
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/DesignPatterns.Adapter.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Adapter")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Adapter")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Adapter")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/DesignPatterns.Adapter.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 1637729bba8a432c5c8f03d617db33e9abdcf9bf
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/DesignPatterns.Adapter.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/DesignPatterns.Adapter.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/DesignPatterns.Adapter.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 286b5fe126d70972d4fdc1fb6e6c1ab768605113
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/DesignPatterns.Adapter.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/DesignPatterns.Adapter.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Adapter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/DesignPatterns.Adapter.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "ZTfjM5YJtpfp7oR5PoZ4msACPtdIrcIhmwvr4Df2lihWFD0N09s044D3aLPStkmFd3TeYwMhg4T6Zh8w5ltyXA==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/DesignPatterns.Adapter.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Adapter/obj/DesignPatterns.Adapter.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/Circle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Bridge
6 | {
7 | public class Circle:Shape
8 | {
9 | private int x, y, radius;
10 | public Circle(int x,int y,int radius,IDrawAPI drawAPI) : base(drawAPI)
11 | {
12 | this.x = x;
13 | this.y = y;
14 | this.radius = radius;
15 | }
16 |
17 | public override void Draw()
18 | {
19 | drawAPI.DrawCircle(radius, x, y);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/DesignPatterns.Bridge.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/GreenCircle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Bridge
6 | {
7 | public class GreenCircle:IDrawAPI
8 | {
9 | public void DrawCircle(int radius, int x, int y)
10 | {
11 | Console.WriteLine($"Drawing Circle[color:green,radius:{radius},x:{x},y:{y}]");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/IDrawAPI.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Bridge
6 | {
7 | public interface IDrawAPI
8 | {
9 | void DrawCircle(int radius, int x, int y);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Bridge
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Shape redCircle = new Circle(100, 100, 10, new RedCircle());
10 | redCircle.Draw();
11 |
12 | Shape greenCircle = new Circle(100, 100, 10, new GreenCircle());
13 | greenCircle.Draw();
14 |
15 | Console.ReadKey();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/RedCircle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Bridge
6 | {
7 | public class RedCircle:IDrawAPI
8 | {
9 | public void DrawCircle(int radius, int x, int y)
10 | {
11 | Console.WriteLine($"Drawing Circle[color:red,radius:{radius},x:{x},y:{y}]");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/Shape.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Bridge
6 | {
7 | public abstract class Shape
8 | {
9 | protected IDrawAPI drawAPI;
10 |
11 | protected Shape(IDrawAPI drawAPI) => this.drawAPI = drawAPI;
12 |
13 | public abstract void Draw();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/DesignPatterns.Bridge.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Bridge")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Bridge")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Bridge")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/DesignPatterns.Bridge.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | e4f62347c83ae5acfec48b83c6c3c126374abe42
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/DesignPatterns.Bridge.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/DesignPatterns.Bridge.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/DesignPatterns.Bridge.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 6ad32d921066e5a128c388f2702913908eb4242a
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/DesignPatterns.Bridge.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/DesignPatterns.Bridge.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Bridge/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/DesignPatterns.Bridge.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "UpaVZfV9rpeuH1MVUSeMSJnqofS+iVZfPs/tkJelNPxh0SBLSoawiETjjrA8K1zxHNQJJIGhipX/+govvfXuzA==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/DesignPatterns.Bridge.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Bridge/obj/DesignPatterns.Bridge.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/AbstractLogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.ChainofResponsibility
6 | {
7 | public abstract class AbstractLogger
8 | {
9 | public static int INFO = 1;
10 | public static int DEBUG = 2;
11 | public static int ERROR = 3;
12 |
13 | protected int level;
14 |
15 | protected AbstractLogger nextLogger;
16 |
17 | public void SetNextLogger(AbstractLogger nextLogger)
18 | {
19 | this.nextLogger = nextLogger;
20 | }
21 |
22 | public void LogMessage(int level, string message)
23 | {
24 | if (this.level <= level)
25 | {
26 | write(message);
27 | }
28 |
29 | if (this.nextLogger != null)
30 | {
31 | nextLogger.LogMessage(level, message);
32 | }
33 |
34 | }
35 |
36 | protected abstract void write(string message);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/ConsoleLogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.ChainofResponsibility
6 | {
7 | public class ConsoleLogger:AbstractLogger
8 | {
9 | public ConsoleLogger(int level)
10 | {
11 | this.level = level;
12 | }
13 | protected override void write(string message) => Console.WriteLine($"Standard Console::Logger{message}");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/DesignPatterns.ChainofResponsibility.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/ErrorLogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.ChainofResponsibility
6 | {
7 | public class ErrorLogger:AbstractLogger
8 | {
9 | public ErrorLogger(int level)
10 | {
11 | this.level = level;
12 | }
13 | protected override void write(string message) => Console.WriteLine($"Error Console::Logger:{message}");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/FileLogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.ChainofResponsibility
4 | {
5 | public class FileLogger:AbstractLogger
6 | {
7 | public FileLogger(int level)
8 | {
9 | this.level = level;
10 | }
11 |
12 | protected override void write(string message) => Console.WriteLine($"File::Logger:{message}");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.ChainofResponsibility
4 | {
5 | class Program
6 | {
7 | private static AbstractLogger GetChainLoggers()
8 | {
9 | AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);
10 | AbstractLogger fileLogger = new FileLogger(AbstractLogger.DEBUG);
11 | AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.INFO);
12 |
13 | errorLogger.SetNextLogger(fileLogger);
14 | fileLogger.SetNextLogger(consoleLogger);
15 |
16 | return errorLogger;
17 | }
18 |
19 | static void Main(string[] args)
20 | {
21 | var loggerChain = GetChainLoggers();
22 |
23 | loggerChain.LogMessage(AbstractLogger.INFO, "This is an information");
24 | loggerChain.LogMessage(AbstractLogger.DEBUG, "This is an debug level information");
25 | loggerChain.LogMessage(AbstractLogger.ERROR, "This is an error information");
26 |
27 | Console.ReadKey();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/DesignPatterns.ChainofResponsibility.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.ChainofResponsibility")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.ChainofResponsibility")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.ChainofResponsibility")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // 由 MSBuild WriteCodeFragment 类生成。
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/DesignPatterns.ChainofResponsibility.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | b30448b709cba047f0f5dd40f5777a3b839a6fd7
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/DesignPatterns.ChainofResponsibility.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/DesignPatterns.ChainofResponsibility.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/DesignPatterns.ChainofResponsibility.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 85e038f70aaa65ff17b2ea813ec2d5fd2b85e0f3
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.ChainofResponsibility/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/DesignPatterns.ChainofResponsibility.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "3MFhC3vyPtahfDBlPmEVQdbISyJMtHGLBoPBMr5+PakDg+1uHCJ+thM8c5w0Yc/YqIz1+QftOeSy9KXx+UCa5A==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/DesignPatterns.ChainofResponsibility.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ChainofResponsibility/obj/DesignPatterns.ChainofResponsibility.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Command/Broker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Command
6 | {
7 | public class Broker
8 | {
9 | private List orderList = new List();
10 |
11 | public void TakeOrder(IOrder order)
12 | {
13 | orderList.Add(order);
14 | }
15 |
16 | public void PlaceOrders()
17 | {
18 | foreach (var order in orderList)
19 | {
20 | order.Execute();
21 | }
22 | orderList.Clear();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Command/BuyStock.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Command
6 | {
7 | public class BuyStock:IOrder
8 | {
9 | private Stock abcStock;
10 |
11 | public BuyStock(Stock abcStock)
12 | {
13 | this.abcStock = abcStock;
14 | }
15 |
16 | public void Execute()
17 | {
18 | this.abcStock.Buy();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Command/DesignPatterns.Command.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Command/IOrder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Command
6 | {
7 | public interface IOrder
8 | {
9 | void Execute();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Command/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Command
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | var abcStock = new Stock();
10 | var buyStockOrder = new BuyStock(abcStock);
11 | var sellStock = new SellStock(abcStock);
12 |
13 | var broker = new Broker();
14 | broker.TakeOrder(buyStockOrder);
15 | broker.TakeOrder(sellStock);
16 | broker.PlaceOrders();
17 |
18 | Console.ReadKey();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Command/SellStock.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Command
6 | {
7 | public class SellStock:IOrder
8 | {
9 | private Stock abcStock;
10 |
11 | public SellStock(Stock abcStock)
12 | {
13 | this.abcStock = abcStock;
14 | }
15 |
16 | public void Execute()
17 | {
18 | abcStock.Sell();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Command/Stock.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Command
6 | {
7 | public class Stock
8 | {
9 | private string name = "ABC";
10 | private int quantity = 10;
11 |
12 | public void Buy()
13 | {
14 | Console.WriteLine($"Stock [name:{name} Quantity:{quantity}] bought");
15 | }
16 |
17 | public void Sell()
18 | {
19 | Console.WriteLine($"Stock [Name:{name} Quantity:{quantity}] sold");
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/DesignPatterns.Composite.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/Employee.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Composite
6 | {
7 | public class Employee
8 | {
9 | private string name;
10 | private string dept;
11 | private int salary;
12 | private List subordinates;
13 | public Employee(string name,string dept,int sal)
14 | {
15 | this.name = name;
16 | this.dept = dept;
17 | this.salary = sal;
18 | subordinates = new List();
19 | }
20 |
21 | public void Add(Employee e) => subordinates.Add(e);
22 | public void Remove(Employee e) => subordinates.Remove(e);
23 |
24 | public List GetSubordinates() => this.subordinates;
25 |
26 | public override string ToString() => $"Employee :[name:{name},dept:{dept},salary:{salary}]";
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Composite
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Employee CEO = new Employee("John", "CEO", 30000);
10 |
11 | Employee headSales = new Employee("Robert", "Head Sales", 20000);
12 |
13 | Employee headMarketing = new Employee("Michel", "Head Marketing", 20000);
14 |
15 | Employee clerk1 = new Employee("Laura", "Marketing", 10000);
16 | Employee clerk2 = new Employee("Bob", "Marketing", 10000);
17 |
18 | Employee salesExecutive1 = new Employee("Richard", "Sales", 10000);
19 | Employee salesExecutive2 = new Employee("Rob", "Sales", 10000);
20 |
21 | CEO.Add(headSales);
22 | CEO.Add(headMarketing);
23 |
24 | headSales.Add(salesExecutive1);
25 | headSales.Add(salesExecutive2);
26 |
27 | headMarketing.Add(clerk1);
28 | headMarketing.Add(clerk2);
29 |
30 | Console.WriteLine(CEO);
31 | foreach (var headEmployee in CEO.GetSubordinates())
32 | {
33 | Console.WriteLine(headEmployee);
34 | foreach (var employee in headEmployee.GetSubordinates())
35 | {
36 | Console.WriteLine(employee);
37 | }
38 | }
39 |
40 | Console.ReadKey();
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/DesignPatterns.Composite.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Composite")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Composite")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Composite")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // 由 MSBuild WriteCodeFragment 类生成。
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/DesignPatterns.Composite.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 60f3afc0ef4b9ed245552d8df4d75c682b6a6bcb
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/DesignPatterns.Composite.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/DesignPatterns.Composite.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/DesignPatterns.Composite.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | a991f90b57bcdea500d76d346238ab48ffae9980
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Composite/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/DesignPatterns.Composite.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "thq1orzUEXCGO9DxwqEvGSVHVcxxV8Vtylf4KDPi1Xzmyi00vM9uuTCxlGfooPpexLA2bFMkxl0oTTUjkkEj+A==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/DesignPatterns.Composite.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Composite/obj/DesignPatterns.Composite.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/Circle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Decorator
6 | {
7 | public class Circle:IShape
8 | {
9 | public void Draw()
10 | {
11 | Console.WriteLine("Shape:Circle");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/DesignPatterns.Decorator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/IShape.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Decorator
6 | {
7 | public interface IShape
8 | {
9 | void Draw();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Decorator
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | IShape circle = new Circle();
10 | IShape redCircle = new RedShapleDecorator(new Circle());
11 |
12 | IShape redRectangle = new RedShapleDecorator(new Rectangle());
13 | Console.WriteLine("Circle with normal border");
14 | circle.Draw();
15 |
16 | Console.WriteLine("Circle of red border");
17 | redCircle.Draw();
18 |
19 | Console.WriteLine("Rectangel of red border");
20 | redRectangle.Draw();
21 |
22 | Console.ReadKey();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/Rectangle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Decorator
6 | {
7 | public class Rectangle : IShape
8 | {
9 | public void Draw()
10 | {
11 | Console.WriteLine("Shape:Rectangle");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/RedShapleDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Decorator
6 | {
7 | public class RedShapleDecorator : ShapeDecorator
8 | {
9 | public RedShapleDecorator(IShape decoratedShape) : base(decoratedShape)
10 | {
11 | }
12 |
13 | public override void Draw()
14 | {
15 | this.decoratedShape.Draw();
16 | setRedBorder(this.decoratedShape);
17 | }
18 |
19 | private void setRedBorder(IShape decoratedShape)
20 | {
21 | Console.WriteLine("Border Color:Red");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/ShapeDecorator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Decorator
6 | {
7 | public class ShapeDecorator:IShape
8 | {
9 | protected IShape decoratedShape;
10 |
11 | public ShapeDecorator(IShape decoratedShape)
12 | {
13 | this.decoratedShape = decoratedShape;
14 | }
15 |
16 | public virtual void Draw()
17 | {
18 | decoratedShape.Draw();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/DesignPatterns.Decorator.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Decorator")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Decorator")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Decorator")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // 由 MSBuild WriteCodeFragment 类生成。
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/DesignPatterns.Decorator.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 1689641d2afeb282c5487dc2954408f1c31007fc
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/DesignPatterns.Decorator.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/DesignPatterns.Decorator.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/DesignPatterns.Decorator.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | d7646c3dd4ef78d98768eaea2b4d40f4f6102b38
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Decorator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/DesignPatterns.Decorator.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "w4GsMckFgFWeXo9Nw17re771+jAfo/CJBjCnILNfeNvRS+jPpobS5x/UW+ctxqFTbkrOtNwAFObzbk0TgsOeAQ==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/DesignPatterns.Decorator.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Decorator/obj/DesignPatterns.Decorator.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Facade/Circle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Facade
6 | {
7 | public class Circle:IShape
8 | {
9 | public void Draw() => Console.WriteLine("Circle:Draw()");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Facade/DesignPatterns.Facade.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Facade/IShape.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Facade
6 | {
7 | public interface IShape
8 | {
9 | void Draw();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Facade/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Facade
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | var shapeMarker = new ShapeMarker();
10 | shapeMarker.DrawCircle();
11 | shapeMarker.DrawRectangle();
12 | shapeMarker.DrawSquare();
13 | Console.ReadKey();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Facade/README.md:
--------------------------------------------------------------------------------
1 | > 外观模式通过创建新的对象访问接口,从而隐藏对象内部发复复杂性
2 |
3 | ## 介绍
4 |
5 | 外观模式属于结构型模式,通过定义的外观器,从而简化了具体对象的内部复杂性。这种模式通过在复杂系统和上层调用之间添加了一层,这一层对上提供简单接口,对下执行复杂操作。
6 |
7 | ## 类图描述
8 |
9 | 
10 |
11 | 通过上图我们可以发现,**IShape** 为行为接口,然后 **Rectangle** **Square** **Circle** 为具体的对象实体类型, **ShapeMarker** 为我们定义的外观器,通过它,我们能间接访问复杂对象。
12 |
13 | ## 代码实现
14 |
15 | 1、定义对象接口
16 |
17 | ```C#
18 | public interface IShape
19 | {
20 | void Draw();
21 | }
22 | ```
23 |
24 | 2、定义实体对象类型
25 |
26 | ```C#
27 | public class Circle:IShape
28 | {
29 | public void Draw() => Console.WriteLine("Circle:Draw()");
30 | }
31 | public class Rectangle:IShape
32 | {
33 | public void Draw() => Console.WriteLine("Rectangle:Draw()");
34 | }
35 | public class Square:IShape
36 | {
37 | public void Draw() => Console.WriteLine("Square:Draw()");
38 | }
39 | ```
40 |
41 | 3、定义外观类
42 |
43 | ```C#
44 | public class ShapeMarker
45 | {
46 | private IShape circle;
47 | private IShape rectangle;
48 | private IShape square;
49 |
50 | public ShapeMarker()
51 | {
52 | circle = new Circle();
53 | rectangle = new Rectangle();
54 | square = new Square();
55 | }
56 |
57 | public void DrawCircle() => circle.Draw();
58 | public void DrawRectangle() => rectangle.Draw();
59 | public void DrawSquare() => square.Draw();
60 | }
61 | ```
62 |
63 | 4、上层调用
64 |
65 | ```C#
66 | class Program
67 | {
68 | static void Main(string[] args)
69 | {
70 | var shapeMarker = new ShapeMarker();
71 | shapeMarker.DrawCircle();
72 | shapeMarker.DrawRectangle();
73 | shapeMarker.DrawSquare();
74 | Console.ReadKey();
75 | }
76 | }
77 | ```
78 |
79 | ## 总结
80 |
81 | 外观模式不符合开闭原则,如果外观类执行的操作过于复杂的话,则不建议使用这种模式。
--------------------------------------------------------------------------------
/src/DesignPatterns.Facade/Rectangle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Facade
6 | {
7 | public class Rectangle:IShape
8 | {
9 | public void Draw() => Console.WriteLine("Rectangle:Draw()");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Facade/ShapeMarker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Facade
6 | {
7 | public class ShapeMarker
8 | {
9 | private IShape circle;
10 | private IShape rectangle;
11 | private IShape square;
12 |
13 | public ShapeMarker()
14 | {
15 | circle = new Circle();
16 | rectangle = new Rectangle();
17 | square = new Square();
18 | }
19 |
20 | public void DrawCircle() => circle.Draw();
21 | public void DrawRectangle() => rectangle.Draw();
22 | public void DrawSquare() => square.Draw();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Facade/Square.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Facade
6 | {
7 | public class Square:IShape
8 | {
9 | public void Draw() => Console.WriteLine("Square:Draw()");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Filter/AndCriteria.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Filter
6 | {
7 | public class AndCriteria : ICriteria
8 | {
9 | private ICriteria criteria;
10 | private ICriteria otherCriteria;
11 |
12 | public AndCriteria(ICriteria criteria,ICriteria otherCriteria)
13 | {
14 | this.criteria = criteria;
15 | this.otherCriteria = otherCriteria;
16 | }
17 | public IEnumerable MeetCriteria(IEnumerable persions)
18 | {
19 | IEnumerable firstCriteriaPersons = criteria.MeetCriteria(persions);
20 | return otherCriteria.MeetCriteria(firstCriteriaPersons);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Filter/CriteriaFemale.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace DesignPatterns.Filter
7 | {
8 | public class CriteriaFemale : ICriteria
9 | {
10 | public IEnumerable MeetCriteria(IEnumerable persions)
11 | {
12 | List femalePersons = new List();
13 | femalePersons.AddRange(persions.Where(p => p.GetGender() == "FEMALE"));
14 | return femalePersons;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Filter/CriteriaMale.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace DesignPatterns.Filter
7 | {
8 | public class CriteriaMale : ICriteria
9 | {
10 | public IEnumerable MeetCriteria(IEnumerable persions)
11 | {
12 | List malePersons = new List();
13 | malePersons.AddRange(persions.Where(p => p.GetGender() == "MALE"));
14 | return malePersons;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Filter/CriteriaSingle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace DesignPatterns.Filter
7 | {
8 | public class CriteriaSingle : ICriteria
9 | {
10 | public IEnumerable MeetCriteria(IEnumerable persons)
11 | {
12 | List malePersons = new List();
13 | malePersons.AddRange(persons.Where(p => p.GetMaritalStatus() == "SINGLE"));
14 | return malePersons;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Filter/DesignPatterns.Filter.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Filter/ICriteria.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Filter
6 | {
7 | public interface ICriteria
8 | {
9 | IEnumerable MeetCriteria(IEnumerable persons);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Filter/OrCriteria.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace DesignPatterns.Filter
7 | {
8 | public class OrCriteria : ICriteria
9 | {
10 | private ICriteria criteria;
11 | private ICriteria otherCriteria;
12 | public OrCriteria(ICriteria criteria, ICriteria otherCriteria)
13 | {
14 | this.criteria = criteria;
15 | this.otherCriteria = otherCriteria;
16 | }
17 |
18 | public IEnumerable MeetCriteria(IEnumerable persions)
19 | {
20 | List firstCriteriaItems = criteria.MeetCriteria(persions).ToList();
21 | IEnumerable otherCriteriaItems = otherCriteria.MeetCriteria(persions);
22 | foreach (var person in otherCriteriaItems)
23 | {
24 | if (!firstCriteriaItems.Contains(person))
25 | {
26 | firstCriteriaItems.Add(person);
27 | }
28 | }
29 | return firstCriteriaItems;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Filter/Person.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Filter
6 | {
7 | public class Person
8 | {
9 | private string name;
10 | private string gender;
11 | private string maritalStatus;
12 |
13 | public Person(string name, string gender, string maritalStatus)
14 | {
15 | this.name = name;
16 | this.gender = gender;
17 | this.maritalStatus = maritalStatus;
18 | }
19 |
20 | public string GetName() => name;
21 | public string GetGender() => gender;
22 | public string GetMaritalStatus() => maritalStatus;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Flyweight/Circle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Flyweight
6 | {
7 | public class Circle:IShape
8 | {
9 | private string color;
10 | private int x;
11 | private int y;
12 | private int radius;
13 | public Circle(string color)
14 | {
15 | this.color = color;
16 | }
17 |
18 | public void SetX(int x) => this.x = x;
19 | public void SetY(int y) => this.y = y;
20 | public void SetRadius(int radius) => this.radius = radius;
21 | public void Draw() => Console.WriteLine($"Circle:Draw()[Color:{color},x={x},y={y},radius:{radius}]");
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Flyweight/DesignPatterns.Flyweight.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Flyweight/IShape.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Flyweight
6 | {
7 | public interface IShape
8 | {
9 | void Draw();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Flyweight/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Flyweight
4 | {
5 | class Program
6 | {
7 | private static string[] colors = new[] {"Red", "Green", "Blue", "White", "Black"};
8 | private static Random random = new Random();
9 |
10 | static void Main(string[] args)
11 | {
12 | for (int i = 0; i < 20; i++)
13 | {
14 | Circle circle = (Circle) ShapeFactory.GetCircle(GetRandomColor());
15 | circle.SetX(GetRandomX());
16 | circle.SetY(GetRandomY());
17 | circle.SetRadius(100);
18 | circle.Draw();
19 | }
20 |
21 | Console.ReadKey();
22 | }
23 |
24 | private static string GetRandomColor()
25 | {
26 | return colors[random.Next(0, colors.Length)];
27 | }
28 |
29 | private static int GetRandomX()
30 | {
31 | return random.Next(0, colors.Length) * 100;
32 | }
33 |
34 | private static int GetRandomY()
35 | {
36 | return random.Next(0, colors.Length) * 100;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Flyweight/ShapeFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace DesignPatterns.Flyweight
7 | {
8 | public class ShapeFactory
9 | {
10 | private static Dictionary circleMap = new Dictionary();
11 |
12 | public static IShape GetCircle(string color)
13 | {
14 | circleMap.TryGetValue(color, out var circle);
15 |
16 | if (circle != null) return circle;
17 | circle = new Circle(color);
18 | circleMap.Add(color, circle);
19 | Console.WriteLine($"Creating circle of color:{color}");
20 |
21 | return circle;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/AndExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Interpreter
6 | {
7 | public class AndExpression : IExpression
8 | {
9 | private IExpression expr1 = null;
10 | private IExpression expr2 = null;
11 | public AndExpression(IExpression expr1, IExpression expr2)
12 | {
13 | this.expr1 = expr1;
14 | this.expr2 = expr2;
15 | }
16 |
17 | public bool Interpret(string context)
18 | {
19 | return expr1.Interpret(context) && expr2.Interpret(context);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/DesignPatterns.Interpreter.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/IExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Interpreter
6 | {
7 | public interface IExpression
8 | {
9 | bool Interpret(string context);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/OrExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Interpreter
6 | {
7 | public class OrExpression : IExpression
8 | {
9 | private IExpression expr1 = null;
10 | private IExpression expr2 = null;
11 | public OrExpression(IExpression expr1,IExpression expr2)
12 | {
13 | this.expr1 = expr1;
14 | this.expr2 = expr2;
15 | }
16 | public bool Interpret(string context)
17 | {
18 | return expr1.Interpret(context) || expr2.Interpret(context);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Interpreter
4 | {
5 | class Program
6 | {
7 | static IExpression GetMaleExpression()
8 | {
9 | IExpression robert = new TerminalExpression("Robert");
10 | IExpression john = new TerminalExpression("John");
11 | return new OrExpression(robert, john);
12 | }
13 | static IExpression GetMarriedWomanExpression()
14 | {
15 | IExpression julie = new TerminalExpression("Julie");
16 | IExpression married = new TerminalExpression("Married");
17 | return new AndExpression(julie, married);
18 | }
19 |
20 | static void Main(string[] args)
21 | {
22 | IExpression isMale = GetMaleExpression();
23 | IExpression isMarriedWoman = GetMarriedWomanExpression();
24 |
25 | Console.WriteLine($"John is male? {isMale.Interpret("John")}");
26 | Console.WriteLine($"Julie is a married women? {isMarriedWoman.Interpret("Married Julie")}");
27 | Console.ReadKey();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/TerminalExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Interpreter
6 | {
7 | public class TerminalExpression : IExpression
8 | {
9 | private string data;
10 |
11 | public TerminalExpression(string data)
12 | {
13 | this.data = data;
14 | }
15 | public bool Interpret(string context)
16 | {
17 | return context.Contains(data);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/DesignPatterns.Interpreter.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Interpreter")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Interpreter")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Interpreter")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/DesignPatterns.Interpreter.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 27bc438781d4a7440bf6747553cbe7bf18e44318
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/DesignPatterns.Interpreter.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/DesignPatterns.Interpreter.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/DesignPatterns.Interpreter.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 2f46bc14fd7d81cee6aa33b7c279bfad1c4175b8
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Interpreter/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/DesignPatterns.Interpreter.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "dogv2RStlYDUKvw6ui6i5w9ecQ2VsPNf/JSMR+WWtND5R6kAw00J+XqeSUce5wCoyQcZauVzsG7/ZTbvNxhCUg==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/DesignPatterns.Interpreter.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Interpreter/obj/DesignPatterns.Interpreter.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/Container.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Iterator
6 | {
7 | public interface Container
8 | {
9 | IIterator GetIterator();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/DesignPatterns.Iterator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Iterator
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | var namesRepository = new NameRepository();
10 | var iter = namesRepository.GetIterator();
11 | for (;iter.hasNext();)
12 | {
13 | Console.WriteLine(iter.Next());
14 | }
15 | Console.ReadKey();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/README.md:
--------------------------------------------------------------------------------
1 | > 迭代器模式在 **.Net** 中使用很广泛,其循环遍历对于的集合已经实现了迭代器模式
2 |
3 | ## 介绍
4 |
5 | 迭代器模式属于行为型模式,它通过提供一种方法来顺序访问集合对象中的每个元素,而又不用暴露其内部表示。
6 |
7 | ## 类图描述
8 |
9 | 
10 |
11 | ## 代码实现
12 |
13 | 1、创建接口
14 |
15 | ```C#
16 | public interface IIterator
17 | {
18 | bool hasNext();
19 | object Next();
20 | }
21 |
22 | public interface Container
23 | {
24 | IIterator GetIterator();
25 | }
26 | ```
27 |
28 | 2、创建可遍历的实体类
29 |
30 | ```C#
31 | public class NameRepository : Container
32 | {
33 | public static string[] names = {"Robert", "John", "Julie", "Lora"};
34 |
35 | public IIterator GetIterator()
36 | {
37 | return new NameIterator();
38 | }
39 |
40 | private class NameIterator : IIterator
41 | {
42 | private int index;
43 | public bool hasNext()
44 | {
45 | return index < names.Length;
46 | }
47 |
48 | public object Next()
49 | {
50 | return hasNext() ? names[index++] : null;
51 | }
52 | }
53 | }
54 | ```
55 |
56 | 3、上层调用
57 |
58 | ```C#
59 | class Program
60 | {
61 | static void Main(string[] args)
62 | {
63 | var namesRepository = new NameRepository();
64 | var iter = namesRepository.GetIterator();
65 | for (;iter.hasNext();)
66 | {
67 | Console.WriteLine(iter.Next());
68 | }
69 | Console.ReadKey();
70 | }
71 | }
72 | ```
73 |
74 | ## 总结
75 |
76 | 迭代器模式常用于对聚合对象的遍历。这种模式分离了集合对象的遍历行为。如果一个对象需要使用遍历的同时又不想暴露内部,这个时候则可以考虑使用这种设计模式。
77 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/DesignPatterns.Iterator.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Iterator")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Iterator")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Iterator")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/DesignPatterns.Iterator.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 5d1da24adb8f4f06007970d406e24ceff2a1f34c
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/DesignPatterns.Iterator.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/DesignPatterns.Iterator.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/DesignPatterns.Iterator.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 4a19b1e71b51ed1139bdb182cdc0a99a135a442a
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/DesignPatterns.Iterator.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/DesignPatterns.Iterator.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Iterator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/DesignPatterns.Iterator.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "+RFUfaKKQkrGQb13ZxQ6MjGhAYGN1I+XQ6Of2oKgC1K6Dc4o9PDbme+ZvDWIGvH5N/MxE9KBp5//YuyzCtIonQ==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/DesignPatterns.Iterator.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Iterator/obj/DesignPatterns.Iterator.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/ChatRoom.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Mediator
6 | {
7 | public class ChatRoom
8 | {
9 | public static void ShowMessage(User user, string message)
10 | {
11 | Console.WriteLine($"{DateTime.Now} [{user.GetName()}]:{message}");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/DesignPatterns.Mediator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Mediator
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | User robert = new User("Robert");
10 | User john = new User("john");
11 |
12 | robert.SendMessage("Hi! John!");
13 | john.SendMessage("Hello! Robert");
14 |
15 | Console.ReadKey();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/READMD.md:
--------------------------------------------------------------------------------
1 | > 中介者模式是用来降低多个对象和类之间的通信复杂性。这种模式提供了一个中介类,该类通常处理不同类之间的通信,并支持松耦合,使代码易于维护。
2 |
3 | ## 前言
4 |
5 | 中介者模式属于行为者模式,通过一个中介对象来封装一些列的对象交互,使对象之间解耦和,降低系统复杂度。
6 |
7 | ## 类图描述
8 |
9 | 
10 |
11 | ## 代码实现
12 |
13 | 1、创建中介类
14 |
15 | ```C#
16 | public class ChatRoom
17 | {
18 | public static void ShowMessage(User user, string message)
19 | {
20 | Console.WriteLine($"{DateTime.Now} [{user.GetName()}]:{message}");
21 | }
22 | }
23 | ```
24 |
25 | 2、创建实体
26 |
27 | ```C#
28 | public class User
29 | {
30 | private string name;
31 | public User(string name)
32 | {
33 | this.name = name;
34 | }
35 | internal object GetName()
36 | {
37 | return this.name;
38 | }
39 |
40 | public void SetName(string name)
41 | {
42 | this.name = name;
43 | }
44 |
45 | public void SendMessage(string message)
46 | {
47 | ChatRoom.ShowMessage(this, message);
48 | }
49 | }
50 | ```
51 |
52 | 3、上层调用
53 |
54 | ```C#
55 | class Program
56 | {
57 | static void Main(string[] args)
58 | {
59 | User robert = new User("Robert");
60 | User john = new User("john");
61 |
62 | robert.SendMessage("Hi! John!");
63 | john.SendMessage("Hello! Robert");
64 |
65 | Console.ReadKey();
66 | }
67 | }
68 | ```
69 |
70 | ## 总结
71 |
72 | 中介者模式通过为多个对象提供统一的通信方式进而简化对象之间的复杂引用关系,但是这种模式应该适可而止,否则到时候会使中介者过于庞大而难以维护。
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/DesignPatterns.Mediator.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Mediator")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Mediator")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Mediator")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // 由 MSBuild WriteCodeFragment 类生成。
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/DesignPatterns.Mediator.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 4af693e71f004690c05aede9648ff863d4bc36ed
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/DesignPatterns.Mediator.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/DesignPatterns.Mediator.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/DesignPatterns.Mediator.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 91fd9d9cc6cff6b4dea9f4f44059b5206ef06cb9
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/DesignPatterns.Mediator.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/DesignPatterns.Mediator.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Mediator/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/DesignPatterns.Mediator.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "xu6jD/+LI++toVeDHQFW91g6s+hehyqJCRf1cVCwv3JrbmoprmwPg0+z1Kqe5V3OhRZQ8tLe6cueOpKnl/Mfwg==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/DesignPatterns.Mediator.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Mediator/obj/DesignPatterns.Mediator.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/CareTaker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Memento
6 | {
7 | public class CareTaker
8 | {
9 | private List mementoList = new List();
10 |
11 | public void Add(Memento state)
12 | {
13 | mementoList.Add(state);
14 | }
15 |
16 | public Memento Get(int index)
17 | {
18 | return mementoList[index];
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/DesignPatterns.Memento.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/Memento.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Memento
6 | {
7 | public class Memento
8 | {
9 | private string state;
10 | public Memento(string state)
11 | {
12 | this.state = state;
13 | }
14 |
15 | public string GetState() => state;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/Originator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Memento
6 | {
7 | public class Originator
8 | {
9 | private string state;
10 | public void SetState(string state)
11 | {
12 | this.state = state;
13 | }
14 |
15 | public string GetState()
16 | {
17 | return state;
18 | }
19 |
20 | public Memento SaveStateToMemento()
21 | {
22 | return new Memento(this.state);
23 | }
24 |
25 | public void GetStateFromMemento(Memento memento)
26 | {
27 | state = memento.GetState();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Memento
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Originator originator = new Originator();
10 | CareTaker careTaker = new CareTaker();
11 | originator.SetState("State #1");
12 | originator.SetState("State #2");
13 | careTaker.Add(originator.SaveStateToMemento());
14 | originator.SetState("State #3");
15 | careTaker.Add(originator.SaveStateToMemento());
16 | originator.SetState("State #4");
17 |
18 | Console.WriteLine($"Current State:{originator.GetState()}");
19 | originator.GetStateFromMemento(careTaker.Get(0));
20 | Console.WriteLine($"First saved State:{originator.GetState()}");
21 | originator.GetStateFromMemento(careTaker.Get(1));
22 | Console.WriteLine($"Second saved State:{originator.GetState()}");
23 |
24 | Console.ReadKey();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/DesignPatterns.Memento.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Memento")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Memento")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Memento")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // 由 MSBuild WriteCodeFragment 类生成。
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/DesignPatterns.Memento.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 031ff17253c38b72c2a451baa4356844a5ba5477
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/DesignPatterns.Memento.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/DesignPatterns.Memento.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/DesignPatterns.Memento.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 6d3f936a2fbd63d7ed553ac52a94da972c363ef4
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/DesignPatterns.Memento.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/DesignPatterns.Memento.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Memento/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/DesignPatterns.Memento.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "UfZfAy7of+ymmXQLmRgt0Xacj4MggFhFfMD35XvgklmceXkwre9+f3QD3srWGzzz6cw+WeSly/wJWg42i5E6rg==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/DesignPatterns.Memento.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Memento/obj/DesignPatterns.Memento.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.NullObject/AbstractCustomer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.NullObject
6 | {
7 | public abstract class AbstractCustomer
8 | {
9 | protected string Name;
10 | public abstract bool IsNil();
11 | public abstract string GetName();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DesignPatterns.NullObject/CustomerFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.NullObject
6 | {
7 | public class CustomerFactory
8 | {
9 | public static readonly string[] names = { "Rob", "Joe", "Julie" };
10 |
11 | public static AbstractCustomer GetCustomer(string name)
12 | {
13 | for (int i = 0; i < names.Length; i++)
14 | {
15 | if (names[i] == name)
16 | return new RealCustomer(names[i]);
17 | }
18 | return new NullCustomer();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.NullObject/DesignPatterns.NullObject.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.NullObject/NullCustomer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.NullObject
6 | {
7 | public class NullCustomer : AbstractCustomer
8 | {
9 | public override string GetName()
10 | {
11 | return "Not Available in Customer Database";
12 | }
13 |
14 | public override bool IsNil()
15 | {
16 | return true;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/DesignPatterns.NullObject/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.NullObject
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | AbstractCustomer customer1 = CustomerFactory.GetCustomer("Rob");
10 | AbstractCustomer customer2 = CustomerFactory.GetCustomer("Bob");
11 | AbstractCustomer customer3 = CustomerFactory.GetCustomer("Julie");
12 | AbstractCustomer customer4 = CustomerFactory.GetCustomer("Laura");
13 | Console.WriteLine("Customers");
14 | Console.WriteLine(customer1.GetName());
15 | Console.WriteLine(customer2.GetName());
16 | Console.WriteLine(customer3.GetName());
17 | Console.WriteLine(customer4.GetName());
18 |
19 | Console.ReadKey();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/DesignPatterns.NullObject/RealCustomer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.NullObject
6 | {
7 | public class RealCustomer : AbstractCustomer
8 | {
9 | public RealCustomer(string name)
10 | {
11 | Name = name;
12 | }
13 | public override string GetName()
14 | {
15 | return this.Name;
16 | }
17 |
18 | public override bool IsNil()
19 | {
20 | return false;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/BinaryObserver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Observer
6 | {
7 | public class BinaryObserver : Observer
8 | {
9 | public BinaryObserver(Subject subject)
10 | {
11 | this.subject = subject;
12 | this.subject.Attach(this);
13 | }
14 |
15 | public override void Update()
16 | {
17 | Console.WriteLine($"Binary string:{subject.GetState()}");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/DesignPatterns.Observer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/HexaObserver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Observer
6 | {
7 | public class HexaObserver:Observer
8 | {
9 | public HexaObserver(Subject subject)
10 | {
11 | this.subject = subject;
12 | this.subject.Attach(this);
13 | }
14 |
15 | public override void Update()
16 | {
17 | Console.WriteLine($"Hex string:{subject.GetState()}");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/Observer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Observer
6 | {
7 | public abstract class Observer
8 | {
9 | protected Subject subject;
10 | public abstract void Update();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/OctalObserver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Observer
6 | {
7 | public class OctalObserver:Observer
8 | {
9 | public OctalObserver(Subject subject)
10 | {
11 | this.subject = subject;
12 | this.subject.Attach(this);
13 | }
14 |
15 | public override void Update()
16 | {
17 | Console.WriteLine($"Octal string:{subject.GetState()}");
18 |
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Observer
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Subject subject = new Subject();
10 |
11 | new HexaObserver(subject);
12 | new OctalObserver(subject);
13 | new BinaryObserver(subject);
14 | Console.WriteLine("First state change:15");
15 | subject.SetState(15);
16 | Console.WriteLine("Second state change:10");
17 | subject.SetState(10);
18 |
19 | Console.ReadKey();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/Subject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Observer
6 | {
7 | public class Subject
8 | {
9 | private List observers = new List();
10 |
11 | private int state;
12 | public int GetState() => this.state;
13 |
14 | public void SetState(int state)
15 | {
16 | this.state = state;
17 | NitifyAllObservers();
18 | }
19 |
20 | public void Attach(Observer observer)
21 | {
22 | observers.Add(observer);
23 | }
24 |
25 | private void NitifyAllObservers()
26 | {
27 | foreach (var observer in observers)
28 | {
29 | observer.Update();
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/DesignPatterns.Observer.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Observer")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Observer")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Observer")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // 由 MSBuild WriteCodeFragment 类生成。
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/DesignPatterns.Observer.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 549616249ed923e07e39bacbaaaee759dbd7d4cc
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/DesignPatterns.Observer.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/DesignPatterns.Observer.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/DesignPatterns.Observer.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 9cf1f8077520c3ebb7a2050f59c0d429b7067964
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Observer/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/DesignPatterns.Observer.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "XNCTq19LrMI94LDK7TCNewVjDXNdrjxWZb/NxhvYuKqW8c2CbgdofIvBg3/UHB6Al1PQyHFZ7eQxquHQjEGkpw==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/DesignPatterns.Observer.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Observer/obj/DesignPatterns.Observer.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/DesignPatterns.ProtoType.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.ProtoType
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | ShapeCache.LoadCache();
10 |
11 | Shape clonedShape1 = (Shape) ShapeCache.GetShape("1");
12 | Console.WriteLine(clonedShape1.GetType());
13 | clonedShape1.Draw();
14 |
15 | Shape clonedShape2 = (Shape)ShapeCache.GetShape("2");
16 | Console.WriteLine(clonedShape2.GetType());
17 | clonedShape2.Draw();
18 |
19 | Shape clonedShape3 = (Shape)ShapeCache.GetShape("3");
20 | Console.WriteLine(clonedShape3.GetType());
21 | clonedShape3.Draw();
22 |
23 | Console.ReadKey();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/ShapeCache.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 |
5 | namespace DesignPatterns.ProtoType
6 | {
7 | public class ShapeCache
8 | {
9 | private static HashSet shapeMap = new HashSet();
10 |
11 | public static Shape GetShape(string shapeId)
12 | {
13 | var cachedShape = shapeMap.FirstOrDefault(p => p.GetId() == shapeId);
14 | return (Shape) cachedShape?.Clone();
15 | }
16 |
17 | public static void LoadCache()
18 | {
19 | Circle circle = new Circle();
20 | circle.SetId("1");
21 | shapeMap.Add(circle);
22 |
23 |
24 | Square square = new Square();
25 | square.SetId("2");
26 | shapeMap.Add(square);
27 |
28 | Rectangle rectangle = new Rectangle();
29 | rectangle.SetId("3");
30 | shapeMap.Add(rectangle);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/DesignPatterns.ProtoType.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.ProtoType")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.ProtoType")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.ProtoType")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // 由 MSBuild WriteCodeFragment 类生成。
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/DesignPatterns.ProtoType.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 2885c0d6d6d2467ed913af56192c31c260f5ca6a
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/DesignPatterns.ProtoType.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/DesignPatterns.ProtoType.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/DesignPatterns.ProtoType.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 4784509f331d8dee4112da09342adc1ce0de78ce
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.ProtoType/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/DesignPatterns.ProtoType.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "evlX0vQbAIFp2VMG2uCUywUtTPj1oadUDPVxRTuvYqhWpKIkg4LuvxYEK9S6jJpaVwaCxc/M1OdE3iLYx7jvRQ==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/DesignPatterns.ProtoType.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.ProtoType/obj/DesignPatterns.ProtoType.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/DesignPatterns.Proxy.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/IImage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Proxy
6 | {
7 | public interface IImage
8 | {
9 | void Display();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Proxy
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | IImage image = new ProxyImage("test.png");
10 | image.Display();
11 |
12 | //继续访问时不会创建新对象
13 | image.Display();
14 | Console.ReadKey();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/ProxyImage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Proxy
6 | {
7 | public class ProxyImage : IImage
8 | {
9 | private RealImage realImage;
10 | private string fileName;
11 | public ProxyImage(string fileName)
12 | {
13 | this.fileName = fileName;
14 | }
15 |
16 | public void Display()
17 | {
18 | if (realImage == null)
19 | {
20 | realImage = new RealImage(fileName);
21 | }
22 | realImage.Display();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/README.md:
--------------------------------------------------------------------------------
1 | > 通过创建现有对象的对象,以便向外界通过访问接口,这种模式我们称之为代理模式
2 |
3 | ## 介绍
4 |
5 | 代理模式属于结构型模式,通过在对象与对象之间添加一个代理中间层来到达对目标对象的间接访问。
6 |
7 | ## 类图描述
8 |
9 | 
10 |
11 | 由上图可知,我们通过定义一个基本接口来约束业务行为,然后定义具体的业务实现该接口,最后通过定义一个代理类来协调上层和具体业务实体之间的访问,从而使上层也能访问到下层对象。
12 |
13 | ## 代码实现
14 |
15 | 1、创建接口
16 |
17 | ```C#
18 | public interface IImage
19 | {
20 | void Display();
21 | }
22 | ```
23 |
24 | 2、实现接口
25 |
26 | ```C#
27 | public class RealImage : IImage
28 | {
29 | private string fileName;
30 | public RealImage(string fileName)
31 | {
32 | this.fileName = fileName;
33 | LoadFromDisk();
34 | }
35 |
36 | public void Display() => Console.WriteLine($"Displaying:{fileName}");
37 | private void LoadFromDisk() => Console.WriteLine($"Loading:{fileName}");
38 | }
39 | ```
40 |
41 | 3、定义代理类
42 |
43 | ```C#
44 | public class ProxyImage : IImage
45 | {
46 | private RealImage realImage;
47 | private string fileName;
48 | public ProxyImage(string fileName)
49 | {
50 | this.fileName = fileName;
51 | }
52 |
53 | public void Display()
54 | {
55 | if (realImage == null)
56 | {
57 | realImage = new RealImage(fileName);
58 | }
59 | realImage.Display();
60 | }
61 | }
62 | ```
63 |
64 | 4、上层调用
65 |
66 | ```C#
67 | class Program
68 | {
69 | static void Main(string[] args)
70 | {
71 | IImage image = new ProxyImage("test.png");
72 | image.Display();
73 |
74 | //继续访问时不会创建新对象
75 | image.Display();
76 |
77 | Console.ReadKey();
78 | }
79 | }
80 | ```
81 |
82 | ## 总结
83 |
84 | 当上层访问下次对象时,由于业务的需要,我们需要对下层对象进行一个处理,这个时候可以考虑使用代理模式来解决,这个模式带来的好处是保证了现有底层对象不变的情况下进行了访问控制。
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/RealImage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Proxy
6 | {
7 | public class RealImage : IImage
8 | {
9 | private string fileName;
10 | public RealImage(string fileName)
11 | {
12 | this.fileName = fileName;
13 | LoadFromDisk();
14 | }
15 |
16 | public void Display() => Console.WriteLine($"Displaying:{fileName}");
17 | private void LoadFromDisk() => Console.WriteLine($"Loading:{fileName}");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/DesignPatterns.Proxy.AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 |
14 | [assembly: System.Reflection.AssemblyCompanyAttribute("DesignPatterns.Proxy")]
15 | [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16 | [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18 | [assembly: System.Reflection.AssemblyProductAttribute("DesignPatterns.Proxy")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("DesignPatterns.Proxy")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/DesignPatterns.Proxy.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 490f24d483b4377c89b59556e3a0202bd3bc51b4
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/DesignPatterns.Proxy.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/DesignPatterns.Proxy.assets.cache
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/DesignPatterns.Proxy.csproj.CoreCompileInputs.cache:
--------------------------------------------------------------------------------
1 | 3783e478893384a2432921cac8303e5a5e105145
2 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hippieZhou/DesignPatterns/ec07880af7751faae86f7514d0ee929747931efe/src/DesignPatterns.Proxy/obj/Debug/netcoreapp2.1/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/DesignPatterns.Proxy.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "J4RHcMOhsb+9V06BtpkBnHpSpVTlsL3g5Wha18qEU/QFJhR5r845iPQ6nXcUFK+0FVmD3YKoPRewuYtX9rLBrw==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/DesignPatterns.Proxy.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\hippieZhou\.nuget\packages\;C:\Program Files\dotnet\sdk\NuGetFallbackFolder
9 | PackageReference
10 | 5.4.0
11 |
12 |
13 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Proxy/obj/DesignPatterns.Proxy.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Singleton/DesignPatterns.Singleton.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Singleton/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Singleton
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 |
10 | SingleObject.GetInstance().ShowMessage();
11 | Console.ReadKey();
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.State/Context.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.State
4 | {
5 | public class Context
6 | {
7 | private static IState state;
8 |
9 | public void SetState(IState state) => Context.state = state;
10 |
11 | public IState GetState() => state;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.State/DesignPatterns.State.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.State/IState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.State
6 | {
7 | public interface IState
8 | {
9 | void DoAction(Context context);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.State/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.State
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Context context = new Context();
10 | IState startState = new StartState();
11 | startState.DoAction(context);
12 |
13 | Console.WriteLine(context.GetState().ToString());
14 |
15 | IState stopState = new StopState();
16 | stopState.DoAction(context);
17 | Console.WriteLine(context.GetState().ToString());
18 |
19 | Console.ReadKey();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/DesignPatterns.State/StartState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Threading;
5 |
6 | namespace DesignPatterns.State
7 | {
8 | public class StartState : IState
9 | {
10 | public void DoAction(Context context)
11 | {
12 | Console.WriteLine("Player is in start state");
13 | context.SetState(this);
14 | }
15 |
16 | public override string ToString()
17 | {
18 | return "Start State";
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.State/StopState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.State
6 | {
7 | public class StopState : IState
8 | {
9 | public void DoAction(Context context)
10 | {
11 | Console.WriteLine("Player is in stop state");
12 | context.SetState(this);
13 | }
14 |
15 | public override string ToString()
16 | {
17 | return "Stop State";
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Strategy/Context.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Strategy
6 | {
7 | public class Context
8 | {
9 | private readonly IStrategy _strategy;
10 | public Context(IStrategy strategy) => _strategy = strategy;
11 |
12 | public int ExecuteStrategy(int num1, int num2) => _strategy.DoOperation(num1, num2);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Strategy/DesignPatterns.Strategy.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Strategy/IStrategy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Strategy
6 | {
7 | public interface IStrategy
8 | {
9 | int DoOperation(int num1, int num2);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Strategy/OperationAdd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Strategy
6 | {
7 | public class OperationAdd : IStrategy
8 | {
9 | public int DoOperation(int num1, int num2) => num1 + num2;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Strategy/OperationMultiply.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Strategy
6 | {
7 | public class OperationMultiply : IStrategy
8 | {
9 | public int DoOperation(int num1, int num2) => num1 * num2;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Strategy/OperationSubstract.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Strategy
6 | {
7 | public class OperationSubstract : IStrategy
8 | {
9 | public int DoOperation(int num1, int num2) => num1 - num2;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Strategy/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Strategy
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Context context = new Context(new OperationAdd());
10 | Console.WriteLine($"10 + 5 = {context.ExecuteStrategy(10, 5)}");
11 |
12 | context = new Context(new OperationSubstract());
13 | Console.WriteLine($"10 - 5 = {context.ExecuteStrategy(10, 5)}");
14 |
15 | context = new Context(new OperationMultiply());
16 | Console.WriteLine($"10 * 5 = {context.ExecuteStrategy(10, 5)}");
17 |
18 | Console.ReadKey();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Strategy/README.md:
--------------------------------------------------------------------------------
1 | > 在策略模式中,一个类的行为或其算法可以在运行时更改。
2 |
3 | ## 介绍
4 |
5 | 策略模式属于行为型模式,通过将一系列通用算法封装起来,使它们能够动态替换,而不是通过一大堆条件语句进行选择判断。
6 |
7 | ## 类图描述
8 |
9 | 
10 |
11 | ## 代码实现
12 |
13 | 1、定义策略接口
14 | ```C#
15 | public interface IStrategy
16 | {
17 | int DoOperation(int num1, int num2);
18 | }
19 | ```
20 |
21 | 2、实现策略
22 | ```C#
23 | public class OperationAdd : IStrategy
24 | {
25 | public int DoOperation(int num1, int num2) => num1 + num2;
26 | }
27 |
28 | public class OperationMultiply : IStrategy
29 | {
30 | public int DoOperation(int num1, int num2) => num1 * num2;
31 | }
32 |
33 | public class OperationSubstract : IStrategy
34 | {
35 | public int DoOperation(int num1, int num2) => num1 - num2;
36 | }
37 | ```
38 |
39 | 3、封装策略
40 | ```C#
41 | public class Context
42 | {
43 | private readonly IStrategy _strategy;
44 | public Context(IStrategy strategy) => _strategy = strategy;
45 |
46 | public int ExecuteStrategy(int num1, int num2) => _strategy.DoOperation(num1, num2);
47 | }
48 | ```
49 |
50 | 4、上层调用
51 | ```C#
52 | class Program
53 | {
54 | static void Main(string[] args)
55 | {
56 | Context context = new Context(new OperationAdd());
57 | Console.WriteLine($"10 + 5 = {context.ExecuteStrategy(10, 5)}");
58 |
59 | context = new Context(new OperationSubstract());
60 | Console.WriteLine($"10 - 5 = {context.ExecuteStrategy(10, 5)}");
61 |
62 | context = new Context(new OperationMultiply());
63 | Console.WriteLine($"10 * 5 = {context.ExecuteStrategy(10, 5)}");
64 |
65 | Console.ReadKey();
66 | }
67 | }
68 | ```
69 |
70 | ## 总结
71 |
72 | 策略模式的出现是为了解决条件语句判断的难维护,简化了策略选择的代码复杂度。
--------------------------------------------------------------------------------
/src/DesignPatterns.Template/Cricket.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Template
6 | {
7 | public class Cricket : Game
8 | {
9 | public override void EndPlay()
10 | {
11 | Console.WriteLine("Cricket Game Finished");
12 | }
13 |
14 | public override void Initialize()
15 | {
16 | Console.WriteLine("Cricket Game Initialized!Start palying");
17 | }
18 |
19 | public override void StartPlay()
20 | {
21 | Console.WriteLine("Cricket Game Started.Enjoy the game");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Template/DesignPatterns.Template.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Template/Football.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Template
6 | {
7 | public class Football : Game
8 | {
9 | public override void StartPlay()
10 | {
11 | Console.WriteLine("Football Game Started.Enjog the game");
12 | }
13 |
14 | public override void Initialize()
15 | {
16 | Console.WriteLine("Football Game Initialized.Start playing.");
17 | }
18 |
19 | public override void EndPlay()
20 | {
21 | Console.WriteLine("Football Game Finished.");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Template/Game.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Template
6 | {
7 | public abstract class Game
8 | {
9 | public abstract void Initialize();
10 | public abstract void StartPlay();
11 | public abstract void EndPlay();
12 |
13 | public void Play()
14 | {
15 | Initialize();
16 | StartPlay();
17 | EndPlay();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Template/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Template
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Game game = new Cricket();
10 | game.Play();
11 |
12 | game = new Football();
13 | game.Play();
14 |
15 | Console.ReadKey();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/Computer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Visitor
6 | {
7 | public class Computer : IComputerPart
8 | {
9 | readonly IComputerPart[] parts;
10 | public Computer() => parts = new IComputerPart[] { new Mouse(), new Keyboard(), new Monitor() };
11 |
12 | public void Accept(ComputerPartVisitor computerPartVisitor)
13 | {
14 | for (int i = 0; i < parts.Length; i++)
15 | {
16 | parts[i].Accept(computerPartVisitor);
17 | }
18 | computerPartVisitor.Visit(this);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/ComputerPartDisplayVisitor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Visitor
6 | {
7 | public class ComputerPartDisplayVisitor : ComputerPartVisitor
8 | {
9 | public override void Visit(Computer computer)
10 | {
11 | Console.WriteLine("Displaying computer");
12 | }
13 |
14 | public override void Visit(Mouse mouse)
15 | {
16 | Console.WriteLine("Displaying mouse");
17 | }
18 |
19 | public override void Visit(Keyboard keyboard)
20 | {
21 | Console.WriteLine("Displaying keyboard");
22 | }
23 |
24 | public override void Visit(Monitor monitor)
25 | {
26 | Console.WriteLine("Displaying monitor");
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/ComputerPartVisitor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Visitor
4 | {
5 | public abstract class ComputerPartVisitor
6 | {
7 | public abstract void Visit(Computer computer);
8 | public abstract void Visit(Mouse mouse);
9 | public abstract void Visit(Keyboard keyboard);
10 | public abstract void Visit(Monitor monitor);
11 | }
12 | }
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/DesignPatterns.Visitor.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/IComputerPart.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Visitor
6 | {
7 | public interface IComputerPart
8 | {
9 | void Accept(ComputerPartVisitor computerPartVisitor);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/Keyboard.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Visitor
6 | {
7 | public class Keyboard : IComputerPart
8 | {
9 | public void Accept(ComputerPartVisitor computerPartVisitor)
10 | {
11 | computerPartVisitor.Visit(this);
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/Monitor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Visitor
6 | {
7 | public class Monitor : IComputerPart
8 | {
9 | public void Accept(ComputerPartVisitor computerPartVisitor)
10 | {
11 | computerPartVisitor.Visit(this);
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/Mouse.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DesignPatterns.Visitor
6 | {
7 | public class Mouse : IComputerPart
8 | {
9 | public void Accept(ComputerPartVisitor computerPartVisitor)
10 | {
11 | computerPartVisitor.Visit(this);
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/DesignPatterns.Visitor/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DesignPatterns.Visitor
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | IComputerPart computer = new Computer();
10 | computer.Accept(new ComputerPartDisplayVisitor());
11 | Console.ReadKey();
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------