├── .gitignore
├── Project
├── AbstractFactoryConsole
│ ├── AbstractFactory.cd
│ ├── AbstractFactory
│ │ └── VehicleFactory.cs
│ ├── AbstractFactoryConsole.csproj
│ ├── AbstractProduct
│ │ ├── Bike.cs
│ │ ├── Car.cs
│ │ └── Scooter.cs
│ ├── Client
│ │ └── VehicleClient.cs
│ ├── ConcreteFactory
│ │ ├── HondaFactory.cs
│ │ └── SuzukiFactory.cs
│ ├── ConcreteProduct
│ │ ├── RegularBike.cs
│ │ ├── RegularCar.cs
│ │ ├── RegularScooter.cs
│ │ ├── Scooty.cs
│ │ ├── SportsBike.cs
│ │ └── SportsCar.cs
│ └── Program.cs
├── AdapterConsole
│ ├── Adaptee
│ │ └── HRSystem.cs
│ ├── Adapter
│ │ └── EmployeeAdapter.cs
│ ├── AdapterConsole.csproj
│ ├── Client
│ │ └── ThirdPartyBillingSystem.cs
│ ├── Interfaces
│ │ └── ITarget.cs
│ ├── Program.cs
│ └── obj
│ │ └── Debug
│ │ └── netcoreapp3.0
│ │ └── AdapterConsole.AssemblyInfo.cs
├── BridgeConsole
│ ├── Abstraction
│ │ └── Message.cs
│ ├── Bridge
│ │ └── IMessageSender.cs
│ ├── BridgeConsole.csproj
│ ├── Implementation
│ │ ├── EmailSender.cs
│ │ ├── MSMQSender.cs
│ │ └── WebServiceSender.cs
│ ├── Program.cs
│ └── RefinedAbstraction
│ │ ├── SystemMessage.cs
│ │ └── UserMessage.cs
├── BuilderConsole
│ ├── Builder.cd
│ ├── BuilderConsole.csproj
│ ├── BuilderInterface
│ │ └── IVehicleBuilder.cs
│ ├── ConcreteBuilder
│ │ ├── FerrariBuilder.cs
│ │ └── HondaBuilder.cs
│ ├── Director
│ │ └── VehicleCreator.cs
│ ├── Product
│ │ └── Vehicle.cs
│ ├── Program.cs
│ ├── bin
│ │ └── Debug
│ │ │ └── netcoreapp3.0
│ │ │ ├── BuilderConsole.deps.json
│ │ │ ├── BuilderConsole.dll
│ │ │ ├── BuilderConsole.exe
│ │ │ ├── BuilderConsole.pdb
│ │ │ ├── BuilderConsole.runtimeconfig.dev.json
│ │ │ └── BuilderConsole.runtimeconfig.json
│ └── obj
│ │ ├── BuilderConsole.csproj.nuget.cache
│ │ ├── BuilderConsole.csproj.nuget.dgspec.json
│ │ ├── BuilderConsole.csproj.nuget.g.props
│ │ ├── BuilderConsole.csproj.nuget.g.targets
│ │ ├── Debug
│ │ └── netcoreapp3.0
│ │ │ ├── BuilderConsole.AssemblyInfo.cs
│ │ │ ├── BuilderConsole.AssemblyInfoInputs.cache
│ │ │ ├── BuilderConsole.assets.cache
│ │ │ ├── BuilderConsole.csproj.FileListAbsolute.txt
│ │ │ ├── BuilderConsole.csprojAssemblyReference.cache
│ │ │ ├── BuilderConsole.dll
│ │ │ ├── BuilderConsole.exe
│ │ │ └── BuilderConsole.pdb
│ │ └── project.assets.json
├── ChainOfResponsibilityConsole
│ ├── ChainOfResponsibilityConsole.csproj
│ ├── ConcreteHandler
│ │ ├── AssistantManager.cs
│ │ ├── Clerk.cs
│ │ └── Manager.cs
│ ├── Handler
│ │ └── Approver.cs
│ ├── InternalProcess
│ │ ├── Loan.cs
│ │ └── LoanEventArgs.cs
│ └── Program.cs
├── CommandConsole
│ ├── Command
│ │ └── ICommand.cs
│ ├── CommandConsole.csproj
│ ├── ConcreteCommand
│ │ ├── FlipDownCommand.cs
│ │ └── FlipUpCommand.cs
│ ├── Invoker
│ │ └── Switch.cs
│ ├── Program.cs
│ └── Receiver
│ │ └── Light.cs
├── CompositeConsole
│ ├── Component
│ │ └── IEmployed.cs
│ ├── Composite
│ │ └── Employee.cs
│ ├── CompositeConsole.csproj
│ ├── Leaf
│ │ └── Contractor.cs
│ └── Program.cs
├── DecoratorConsole
│ ├── Component
│ │ └── IVehicle.cs
│ ├── ConcreteComponent
│ │ ├── HondaCity.cs
│ │ └── SpecialOffer.cs
│ ├── Decorator
│ │ └── VehicleDecorator.cs
│ ├── DecoratorConsole.csproj
│ └── Program.cs
├── Design-Patterns.sln
├── FacadeConsole
│ ├── Facade
│ │ └── CarFacade.cs
│ ├── FacadeConsole.csproj
│ ├── Program.cs
│ └── Subsystem
│ │ ├── CarAccessories.cs
│ │ ├── CarBody.cs
│ │ ├── CarEngine.cs
│ │ └── CarModel.cs
├── FactoryMethodConsole
│ ├── ConcreateCreator
│ │ └── ConcreteVehicleFactory.cs
│ ├── ConcreateProduct
│ │ ├── Bike.cs
│ │ └── Scooter.cs
│ ├── Creator
│ │ └── VehicleFactory.cs
│ ├── FactoryMethodConsole.csproj
│ ├── Interface
│ │ └── IFactory.cs
│ └── Program.cs
├── FlyweightConsole
│ ├── ConcreteFlyweight
│ │ ├── Circle.cs
│ │ └── Rectangle.cs
│ ├── Flyweight
│ │ └── IShape.cs
│ ├── FlyweightConsole.csproj
│ ├── FlyweightFactory
│ │ └── ShapeObjectFactory.cs
│ └── Program.cs
├── InterpreterConsole
│ ├── Client
│ │ └── Client.cs
│ ├── Context
│ │ └── Context.cs
│ ├── Expression
│ │ └── IExpression.cs
│ ├── InterpreterConsole.csproj
│ ├── NonterminalExpression
│ │ └── NonterminalExpression.cs
│ ├── Program.cs
│ └── TerminalExpression
│ │ └── TerminalExpression.cs
├── IteratorConsole
│ ├── Aggregate
│ │ └── IAggregate.cs
│ ├── Client
│ │ └── Client.cs
│ ├── ConcreteAggregate
│ │ └── ConcreteAggregate.cs
│ ├── ConcreteIterator
│ │ └── ConcreteIterator.cs
│ ├── Iterator
│ │ └── Iterator.cs
│ ├── IteratorConsole.csproj
│ └── Program.cs
├── MediatorConsole
│ ├── CollegueClasses
│ │ ├── Colleague.cs
│ │ ├── ConcreteColleagueA.cs
│ │ └── ConcreteColleagueB.cs
│ ├── ConcreteMediator
│ │ └── ConcreteMediator.cs
│ ├── Mediator
│ │ └── IMediator.cs
│ ├── MediatorConsole.csproj
│ └── Program.cs
├── MementoConsole
│ ├── Caretaker
│ │ └── Caretaker.cs
│ ├── Memento
│ │ ├── ConcreteMemento.cs
│ │ └── IMemento.cs
│ ├── MementoConsole.csproj
│ ├── Originator
│ │ └── Originator.cs
│ └── Program.cs
├── ObserverConsole
│ ├── ConcreteObserver
│ │ ├── ConcreteObserverA.cs
│ │ └── ConcreteObserverB.cs
│ ├── Observer
│ │ └── IObserver.cs
│ ├── ObserverConsole.csproj
│ ├── Program.cs
│ └── Subject
│ │ ├── ISubject.cs
│ │ └── Subject.cs
├── PrototypeConsole
│ ├── Developer .cs
│ ├── Interfaces
│ │ └── IEmployee.cs
│ ├── Manager.cs
│ ├── Program.cs
│ ├── PrototypeConsole.csproj
│ └── obj
│ │ ├── Debug
│ │ └── netcoreapp3.0
│ │ │ └── PrototypeConsole.AssemblyInfo.cs
│ │ └── project.assets.json
├── ProxyConsole
│ ├── Program.cs
│ ├── Proxy
│ │ └── ProxyClient.cs
│ ├── ProxyConsole.csproj
│ ├── RealSubject
│ │ └── RealClient.cs
│ └── Subject
│ │ └── IClient.cs
├── SingletonConsole
│ ├── Program.cs
│ ├── SingletonConsole.csproj
│ ├── SingletonThreadSafe.cs
│ └── SingletonWrong.cs
├── StateConsole
│ ├── ConcreteState
│ │ ├── ConcreteStateA.cs
│ │ └── ConcreteStateB.cs
│ ├── Context
│ │ └── Context.cs
│ ├── Program.cs
│ ├── State
│ │ └── State.cs
│ └── StateConsole.csproj
├── StrategyConsole
│ ├── ConcreteStrategy
│ │ ├── PositionEquities.cs
│ │ └── PositionFunds.cs
│ ├── Context
│ │ └── Context.cs
│ ├── Model
│ │ └── CustomerPositionModel.cs
│ ├── Program.cs
│ ├── Strategy
│ │ └── IStrategy.cs
│ └── StrategyConsole.csproj
├── TemplateMethodConsole
│ ├── Abstract
│ │ └── AbstractClass.cs
│ ├── Client
│ │ └── Client.cs
│ ├── Concrete
│ │ ├── ConcreteClass1.cs
│ │ └── ConcreteClass2.cs
│ ├── Program.cs
│ └── TemplateMethodConsole.csproj
├── VisitorConsole
│ ├── Client
│ │ └── Client.cs
│ ├── ConcreteElement
│ │ ├── ConcreteElementA.cs
│ │ └── ConcreteElementB.cs
│ ├── ConcreteVisitor
│ │ ├── ConcreteVisitor1.cs
│ │ └── ConcreteVisitor2.cs
│ ├── Element
│ │ └── IElement.cs
│ ├── Program.cs
│ ├── Visitor
│ │ └── IVisitor.cs
│ └── VisitorConsole.csproj
└── gitignore
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/AbstractFactory.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAABAAAAAAAQAAAAAAAAAAAAAAAAACAAAAAAAAAAAA=
7 | ConcreteFactory\HondaFactory.cs
8 |
9 |
10 |
11 |
12 |
13 |
14 | AAAABAAAAAAAQAAAAAAAAAAAAAAAAACAAAAAAAAAAAA=
15 | ConcreteFactory\SuzukiFactory.cs
16 |
17 |
18 |
19 |
20 |
21 |
22 | AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=
23 | ConcreteProduct\RegularBike.cs
24 |
25 |
26 |
27 |
28 |
29 |
30 | AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=
31 | ConcreteProduct\RegularScooter.cs
32 |
33 |
34 |
35 |
36 |
37 |
38 | AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=
39 | ConcreteProduct\Scooty.cs
40 |
41 |
42 |
43 |
44 |
45 |
46 | AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=
47 | ConcreteProduct\SportsBike.cs
48 |
49 |
50 |
51 |
52 |
53 |
54 | AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=
55 | ConcreteProduct\SportsCar.cs
56 |
57 |
58 |
59 |
60 |
61 |
62 | AAAADAAAAEAAAAAAACAAAAAABAAAAAAAAAAAAAAAAAA=
63 | Client\VehicleClient.cs
64 |
65 |
66 |
67 |
68 |
69 | AAAABAAAAAAAQAAAAAAAAAAAAAAAAACAAAAAAAAAAAA=
70 | AbstractFactory\VehicleFactory.cs
71 |
72 |
73 |
74 |
75 |
76 | AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=
77 | AbstractProduct\Bike.cs
78 |
79 |
80 |
81 |
82 |
83 | AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=
84 | AbstractProduct\Car.cs
85 |
86 |
87 |
88 |
89 |
90 | AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA=
91 | AbstractProduct\Scooter.cs
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/AbstractFactory/VehicleFactory.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 |
3 | namespace AbstractFactoryConsole
4 | {
5 | public interface VehicleFactory
6 | {
7 | Bike GetBike(string bike);
8 | Scooter GetScooter(string scooter);
9 | Car GetCar(string car);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/AbstractFactoryConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/AbstractProduct/Bike.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace AbstractFactoryConsole.AbstractProduct
6 | {
7 | public interface Bike
8 | {
9 | string Name();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/AbstractProduct/Car.cs:
--------------------------------------------------------------------------------
1 | namespace AbstractFactoryConsole.AbstractProduct
2 | {
3 | public interface Car
4 | {
5 | string Name();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/AbstractProduct/Scooter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace AbstractFactoryConsole.AbstractProduct
6 | {
7 | public interface Scooter
8 | {
9 | string Name();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/Client/VehicleClient.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace AbstractFactoryConsole.Client
7 | {
8 | public class VehicleClient
9 | {
10 | Bike bike;
11 | Scooter scooter;
12 | Car car;
13 |
14 | public VehicleClient(VehicleFactory factory, string type)
15 | {
16 | bike = factory.GetBike(type);
17 | scooter = factory.GetScooter(type);
18 | car = factory.GetCar(type);
19 | }
20 |
21 | public string GetBikeName()
22 | {
23 | return bike.Name();
24 | }
25 |
26 | public string GetScooterName()
27 | {
28 | return scooter.Name();
29 | }
30 |
31 | public string GetCar()
32 | {
33 | return car.Name();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/ConcreteFactory/HondaFactory.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 | using AbstractFactoryConsole.ConcreteProduct;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace AbstractFactoryConsole.ConcreteFactory
8 | {
9 | class HondaFactory : VehicleFactory
10 | {
11 | public Bike GetBike(string bike)
12 | {
13 | switch (bike)
14 | {
15 | case "Sports":
16 | return new SportsBike();
17 | case "Regular":
18 | return new RegularBike();
19 | default:
20 | throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", bike));
21 | }
22 | }
23 |
24 | public Car GetCar(string car)
25 | {
26 | switch (car)
27 | {
28 | case "Sports":
29 | return new SportsCar();
30 | case "Regular":
31 | return new RegularCar();
32 | default:
33 | throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", car));
34 | }
35 | }
36 |
37 | public Scooter GetScooter(string scooter)
38 | {
39 | switch (scooter)
40 | {
41 | case "Sports":
42 | return new Scooty();
43 | case "Regular":
44 | return new RegularScooter();
45 | default:
46 | throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", scooter));
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/ConcreteFactory/SuzukiFactory.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 | using AbstractFactoryConsole.ConcreteProduct;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace AbstractFactoryConsole.ConcreteFactory
8 | {
9 | class SuzukiFactory : VehicleFactory
10 | {
11 | public Bike GetBike(string bike)
12 | {
13 | switch (bike)
14 | {
15 | case "Sports":
16 | return new SportsBike();
17 | case "Regular":
18 | return new RegularBike();
19 | default:
20 | throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", bike));
21 | }
22 |
23 | }
24 |
25 | public Car GetCar(string car)
26 | {
27 | switch (car)
28 | {
29 | case "Sports":
30 | return new SportsCar();
31 | case "Regular":
32 | return new RegularCar();
33 | default:
34 | throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", car));
35 | }
36 | }
37 |
38 | public Scooter GetScooter(string scooter)
39 | {
40 | switch (scooter)
41 | {
42 | case "Sports":
43 | return new Scooty();
44 | case "Regular":
45 | return new RegularScooter();
46 | default:
47 | throw new ApplicationException(string.Format("Vehicle '{0}' cannot be created", scooter));
48 | }
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/ConcreteProduct/RegularBike.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 |
3 | namespace AbstractFactoryConsole.ConcreteProduct
4 | {
5 | public class RegularBike : Bike
6 | {
7 | public string Name()
8 | {
9 | return "Regular Bike- Name";
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/ConcreteProduct/RegularCar.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace AbstractFactoryConsole.ConcreteProduct
7 | {
8 | public class RegularCar : Car
9 | {
10 | public string Name()
11 | {
12 | return "Regular Car- Name";
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/ConcreteProduct/RegularScooter.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace AbstractFactoryConsole.ConcreteProduct
7 | {
8 | public class RegularScooter : Scooter
9 | {
10 | public string Name()
11 | {
12 | return "Regular Scooter- Name";
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/ConcreteProduct/Scooty.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace AbstractFactoryConsole.ConcreteProduct
7 | {
8 | public class Scooty : Scooter
9 | {
10 | public string Name()
11 | {
12 | return "Scooty- Name";
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/ConcreteProduct/SportsBike.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 |
3 | namespace AbstractFactoryConsole.ConcreteProduct
4 | {
5 | public class SportsBike : Bike
6 | {
7 | public string Name()
8 | {
9 | return "Sports Bike- Name";
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/ConcreteProduct/SportsCar.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.AbstractProduct;
2 |
3 | namespace AbstractFactoryConsole.ConcreteProduct
4 | {
5 | public class SportsCar : Car
6 | {
7 | public string Name()
8 | {
9 | return "Sports Car - Name";
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/AbstractFactoryConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using AbstractFactoryConsole.Client;
2 | using AbstractFactoryConsole.ConcreteFactory;
3 | using System;
4 |
5 | namespace AbstractFactoryConsole
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | VehicleFactory honda = new HondaFactory();
12 |
13 | VehicleClient hondaclient = new VehicleClient(honda, "Regular");
14 | Console.WriteLine("******* Honda **********");
15 | Console.WriteLine(hondaclient.GetBikeName());
16 | Console.WriteLine(hondaclient.GetScooterName());
17 |
18 | hondaclient = new VehicleClient(honda, "Sports");
19 | Console.WriteLine(hondaclient.GetBikeName());
20 | Console.WriteLine(hondaclient.GetScooterName());
21 |
22 | hondaclient = new VehicleClient(honda, "Regular");
23 | Console.WriteLine(hondaclient.GetCar());
24 |
25 | VehicleFactory suzuki = new SuzukiFactory();
26 | VehicleClient suzukiClient = new VehicleClient(suzuki, "Regular");
27 |
28 | Console.WriteLine("******* Suzuki **********");
29 | Console.WriteLine(suzukiClient.GetBikeName());
30 | Console.WriteLine(suzukiClient.GetScooterName());
31 |
32 | suzukiClient = new VehicleClient(suzuki, "Sports");
33 | Console.WriteLine(suzukiClient.GetBikeName());
34 | Console.WriteLine(suzukiClient.GetScooterName());
35 |
36 | suzukiClient = new VehicleClient(honda, "Regular");
37 | Console.WriteLine(suzukiClient.GetCar());
38 |
39 | Console.ReadKey();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Project/AdapterConsole/Adaptee/HRSystem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace AdapterConsole
6 | {
7 | public class HRSystem
8 | {
9 | public string[][] GetEmployees()
10 | {
11 | string[][] employees = new string[4][];
12 |
13 | employees[0] = new string[] { "100", "Cesar Silva", "Coordenador de TI" };
14 | employees[1] = new string[] { "101", "Igor Kawata", "Coordenador de TI" };
15 | employees[2] = new string[] { "102", "Renato Novelli", "Desenvolvedor Senior" };
16 | employees[3] = new string[] { "103", "André Cirelli", "Product Owner" };
17 |
18 | return employees;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Project/AdapterConsole/Adapter/EmployeeAdapter.cs:
--------------------------------------------------------------------------------
1 | using AdapterConsole.Interfaces;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace AdapterConsole
7 | {
8 | public class EmployeeAdapter : HRSystem, ITarget
9 | {
10 | public List GetEmployeeList()
11 | {
12 | List employeeList = new List();
13 | string[][] employees = GetEmployees();
14 | foreach (string[] employee in employees)
15 | {
16 | employeeList.Add(employee[0]);
17 | employeeList.Add(",");
18 | employeeList.Add(employee[1]);
19 | employeeList.Add(",");
20 | employeeList.Add(employee[2]);
21 | employeeList.Add("\n");
22 | }
23 |
24 | return employeeList;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Project/AdapterConsole/AdapterConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/AdapterConsole/Client/ThirdPartyBillingSystem.cs:
--------------------------------------------------------------------------------
1 | using AdapterConsole.Interfaces;
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace AdapterConsole
6 | {
7 | public class ThirdPartyBillingSystem
8 | {
9 | private ITarget employeeSource;
10 |
11 | public ThirdPartyBillingSystem(ITarget employeeSource)
12 | {
13 | this.employeeSource = employeeSource;
14 | }
15 |
16 | public void ShowEmployeeList()
17 | {
18 | List employee = employeeSource.GetEmployeeList();
19 | //To DO: Implement you business logic
20 |
21 | Console.WriteLine("######### Lista de funcionários ##########");
22 | foreach (var item in employee)
23 | {
24 | Console.Write(item);
25 | }
26 | }
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/Project/AdapterConsole/Interfaces/ITarget.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace AdapterConsole.Interfaces
6 | {
7 | public interface ITarget
8 | {
9 | List GetEmployeeList();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/AdapterConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using AdapterConsole.Interfaces;
2 | using System;
3 |
4 | namespace AdapterConsole
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | ITarget Itarget = new EmployeeAdapter();
11 | ThirdPartyBillingSystem client = new ThirdPartyBillingSystem(Itarget);
12 | client.ShowEmployeeList();
13 |
14 | Console.ReadKey();
15 |
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Project/AdapterConsole/obj/Debug/netcoreapp3.0/AdapterConsole.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("AdapterConsole")]
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("AdapterConsole")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("AdapterConsole")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/Abstraction/Message.cs:
--------------------------------------------------------------------------------
1 | using BridgeConsole.Bridge;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace BridgeConsole.Abstraction
7 | {
8 | public abstract class Message
9 | {
10 | public IMessageSender MessageSender { get; set; }
11 | public string Subject { get; set; }
12 | public string Body { get; set; }
13 | public abstract void Send();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/Bridge/IMessageSender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace BridgeConsole.Bridge
6 | {
7 | public interface IMessageSender
8 | {
9 | void SendMessage(string subject, string body);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/BridgeConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/Implementation/EmailSender.cs:
--------------------------------------------------------------------------------
1 | using BridgeConsole.Bridge;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace BridgeConsole.Implementation
7 | {
8 | public class EmailSender : IMessageSender
9 | {
10 | public void SendMessage(string subject, string body)
11 | {
12 | Console.WriteLine($"Email\n{subject}\n{body}\n");
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/Implementation/MSMQSender.cs:
--------------------------------------------------------------------------------
1 | using BridgeConsole.Bridge;
2 | using System;
3 |
4 | namespace BridgeConsole.Implementation
5 | {
6 | public class MSMQSender : IMessageSender
7 | {
8 | public void SendMessage(string subject, string body)
9 | {
10 | Console.WriteLine($"MSMQ\n{subject}\n{body}\n");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/Implementation/WebServiceSender.cs:
--------------------------------------------------------------------------------
1 | using BridgeConsole.Bridge;
2 | using System;
3 |
4 | namespace BridgeConsole.Implementation
5 | {
6 | public class WebServiceSender : IMessageSender
7 | {
8 | public void SendMessage(string subject, string body)
9 | {
10 | Console.WriteLine($"Web Service\n{subject}\n{body}\n");
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using BridgeConsole.Abstraction;
2 | using BridgeConsole.Bridge;
3 | using BridgeConsole.Implementation;
4 | using BridgeConsole.RefinedAbstraction;
5 | using System;
6 |
7 | namespace BridgeConsole
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | IMessageSender email = new EmailSender();
14 | IMessageSender queue = new MSMQSender();
15 | IMessageSender web = new WebServiceSender();
16 |
17 | Message message = new SystemMessage();
18 | message.Subject = "Mensagem teste";
19 | message.Body = "Olá, Essa é uma mensagem de teste";
20 |
21 | message.MessageSender = email;
22 | message.Send();
23 |
24 | message.MessageSender = queue;
25 | message.Send();
26 |
27 | message.MessageSender = web;
28 | message.Send();
29 |
30 | UserMessage usermsg = new UserMessage();
31 | usermsg.Subject = "Mensagem Teste";
32 | usermsg.Body = "Olá, Essa é uma mensagem de teste";
33 | usermsg.UserComments = "Espero que todos consigam fazer o exemplo";
34 |
35 | usermsg.MessageSender = email;
36 | usermsg.Send();
37 |
38 | Console.ReadKey();
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/RefinedAbstraction/SystemMessage.cs:
--------------------------------------------------------------------------------
1 | using BridgeConsole.Abstraction;
2 |
3 | namespace BridgeConsole.RefinedAbstraction
4 | {
5 | public class SystemMessage : Message
6 | {
7 | public override void Send()
8 | {
9 | MessageSender.SendMessage(Subject, Body);
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/BridgeConsole/RefinedAbstraction/UserMessage.cs:
--------------------------------------------------------------------------------
1 | using BridgeConsole.Abstraction;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace BridgeConsole.RefinedAbstraction
7 | {
8 | public class UserMessage : Message
9 | {
10 | public string UserComments { get; set; }
11 |
12 | public override void Send()
13 | {
14 | string fullBody = string.Format("{0}\nUser Comments: {1}", Body, UserComments);
15 | MessageSender.SendMessage(Subject, fullBody);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/Builder.cd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | AAAAAQAACAAAAAAAAAAgAAgAAAAAJAAAQAAAAAAAAAA=
7 | ConcreteBuilder\FerrariBuilder.cs
8 |
9 |
10 |
11 |
12 |
13 |
14 | AAAAAQAACAAAAAAAAAAgAAgAAAAAJAAAQAAAAAAAAAA=
15 | ConcreteBuilder\HondaBuilder.cs
16 |
17 |
18 |
19 |
20 |
21 |
22 | AAQAAAAAAAAAAAAAAAAAAAAAABAABAAAAAAAAAAAAAA=
23 | Director\VehicleCreator.cs
24 |
25 |
26 |
27 |
28 |
29 | AAAAAAAAAAAAAAAABIABAAAAAAAAAAAABAgAAAAAgAA=
30 | Product\Vehicle.cs
31 |
32 |
33 |
34 |
35 |
36 | AAAAAQAACAAAAAAAAAAAAAgAAAAAJAAAQAAAAAAAAAA=
37 | BuilderInterface\IVehicleBuilder.cs
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/BuilderConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/BuilderInterface/IVehicleBuilder.cs:
--------------------------------------------------------------------------------
1 | namespace BuilderConsole.Interfaces
2 | {
3 | public interface IVehicleBuilder
4 | {
5 | void SetModel();
6 | void SetEngine();
7 | void SetTransmission();
8 | void SetBody();
9 | void SetAccessories();
10 |
11 | Vehicle GetVehicle();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/ConcreteBuilder/FerrariBuilder.cs:
--------------------------------------------------------------------------------
1 | using BuilderConsole.Interfaces;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace BuilderConsole
7 | {
8 | public class FerrariBuilder : IVehicleBuilder
9 | {
10 | Vehicle objVehicle = new Vehicle();
11 | public void SetModel()
12 | {
13 | objVehicle.Model = "Ferrari 360";
14 | }
15 |
16 | public void SetEngine()
17 | {
18 | objVehicle.Engine = "4 Stroke";
19 | }
20 |
21 | public void SetTransmission()
22 | {
23 | objVehicle.Transmission = "280 Km/hr";
24 | }
25 |
26 | public void SetBody()
27 | {
28 | objVehicle.Body = "Glass Fiber";
29 | }
30 |
31 | public void SetAccessories()
32 | {
33 | objVehicle.Accessories.Add("Seat Cover");
34 | objVehicle.Accessories.Add("Rear Mirror");
35 | objVehicle.Accessories.Add("Helmet");
36 | }
37 |
38 | public Vehicle GetVehicle()
39 | {
40 | return objVehicle;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/ConcreteBuilder/HondaBuilder.cs:
--------------------------------------------------------------------------------
1 | using BuilderConsole.Interfaces;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace BuilderConsole
7 | {
8 | public class HondaBuilder : IVehicleBuilder
9 | {
10 | Vehicle objVehicle = new Vehicle();
11 | public void SetModel()
12 | {
13 | objVehicle.Model = "Honda";
14 | }
15 |
16 | public void SetEngine()
17 | {
18 | objVehicle.Engine = "4 Stroke";
19 | }
20 |
21 | public void SetTransmission()
22 | {
23 | objVehicle.Transmission = "125 Km/hr";
24 | }
25 |
26 | public void SetBody()
27 | {
28 | objVehicle.Body = "Plastic";
29 | }
30 |
31 | public void SetAccessories()
32 | {
33 | objVehicle.Accessories.Add("Seat Cover");
34 | objVehicle.Accessories.Add("Rear Mirror");
35 | objVehicle.Accessories.Add("Helmet");
36 | }
37 |
38 | public Vehicle GetVehicle()
39 | {
40 | return objVehicle;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/Director/VehicleCreator.cs:
--------------------------------------------------------------------------------
1 | using BuilderConsole.Interfaces;
2 |
3 | namespace BuilderConsole
4 | {
5 | public class VehicleCreator
6 | {
7 | private readonly IVehicleBuilder objBuilder;
8 |
9 | public VehicleCreator(IVehicleBuilder builder)
10 | {
11 | objBuilder = builder;
12 | }
13 |
14 | public void CreateVehicle()
15 | {
16 | objBuilder.SetModel();
17 | objBuilder.SetEngine();
18 | objBuilder.SetBody();
19 | objBuilder.SetTransmission();
20 | objBuilder.SetAccessories();
21 | }
22 |
23 | public Vehicle GetVehicle()
24 | {
25 | return objBuilder.GetVehicle();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/Product/Vehicle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace BuilderConsole
6 | {
7 | public class Vehicle
8 | {
9 | public string Model { get; set; }
10 | public string Engine { get; set; }
11 | public string Transmission { get; set; }
12 | public string Body { get; set; }
13 | public List Accessories { get; set; }
14 |
15 | public Vehicle()
16 | {
17 | Accessories = new List();
18 | }
19 |
20 | public void ShowInfo()
21 | {
22 | Console.WriteLine("Model: {0}", Model);
23 | Console.WriteLine("Engine: {0}", Engine);
24 | Console.WriteLine("Body: {0}", Body);
25 | Console.WriteLine("Transmission: {0}", Transmission);
26 | Console.WriteLine("Accessories:");
27 | foreach (var accessory in Accessories)
28 | {
29 | Console.WriteLine("\t{0}", accessory);
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace BuilderConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | var vehicleCreator = new VehicleCreator(new FerrariBuilder());
10 | vehicleCreator.CreateVehicle();
11 | var vehicle = vehicleCreator.GetVehicle();
12 | vehicle.ShowInfo();
13 |
14 | Console.WriteLine("---------------------------------------------");
15 |
16 | vehicleCreator = new VehicleCreator(new HondaBuilder());
17 | vehicleCreator.CreateVehicle();
18 | vehicle = vehicleCreator.GetVehicle();
19 | vehicle.ShowInfo();
20 |
21 | Console.ReadKey();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.deps.json:
--------------------------------------------------------------------------------
1 | {
2 | "runtimeTarget": {
3 | "name": ".NETCoreApp,Version=v3.0",
4 | "signature": ""
5 | },
6 | "compilationOptions": {},
7 | "targets": {
8 | ".NETCoreApp,Version=v3.0": {
9 | "BuilderConsole/1.0.0": {
10 | "runtime": {
11 | "BuilderConsole.dll": {}
12 | }
13 | }
14 | }
15 | },
16 | "libraries": {
17 | "BuilderConsole/1.0.0": {
18 | "type": "project",
19 | "serviceable": false,
20 | "sha512": ""
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jonesroberto/design-patterns/cec69cb9dbbf274e9b6aa59b3b3afe879374d3ea/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.dll
--------------------------------------------------------------------------------
/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jonesroberto/design-patterns/cec69cb9dbbf274e9b6aa59b3b3afe879374d3ea/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.exe
--------------------------------------------------------------------------------
/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jonesroberto/design-patterns/cec69cb9dbbf274e9b6aa59b3b3afe879374d3ea/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.pdb
--------------------------------------------------------------------------------
/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.runtimeconfig.dev.json:
--------------------------------------------------------------------------------
1 | {
2 | "runtimeOptions": {
3 | "additionalProbingPaths": [
4 | "C:\\Users\\U001132\\.dotnet\\store\\|arch|\\|tfm|",
5 | "C:\\Users\\U001132\\.nuget\\packages",
6 | "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder"
7 | ]
8 | }
9 | }
--------------------------------------------------------------------------------
/Project/BuilderConsole/bin/Debug/netcoreapp3.0/BuilderConsole.runtimeconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "runtimeOptions": {
3 | "tfm": "netcoreapp3.0",
4 | "framework": {
5 | "name": "Microsoft.NETCore.App",
6 | "version": "3.0.0"
7 | }
8 | }
9 | }
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/BuilderConsole.csproj.nuget.cache:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "dgSpecHash": "SwIfK+P//+GtbrcKkNK6pWj2ILFJUuq7VOtXj5P7K3q1Nmz8cQyPdIBGmjAk+CsJnV3QKcAK/l9Ptmqg4vuC5Q==",
4 | "success": true
5 | }
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/BuilderConsole.csproj.nuget.dgspec.json:
--------------------------------------------------------------------------------
1 | {
2 | "format": 1,
3 | "restore": {
4 | "C:\\Git\\design-patterns\\Project\\BuilderConsole\\BuilderConsole.csproj": {}
5 | },
6 | "projects": {
7 | "C:\\Git\\design-patterns\\Project\\BuilderConsole\\BuilderConsole.csproj": {
8 | "version": "1.0.0",
9 | "restore": {
10 | "projectUniqueName": "C:\\Git\\design-patterns\\Project\\BuilderConsole\\BuilderConsole.csproj",
11 | "projectName": "BuilderConsole",
12 | "projectPath": "C:\\Git\\design-patterns\\Project\\BuilderConsole\\BuilderConsole.csproj",
13 | "packagesPath": "C:\\Users\\jones\\.nuget\\packages\\",
14 | "outputPath": "C:\\Git\\design-patterns\\Project\\BuilderConsole\\obj\\",
15 | "projectStyle": "PackageReference",
16 | "fallbackFolders": [
17 | "C:\\Microsoft\\Xamarin\\NuGet\\"
18 | ],
19 | "configFilePaths": [
20 | "C:\\Users\\jones\\AppData\\Roaming\\NuGet\\NuGet.Config",
21 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
22 | "C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
23 | ],
24 | "originalTargetFrameworks": [
25 | "netcoreapp3.0"
26 | ],
27 | "sources": {
28 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
29 | "https://api.nuget.org/v3/index.json": {}
30 | },
31 | "frameworks": {
32 | "netcoreapp3.0": {
33 | "targetAlias": "netcoreapp3.0",
34 | "projectReferences": {}
35 | }
36 | },
37 | "warningProperties": {
38 | "warnAsError": [
39 | "NU1605"
40 | ]
41 | }
42 | },
43 | "frameworks": {
44 | "netcoreapp3.0": {
45 | "targetAlias": "netcoreapp3.0",
46 | "imports": [
47 | "net461",
48 | "net462",
49 | "net47",
50 | "net471",
51 | "net472",
52 | "net48"
53 | ],
54 | "assetTargetFallback": true,
55 | "warn": true,
56 | "downloadDependencies": [
57 | {
58 | "name": "Microsoft.AspNetCore.App.Ref",
59 | "version": "[3.0.1, 3.0.1]"
60 | },
61 | {
62 | "name": "Microsoft.NETCore.App.Host.win-x64",
63 | "version": "[3.0.3, 3.0.3]"
64 | },
65 | {
66 | "name": "Microsoft.NETCore.App.Ref",
67 | "version": "[3.0.0, 3.0.0]"
68 | },
69 | {
70 | "name": "Microsoft.WindowsDesktop.App.Ref",
71 | "version": "[3.0.0, 3.0.0]"
72 | }
73 | ],
74 | "frameworkReferences": {
75 | "Microsoft.NETCore.App": {
76 | "privateAssets": "all"
77 | }
78 | },
79 | "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.100\\RuntimeIdentifierGraph.json"
80 | }
81 | }
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/BuilderConsole.csproj.nuget.g.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | True
5 | NuGet
6 | $(MSBuildThisFileDirectory)project.assets.json
7 | $(UserProfile)\.nuget\packages\
8 | C:\Users\jones\.nuget\packages\;C:\Microsoft\Xamarin\NuGet\
9 | PackageReference
10 | 5.8.0
11 |
12 |
13 |
14 |
15 |
16 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
17 |
18 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/BuilderConsole.csproj.nuget.g.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.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("BuilderConsole")]
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("BuilderConsole")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("BuilderConsole")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.AssemblyInfoInputs.cache:
--------------------------------------------------------------------------------
1 | 014f8e985dfaf3fd26060951d2214b3a3eb0b3e2
2 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.assets.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jonesroberto/design-patterns/cec69cb9dbbf274e9b6aa59b3b3afe879374d3ea/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.assets.cache
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\bin\Debug\netcoreapp3.0\BuilderConsole.exe
2 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\bin\Debug\netcoreapp3.0\BuilderConsole.deps.json
3 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\bin\Debug\netcoreapp3.0\BuilderConsole.runtimeconfig.json
4 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\bin\Debug\netcoreapp3.0\BuilderConsole.runtimeconfig.dev.json
5 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\bin\Debug\netcoreapp3.0\BuilderConsole.dll
6 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\bin\Debug\netcoreapp3.0\BuilderConsole.pdb
7 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\obj\Debug\netcoreapp3.0\BuilderConsole.csprojAssemblyReference.cache
8 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\obj\Debug\netcoreapp3.0\BuilderConsole.AssemblyInfoInputs.cache
9 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\obj\Debug\netcoreapp3.0\BuilderConsole.AssemblyInfo.cs
10 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\obj\Debug\netcoreapp3.0\BuilderConsole.dll
11 | C:\Users\U001132\Source\Repos\design-patterns\Project\BuilderConsole\obj\Debug\netcoreapp3.0\BuilderConsole.pdb
12 |
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.csprojAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jonesroberto/design-patterns/cec69cb9dbbf274e9b6aa59b3b3afe879374d3ea/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.csprojAssemblyReference.cache
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jonesroberto/design-patterns/cec69cb9dbbf274e9b6aa59b3b3afe879374d3ea/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.dll
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jonesroberto/design-patterns/cec69cb9dbbf274e9b6aa59b3b3afe879374d3ea/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.exe
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jonesroberto/design-patterns/cec69cb9dbbf274e9b6aa59b3b3afe879374d3ea/Project/BuilderConsole/obj/Debug/netcoreapp3.0/BuilderConsole.pdb
--------------------------------------------------------------------------------
/Project/BuilderConsole/obj/project.assets.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 3,
3 | "targets": {
4 | ".NETCoreApp,Version=v3.0": {}
5 | },
6 | "libraries": {},
7 | "projectFileDependencyGroups": {
8 | ".NETCoreApp,Version=v3.0": []
9 | },
10 | "packageFolders": {
11 | "C:\\Users\\jones\\.nuget\\packages\\": {},
12 | "C:\\Microsoft\\Xamarin\\NuGet\\": {}
13 | },
14 | "project": {
15 | "version": "1.0.0",
16 | "restore": {
17 | "projectUniqueName": "C:\\Git\\design-patterns\\Project\\BuilderConsole\\BuilderConsole.csproj",
18 | "projectName": "BuilderConsole",
19 | "projectPath": "C:\\Git\\design-patterns\\Project\\BuilderConsole\\BuilderConsole.csproj",
20 | "packagesPath": "C:\\Users\\jones\\.nuget\\packages\\",
21 | "outputPath": "C:\\Git\\design-patterns\\Project\\BuilderConsole\\obj\\",
22 | "projectStyle": "PackageReference",
23 | "fallbackFolders": [
24 | "C:\\Microsoft\\Xamarin\\NuGet\\"
25 | ],
26 | "configFilePaths": [
27 | "C:\\Users\\jones\\AppData\\Roaming\\NuGet\\NuGet.Config",
28 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
29 | "C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
30 | ],
31 | "originalTargetFrameworks": [
32 | "netcoreapp3.0"
33 | ],
34 | "sources": {
35 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
36 | "https://api.nuget.org/v3/index.json": {}
37 | },
38 | "frameworks": {
39 | "netcoreapp3.0": {
40 | "targetAlias": "netcoreapp3.0",
41 | "projectReferences": {}
42 | }
43 | },
44 | "warningProperties": {
45 | "warnAsError": [
46 | "NU1605"
47 | ]
48 | }
49 | },
50 | "frameworks": {
51 | "netcoreapp3.0": {
52 | "targetAlias": "netcoreapp3.0",
53 | "imports": [
54 | "net461",
55 | "net462",
56 | "net47",
57 | "net471",
58 | "net472",
59 | "net48"
60 | ],
61 | "assetTargetFallback": true,
62 | "warn": true,
63 | "downloadDependencies": [
64 | {
65 | "name": "Microsoft.AspNetCore.App.Ref",
66 | "version": "[3.0.1, 3.0.1]"
67 | },
68 | {
69 | "name": "Microsoft.NETCore.App.Host.win-x64",
70 | "version": "[3.0.3, 3.0.3]"
71 | },
72 | {
73 | "name": "Microsoft.NETCore.App.Ref",
74 | "version": "[3.0.0, 3.0.0]"
75 | },
76 | {
77 | "name": "Microsoft.WindowsDesktop.App.Ref",
78 | "version": "[3.0.0, 3.0.0]"
79 | }
80 | ],
81 | "frameworkReferences": {
82 | "Microsoft.NETCore.App": {
83 | "privateAssets": "all"
84 | }
85 | },
86 | "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.100\\RuntimeIdentifierGraph.json"
87 | }
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/Project/ChainOfResponsibilityConsole/ChainOfResponsibilityConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/ChainOfResponsibilityConsole/ConcreteHandler/AssistantManager.cs:
--------------------------------------------------------------------------------
1 | using ChainOfResponsibilityConsole.Handler;
2 | using ChainOfResponsibilityConsole.InternalProcess;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace ChainOfResponsibilityConsole.ConcreteHandler
8 | {
9 | class AssistantManager : Approver
10 | {
11 | public override void LoanHandler(object sender, LoanEventArgs e)
12 | {
13 | if (e.Loan.Amount < 45000)
14 | {
15 | Console.WriteLine($"{GetType().Name} approved request# {e.Loan.Number}");
16 | }
17 | else if (Successor != null)
18 | {
19 | Successor.LoanHandler(this, e);
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/ChainOfResponsibilityConsole/ConcreteHandler/Clerk.cs:
--------------------------------------------------------------------------------
1 | using ChainOfResponsibilityConsole.Handler;
2 | using ChainOfResponsibilityConsole.InternalProcess;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace ChainOfResponsibilityConsole.ConcreteHandler
8 | {
9 | class Clerk : Approver
10 | {
11 | public override void LoanHandler(object sender, LoanEventArgs e)
12 | {
13 | if (e.Loan.Amount < 25000)
14 | {
15 | Console.WriteLine($"{GetType().Name} approved request# {e.Loan.Number}");
16 | }
17 | else if (Successor != null)
18 | {
19 | Successor.LoanHandler(this, e);
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/ChainOfResponsibilityConsole/ConcreteHandler/Manager.cs:
--------------------------------------------------------------------------------
1 | using ChainOfResponsibilityConsole.Handler;
2 | using ChainOfResponsibilityConsole.InternalProcess;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace ChainOfResponsibilityConsole.ConcreteHandler
8 | {
9 | class Manager : Approver
10 | {
11 | public override void LoanHandler(object sender, LoanEventArgs e)
12 | {
13 | if (e.Loan.Amount < 100000)
14 | {
15 | Console.WriteLine($"{GetType().Name} approved request# {e.Loan.Number}");
16 | }
17 | else if (Successor != null)
18 | {
19 | Successor.LoanHandler(this, e);
20 | }
21 | else
22 | {
23 | Console.WriteLine(
24 | "Request# {0} requires an executive meeting!",
25 | e.Loan.Number);
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Project/ChainOfResponsibilityConsole/Handler/Approver.cs:
--------------------------------------------------------------------------------
1 | using ChainOfResponsibilityConsole.InternalProcess;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace ChainOfResponsibilityConsole.Handler
7 | {
8 | public abstract class Approver
9 | {
10 | // Loan event
11 | public EventHandler Loan;
12 |
13 | // Loan event handler
14 | public abstract void LoanHandler(object sender, LoanEventArgs e);
15 |
16 | // Constructor
17 | public Approver()
18 | {
19 | Loan += LoanHandler;
20 | }
21 |
22 | public void ProcessRequest(Loan loan)
23 | {
24 | OnLoan(new LoanEventArgs { Loan = loan });
25 | }
26 |
27 | // Invoke the Loan event
28 | public virtual void OnLoan(LoanEventArgs e)
29 | {
30 | if (Loan != null)
31 | {
32 | Loan(this, e);
33 | }
34 | }
35 |
36 | // Sets or gets the next approver
37 | public Approver Successor { get; set; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Project/ChainOfResponsibilityConsole/InternalProcess/Loan.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace ChainOfResponsibilityConsole.InternalProcess
6 | {
7 | public class Loan
8 | {
9 | public decimal Amount { get; set; }
10 | public string Purpose { get; set; }
11 | public int Number { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Project/ChainOfResponsibilityConsole/InternalProcess/LoanEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ChainOfResponsibilityConsole.InternalProcess
4 | {
5 | public class LoanEventArgs : EventArgs
6 | {
7 | internal Loan Loan { get; set; }
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/Project/ChainOfResponsibilityConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using ChainOfResponsibilityConsole.ConcreteHandler;
2 | using ChainOfResponsibilityConsole.Handler;
3 | using ChainOfResponsibilityConsole.InternalProcess;
4 | using System;
5 |
6 | namespace ChainOfResponsibilityConsole
7 | {
8 | class Program
9 | {
10 | static void Main(string[] args)
11 | {
12 | Approver diego = new Clerk();
13 | Approver cesar = new AssistantManager();
14 | Approver jones = new Manager();
15 |
16 | diego.Successor = cesar;
17 | cesar.Successor = jones;
18 |
19 | // Generate and process loan requests
20 | var loan = new Loan { Number = 2034, Amount = 23000, Purpose = "Car Loan" };
21 | diego.ProcessRequest(loan);
22 |
23 | loan = new Loan { Number = 2035, Amount = 44500, Purpose = "Motorcycle Loan" };
24 | diego.ProcessRequest(loan);
25 |
26 | loan = new Loan { Number = 2036, Amount = 156200, Purpose = "Apartament Loan" };
27 | diego.ProcessRequest(loan);
28 |
29 | Console.WriteLine("Press any key to continue!");
30 | Console.ReadKey();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Project/CommandConsole/Command/ICommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace CommandConsole.Command
6 | {
7 | public interface ICommand
8 | {
9 | void Execute();
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/Project/CommandConsole/CommandConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/CommandConsole/ConcreteCommand/FlipDownCommand.cs:
--------------------------------------------------------------------------------
1 | using CommandConsole.Command;
2 | using CommandConsole.Receiver;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace CommandConsole.ConcreteCommand
8 | {
9 | public class FlipDownCommand : ICommand
10 | {
11 | private Light _light;
12 |
13 | public FlipDownCommand(Light light)
14 | {
15 | _light = light;
16 | }
17 |
18 | public void Execute()
19 | {
20 | _light.TurnOff();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/CommandConsole/ConcreteCommand/FlipUpCommand.cs:
--------------------------------------------------------------------------------
1 | using CommandConsole.Command;
2 | using CommandConsole.Receiver;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace CommandConsole.ConcreteCommand
8 | {
9 | public class FlipUpCommand : ICommand
10 | {
11 | private Light _light;
12 |
13 | public FlipUpCommand(Light light)
14 | {
15 | _light = light;
16 | }
17 |
18 | public void Execute()
19 | {
20 | _light.TurnOn();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/CommandConsole/Invoker/Switch.cs:
--------------------------------------------------------------------------------
1 | using CommandConsole.Command;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace CommandConsole.Invoker
7 | {
8 | public class Switch
9 | {
10 | private List _commands = new List();
11 |
12 | public void StoreAndExecute(ICommand command)
13 | {
14 | _commands.Add(command);
15 | command.Execute();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Project/CommandConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using CommandConsole.Command;
2 | using CommandConsole.ConcreteCommand;
3 | using CommandConsole.Invoker;
4 | using CommandConsole.Receiver;
5 | using System;
6 |
7 | namespace CommandConsole
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | Console.WriteLine("Enter Commands (ON/OFF) : ");
14 | string cmd = Console.ReadLine();
15 |
16 | Light lamp = new Light();
17 | ICommand switchUp = new FlipUpCommand(lamp);
18 | ICommand switchDown = new FlipDownCommand(lamp);
19 |
20 | Switch s = new Switch();
21 |
22 | switch (cmd)
23 | {
24 | default:
25 | Console.WriteLine("Command \"ON\" or \"OFF\" is required.");
26 | break;
27 | case "ON":
28 | s.StoreAndExecute(switchUp);
29 | break;
30 | case "OFF":
31 | s.StoreAndExecute(switchDown);
32 | break;
33 | }
34 |
35 | Console.WriteLine("Press any key to exit!");
36 | Console.ReadKey();
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Project/CommandConsole/Receiver/Light.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace CommandConsole.Receiver
6 | {
7 | public class Light
8 | {
9 | public void TurnOn()
10 | {
11 | Console.WriteLine("The light is on");
12 | }
13 |
14 | public void TurnOff()
15 | {
16 | Console.WriteLine("The light is off");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Project/CompositeConsole/Component/IEmployed.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace CompositeConsole.Component
6 | {
7 | public interface IEmployed
8 | {
9 | int EmpID { get; set; }
10 | string Name { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/CompositeConsole/Composite/Employee.cs:
--------------------------------------------------------------------------------
1 | using CompositeConsole.Component;
2 | using System;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace CompositeConsole.Composite
8 | {
9 | public class Employee : IEmployed, IEnumerable
10 | {
11 | private List _subordinates = new List();
12 |
13 | public int EmpID { get; set; }
14 | public string Name { get; set; }
15 |
16 | public void AddSubordinate(IEmployed subordinate)
17 | {
18 | _subordinates.Add(subordinate);
19 | }
20 |
21 | public void RemoveSubordinate(IEmployed subordinate)
22 | {
23 | _subordinates.Remove(subordinate);
24 | }
25 |
26 | public IEmployed GetSubordinate(int index)
27 | {
28 | return _subordinates[index];
29 | }
30 |
31 | public IEnumerator GetEnumerator()
32 | {
33 | foreach (IEmployed subordinate in _subordinates)
34 | {
35 | yield return subordinate;
36 | }
37 | }
38 |
39 | IEnumerator IEnumerable.GetEnumerator()
40 | {
41 | return GetEnumerator();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Project/CompositeConsole/CompositeConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/CompositeConsole/Leaf/Contractor.cs:
--------------------------------------------------------------------------------
1 | using CompositeConsole.Component;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace CompositeConsole.Leaf
7 | {
8 | public class Contractor : IEmployed
9 | {
10 | public int EmpID { get; set; }
11 | public string Name { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Project/CompositeConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using CompositeConsole.Composite;
2 | using CompositeConsole.Leaf;
3 | using System;
4 |
5 | namespace CompositeConsole
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | Employee Thiago = new Employee { EmpID = 1, Name = "Thiago" };
12 |
13 | Employee Gabriel = new Employee { EmpID = 2, Name = "Gabriel" };
14 | Employee Jones = new Employee { EmpID = 3, Name = "Jones" };
15 |
16 | Thiago.AddSubordinate(Gabriel);
17 | Thiago.AddSubordinate(Jones);
18 |
19 | Employee Barbara = new Employee { EmpID = 4, Name = "Barbara" };
20 | Employee Andre = new Employee { EmpID = 5, Name = "André" };
21 |
22 | Gabriel.AddSubordinate(Barbara);
23 | Gabriel.AddSubordinate(Andre);
24 |
25 | Employee Cesar = new Employee { EmpID = 6, Name = "Cesar" };
26 | Employee Igor = new Employee { EmpID = 7, Name = "Igor" };
27 |
28 | Contractor Gisnando = new Contractor { EmpID = 8, Name = "Gisnando" };
29 | Contractor Gerlandio = new Contractor { EmpID = 9, Name = "Gerlandio" };
30 |
31 | Jones.AddSubordinate(Cesar);
32 | Jones.AddSubordinate(Igor);
33 | Jones.AddSubordinate(Gisnando);
34 | Jones.AddSubordinate(Gerlandio);
35 |
36 | Console.WriteLine($"EmpID={Thiago.EmpID}, Name={Thiago.Name}");
37 |
38 | foreach (Employee manager in Thiago)
39 | {
40 | Console.WriteLine($"\n EmpID={manager.EmpID}, Name={manager.Name}");
41 |
42 | foreach (var employee in manager)
43 | {
44 | Console.WriteLine($" \t EmpID={employee.EmpID}, Name={employee.Name}");
45 | }
46 | }
47 | Console.ReadKey();
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/Project/DecoratorConsole/Component/IVehicle.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace DecoratorConsole.Component
6 | {
7 | public interface IVehicle
8 | {
9 | string Make { get; }
10 | string Model { get; }
11 | double Price { get; }
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/Project/DecoratorConsole/ConcreteComponent/HondaCity.cs:
--------------------------------------------------------------------------------
1 | using DecoratorConsole.Component;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace DecoratorConsole.ConcreteComponent
7 | {
8 | public class HondaCity : IVehicle
9 | {
10 | public string Make
11 | {
12 | get { return "HondaCity"; }
13 | }
14 |
15 | public string Model
16 | {
17 | get { return "CNG"; }
18 | }
19 |
20 | public double Price
21 | {
22 | get { return 1000000; }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Project/DecoratorConsole/ConcreteComponent/SpecialOffer.cs:
--------------------------------------------------------------------------------
1 | using DecoratorConsole.Component;
2 | using DecoratorConsole.Decorator;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace DecoratorConsole.ConcreteComponent
8 | {
9 | public class SpecialOffer : VehicleDecorator
10 | {
11 | public SpecialOffer(IVehicle vehicle) : base(vehicle) { }
12 |
13 | public int DiscountPercentage { get; set; }
14 | public string Offer { get; set; }
15 |
16 | public double Price
17 | {
18 | get
19 | {
20 | double price = base.Price;
21 | int percentage = 100 - DiscountPercentage;
22 | return Math.Round((price * percentage) / 100, 2);
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Project/DecoratorConsole/Decorator/VehicleDecorator.cs:
--------------------------------------------------------------------------------
1 | using DecoratorConsole.Component;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace DecoratorConsole.Decorator
7 | {
8 | public abstract class VehicleDecorator : IVehicle
9 | {
10 | private IVehicle _vehicle;
11 |
12 | public VehicleDecorator(IVehicle vehicle)
13 | {
14 | _vehicle = vehicle;
15 | }
16 |
17 | public string Make
18 | {
19 | get { return _vehicle.Make; }
20 | }
21 |
22 | public string Model
23 | {
24 | get { return _vehicle.Model; }
25 | }
26 |
27 | public double Price
28 | {
29 | get { return _vehicle.Price; }
30 | }
31 |
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/Project/DecoratorConsole/DecoratorConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/DecoratorConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using DecoratorConsole.ConcreteComponent;
2 | using System;
3 |
4 | namespace DecoratorConsole
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | HondaCity car = new HondaCity();
11 |
12 | Console.WriteLine($"Honda City preço : {car.Price}");
13 |
14 | SpecialOffer offer = new SpecialOffer(car);
15 | offer.DiscountPercentage = 25;
16 | offer.Offer = "25 % de desconto";
17 |
18 | Console.WriteLine($"{offer.Price} @ Honda preço especial : {offer.Offer} ");
19 |
20 | Console.ReadKey();
21 |
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Project/Design-Patterns.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29001.49
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "FactoryMethod", "FactoryMethod", "{65DA8780-EEB8-4FB0-8227-843A06045A90}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AbstractFactory", "AbstractFactory", "{89F4E9F7-DAF7-4F9C-82AD-5BFE50A4B2B9}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFactoryConsole", "AbstractFactoryConsole\AbstractFactoryConsole.csproj", "{E3111B00-1029-4A63-B5A3-BAF377FFC37C}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Singleton", "Singleton", "{D88FE67B-EC57-4844-AF92-39F66D77ADE4}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SingletonConsole", "SingletonConsole\SingletonConsole.csproj", "{D7B31D1F-E544-4CA1-8A1D-5FCF33347749}"
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Builder", "Builder", "{84F2F5E3-E6D6-43C2-AB0C-FB6267A241D3}"
17 | EndProject
18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuilderConsole", "BuilderConsole\BuilderConsole.csproj", "{AF8EED7C-3B8D-41C8-8F5D-3C67F7991D60}"
19 | EndProject
20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Prototype", "Prototype", "{86D31135-0E04-4602-BB33-CE971174B2BF}"
21 | EndProject
22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrototypeConsole", "PrototypeConsole\PrototypeConsole.csproj", "{9D80477A-6FB8-4064-8391-F28423A01608}"
23 | EndProject
24 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Creational Patterns", "Creational Patterns", "{F9E3DCB3-6D36-4D88-8B96-CAD52E76619C}"
25 | EndProject
26 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Structural Patterns", "Structural Patterns", "{969C243F-4510-41D0-87C7-D65E4D6E49B1}"
27 | EndProject
28 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Adapter", "Adapter", "{200BF0FA-4606-44AA-9950-7E62E68D66A7}"
29 | EndProject
30 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdapterConsole", "AdapterConsole\AdapterConsole.csproj", "{C7D83C07-1F89-4348-BA58-1914C050BD2E}"
31 | EndProject
32 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bridge", "Bridge", "{A89DC050-CBD1-43EA-BBCA-AE4E29F32F44}"
33 | EndProject
34 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FactoryMethodConsole", "FactoryMethodConsole\FactoryMethodConsole.csproj", "{64FC6FFF-7C48-4763-8EFE-0032455FE7FC}"
35 | EndProject
36 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BridgeConsole", "BridgeConsole\BridgeConsole.csproj", "{40729A03-6AAC-4234-A839-6DFCC02DF51B}"
37 | EndProject
38 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Composite", "Composite", "{5C4477D0-1B20-4A11-8AC7-3A9842CE3D2D}"
39 | EndProject
40 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompositeConsole", "CompositeConsole\CompositeConsole.csproj", "{133A4C0F-6B42-4906-81B8-934552BD9ACF}"
41 | EndProject
42 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Decorator", "Decorator", "{3502B897-ED57-496D-AF3D-6BE20848BBCC}"
43 | EndProject
44 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DecoratorConsole", "DecoratorConsole\DecoratorConsole.csproj", "{2E6B0181-57CF-40AC-832D-7CA7ECCFE709}"
45 | EndProject
46 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Facade", "Facade", "{F262F211-4BC9-47AB-AFF1-B1EC130C1C26}"
47 | EndProject
48 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FacadeConsole", "FacadeConsole\FacadeConsole.csproj", "{29AB6516-5D3A-4EA1-8AD9-430A809CC0CA}"
49 | EndProject
50 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Proxy", "Proxy", "{49782F6C-B3EE-4AB7-A47E-770602F4E4C0}"
51 | EndProject
52 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProxyConsole", "ProxyConsole\ProxyConsole.csproj", "{4F155EE7-AB7C-4665-B270-AC4578CC98DC}"
53 | EndProject
54 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Flyweight", "Flyweight", "{65BBBF48-E306-4AE5-B2C5-50F41EE61CC3}"
55 | EndProject
56 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlyweightConsole", "FlyweightConsole\FlyweightConsole.csproj", "{56D78717-946E-4DCE-9D8A-A7563A904B93}"
57 | EndProject
58 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Behavioral Patterns", "Behavioral Patterns", "{45ED1732-BB3A-4B3A-BC61-40087C473D97}"
59 | EndProject
60 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainOfResponsibilityConsole", "ChainOfResponsibilityConsole\ChainOfResponsibilityConsole.csproj", "{9032E4E4-A0BC-4CEE-8EC1-65D460E4FB0A}"
61 | EndProject
62 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandConsole", "CommandConsole\CommandConsole.csproj", "{33891B8A-9383-4C51-946F-61C193892CBF}"
63 | EndProject
64 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediatorConsole", "MediatorConsole\MediatorConsole.csproj", "{BD1E14C7-44B3-45E4-9153-F20085277391}"
65 | EndProject
66 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MementoConsole", "MementoConsole\MementoConsole.csproj", "{F38F9C50-577F-432B-A2C1-3E59B2D2660D}"
67 | EndProject
68 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ObserverConsole", "ObserverConsole\ObserverConsole.csproj", "{07ABD4B1-5904-4215-A95B-F0B316976C5D}"
69 | EndProject
70 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StateConsole", "StateConsole\StateConsole.csproj", "{9AF7A93E-79A6-4DD8-B08E-C8832564F77B}"
71 | EndProject
72 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StrategyConsole", "StrategyConsole\StrategyConsole.csproj", "{C7CB0F2C-42D0-485E-9921-EC5348CB3644}"
73 | EndProject
74 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemplateMethodConsole", "TemplateMethodConsole\TemplateMethodConsole.csproj", "{0D0A3FB4-2E4B-4757-BFC9-2C15223755AD}"
75 | EndProject
76 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisitorConsole", "VisitorConsole\VisitorConsole.csproj", "{14E2B78F-6608-4979-8231-71A6B7F60B0C}"
77 | EndProject
78 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ChainOfResponsibility", "ChainOfResponsibility", "{3801CE30-47BD-4386-98A3-C07135078CE8}"
79 | EndProject
80 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Command", "Command", "{27FAD6DD-AF05-48D8-8A25-0900F0CDD56C}"
81 | EndProject
82 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Iterator", "Iterator", "{C61266C0-E946-4B72-B3B1-FC7ED257A94C}"
83 | EndProject
84 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mediator", "Mediator", "{F21C953C-CB85-4DEC-BC16-0C6FB1E9E772}"
85 | EndProject
86 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Memento", "Memento", "{329D74A5-1D66-4B60-9BF3-8DB15D2EB2AF}"
87 | EndProject
88 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Observer", "Observer", "{36DFBF79-6B66-45A9-9535-39D255E6410C}"
89 | EndProject
90 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "State", "State", "{47E0130A-8F26-45B7-87B0-45B5479E9877}"
91 | EndProject
92 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Strategy", "Strategy", "{83671615-23AC-4BF4-A40D-62BB3BA1FA58}"
93 | EndProject
94 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TemplateMethod", "TemplateMethod", "{19C0DDF9-A024-4EBA-A6F9-A7B61F500CD5}"
95 | EndProject
96 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Visitor", "Visitor", "{7BC9ADF1-688D-444C-9149-94CDDB0AE2BE}"
97 | EndProject
98 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interpreter", "Interpreter", "{826493C6-5E8B-48F1-AF67-3874B6769CC0}"
99 | EndProject
100 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InterpreterConsole", "InterpreterConsole\InterpreterConsole.csproj", "{C0C86BDE-373A-4E1B-A234-F7AAD6777C37}"
101 | EndProject
102 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IteratorConsole", "IteratorConsole\IteratorConsole.csproj", "{7721AA5D-72CC-4C79-BD6F-C80F166831CD}"
103 | EndProject
104 | Global
105 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
106 | Debug|Any CPU = Debug|Any CPU
107 | Release|Any CPU = Release|Any CPU
108 | EndGlobalSection
109 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
110 | {E3111B00-1029-4A63-B5A3-BAF377FFC37C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
111 | {E3111B00-1029-4A63-B5A3-BAF377FFC37C}.Debug|Any CPU.Build.0 = Debug|Any CPU
112 | {E3111B00-1029-4A63-B5A3-BAF377FFC37C}.Release|Any CPU.ActiveCfg = Release|Any CPU
113 | {E3111B00-1029-4A63-B5A3-BAF377FFC37C}.Release|Any CPU.Build.0 = Release|Any CPU
114 | {D7B31D1F-E544-4CA1-8A1D-5FCF33347749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
115 | {D7B31D1F-E544-4CA1-8A1D-5FCF33347749}.Debug|Any CPU.Build.0 = Debug|Any CPU
116 | {D7B31D1F-E544-4CA1-8A1D-5FCF33347749}.Release|Any CPU.ActiveCfg = Release|Any CPU
117 | {D7B31D1F-E544-4CA1-8A1D-5FCF33347749}.Release|Any CPU.Build.0 = Release|Any CPU
118 | {AF8EED7C-3B8D-41C8-8F5D-3C67F7991D60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119 | {AF8EED7C-3B8D-41C8-8F5D-3C67F7991D60}.Debug|Any CPU.Build.0 = Debug|Any CPU
120 | {AF8EED7C-3B8D-41C8-8F5D-3C67F7991D60}.Release|Any CPU.ActiveCfg = Release|Any CPU
121 | {AF8EED7C-3B8D-41C8-8F5D-3C67F7991D60}.Release|Any CPU.Build.0 = Release|Any CPU
122 | {9D80477A-6FB8-4064-8391-F28423A01608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
123 | {9D80477A-6FB8-4064-8391-F28423A01608}.Debug|Any CPU.Build.0 = Debug|Any CPU
124 | {9D80477A-6FB8-4064-8391-F28423A01608}.Release|Any CPU.ActiveCfg = Release|Any CPU
125 | {9D80477A-6FB8-4064-8391-F28423A01608}.Release|Any CPU.Build.0 = Release|Any CPU
126 | {C7D83C07-1F89-4348-BA58-1914C050BD2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
127 | {C7D83C07-1F89-4348-BA58-1914C050BD2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
128 | {C7D83C07-1F89-4348-BA58-1914C050BD2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
129 | {C7D83C07-1F89-4348-BA58-1914C050BD2E}.Release|Any CPU.Build.0 = Release|Any CPU
130 | {64FC6FFF-7C48-4763-8EFE-0032455FE7FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131 | {64FC6FFF-7C48-4763-8EFE-0032455FE7FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
132 | {64FC6FFF-7C48-4763-8EFE-0032455FE7FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
133 | {64FC6FFF-7C48-4763-8EFE-0032455FE7FC}.Release|Any CPU.Build.0 = Release|Any CPU
134 | {40729A03-6AAC-4234-A839-6DFCC02DF51B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
135 | {40729A03-6AAC-4234-A839-6DFCC02DF51B}.Debug|Any CPU.Build.0 = Debug|Any CPU
136 | {40729A03-6AAC-4234-A839-6DFCC02DF51B}.Release|Any CPU.ActiveCfg = Release|Any CPU
137 | {40729A03-6AAC-4234-A839-6DFCC02DF51B}.Release|Any CPU.Build.0 = Release|Any CPU
138 | {133A4C0F-6B42-4906-81B8-934552BD9ACF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
139 | {133A4C0F-6B42-4906-81B8-934552BD9ACF}.Debug|Any CPU.Build.0 = Debug|Any CPU
140 | {133A4C0F-6B42-4906-81B8-934552BD9ACF}.Release|Any CPU.ActiveCfg = Release|Any CPU
141 | {133A4C0F-6B42-4906-81B8-934552BD9ACF}.Release|Any CPU.Build.0 = Release|Any CPU
142 | {2E6B0181-57CF-40AC-832D-7CA7ECCFE709}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
143 | {2E6B0181-57CF-40AC-832D-7CA7ECCFE709}.Debug|Any CPU.Build.0 = Debug|Any CPU
144 | {2E6B0181-57CF-40AC-832D-7CA7ECCFE709}.Release|Any CPU.ActiveCfg = Release|Any CPU
145 | {2E6B0181-57CF-40AC-832D-7CA7ECCFE709}.Release|Any CPU.Build.0 = Release|Any CPU
146 | {29AB6516-5D3A-4EA1-8AD9-430A809CC0CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
147 | {29AB6516-5D3A-4EA1-8AD9-430A809CC0CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
148 | {29AB6516-5D3A-4EA1-8AD9-430A809CC0CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
149 | {29AB6516-5D3A-4EA1-8AD9-430A809CC0CA}.Release|Any CPU.Build.0 = Release|Any CPU
150 | {4F155EE7-AB7C-4665-B270-AC4578CC98DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
151 | {4F155EE7-AB7C-4665-B270-AC4578CC98DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
152 | {4F155EE7-AB7C-4665-B270-AC4578CC98DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
153 | {4F155EE7-AB7C-4665-B270-AC4578CC98DC}.Release|Any CPU.Build.0 = Release|Any CPU
154 | {56D78717-946E-4DCE-9D8A-A7563A904B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
155 | {56D78717-946E-4DCE-9D8A-A7563A904B93}.Debug|Any CPU.Build.0 = Debug|Any CPU
156 | {56D78717-946E-4DCE-9D8A-A7563A904B93}.Release|Any CPU.ActiveCfg = Release|Any CPU
157 | {56D78717-946E-4DCE-9D8A-A7563A904B93}.Release|Any CPU.Build.0 = Release|Any CPU
158 | {9032E4E4-A0BC-4CEE-8EC1-65D460E4FB0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
159 | {9032E4E4-A0BC-4CEE-8EC1-65D460E4FB0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
160 | {9032E4E4-A0BC-4CEE-8EC1-65D460E4FB0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
161 | {9032E4E4-A0BC-4CEE-8EC1-65D460E4FB0A}.Release|Any CPU.Build.0 = Release|Any CPU
162 | {33891B8A-9383-4C51-946F-61C193892CBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
163 | {33891B8A-9383-4C51-946F-61C193892CBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
164 | {33891B8A-9383-4C51-946F-61C193892CBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
165 | {33891B8A-9383-4C51-946F-61C193892CBF}.Release|Any CPU.Build.0 = Release|Any CPU
166 | {BD1E14C7-44B3-45E4-9153-F20085277391}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
167 | {BD1E14C7-44B3-45E4-9153-F20085277391}.Debug|Any CPU.Build.0 = Debug|Any CPU
168 | {BD1E14C7-44B3-45E4-9153-F20085277391}.Release|Any CPU.ActiveCfg = Release|Any CPU
169 | {BD1E14C7-44B3-45E4-9153-F20085277391}.Release|Any CPU.Build.0 = Release|Any CPU
170 | {F38F9C50-577F-432B-A2C1-3E59B2D2660D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
171 | {F38F9C50-577F-432B-A2C1-3E59B2D2660D}.Debug|Any CPU.Build.0 = Debug|Any CPU
172 | {F38F9C50-577F-432B-A2C1-3E59B2D2660D}.Release|Any CPU.ActiveCfg = Release|Any CPU
173 | {F38F9C50-577F-432B-A2C1-3E59B2D2660D}.Release|Any CPU.Build.0 = Release|Any CPU
174 | {07ABD4B1-5904-4215-A95B-F0B316976C5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
175 | {07ABD4B1-5904-4215-A95B-F0B316976C5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
176 | {07ABD4B1-5904-4215-A95B-F0B316976C5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
177 | {07ABD4B1-5904-4215-A95B-F0B316976C5D}.Release|Any CPU.Build.0 = Release|Any CPU
178 | {9AF7A93E-79A6-4DD8-B08E-C8832564F77B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
179 | {9AF7A93E-79A6-4DD8-B08E-C8832564F77B}.Debug|Any CPU.Build.0 = Debug|Any CPU
180 | {9AF7A93E-79A6-4DD8-B08E-C8832564F77B}.Release|Any CPU.ActiveCfg = Release|Any CPU
181 | {9AF7A93E-79A6-4DD8-B08E-C8832564F77B}.Release|Any CPU.Build.0 = Release|Any CPU
182 | {C7CB0F2C-42D0-485E-9921-EC5348CB3644}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
183 | {C7CB0F2C-42D0-485E-9921-EC5348CB3644}.Debug|Any CPU.Build.0 = Debug|Any CPU
184 | {C7CB0F2C-42D0-485E-9921-EC5348CB3644}.Release|Any CPU.ActiveCfg = Release|Any CPU
185 | {C7CB0F2C-42D0-485E-9921-EC5348CB3644}.Release|Any CPU.Build.0 = Release|Any CPU
186 | {0D0A3FB4-2E4B-4757-BFC9-2C15223755AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
187 | {0D0A3FB4-2E4B-4757-BFC9-2C15223755AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
188 | {0D0A3FB4-2E4B-4757-BFC9-2C15223755AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
189 | {0D0A3FB4-2E4B-4757-BFC9-2C15223755AD}.Release|Any CPU.Build.0 = Release|Any CPU
190 | {14E2B78F-6608-4979-8231-71A6B7F60B0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
191 | {14E2B78F-6608-4979-8231-71A6B7F60B0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
192 | {14E2B78F-6608-4979-8231-71A6B7F60B0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
193 | {14E2B78F-6608-4979-8231-71A6B7F60B0C}.Release|Any CPU.Build.0 = Release|Any CPU
194 | {C0C86BDE-373A-4E1B-A234-F7AAD6777C37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
195 | {C0C86BDE-373A-4E1B-A234-F7AAD6777C37}.Debug|Any CPU.Build.0 = Debug|Any CPU
196 | {C0C86BDE-373A-4E1B-A234-F7AAD6777C37}.Release|Any CPU.ActiveCfg = Release|Any CPU
197 | {C0C86BDE-373A-4E1B-A234-F7AAD6777C37}.Release|Any CPU.Build.0 = Release|Any CPU
198 | {7721AA5D-72CC-4C79-BD6F-C80F166831CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
199 | {7721AA5D-72CC-4C79-BD6F-C80F166831CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
200 | {7721AA5D-72CC-4C79-BD6F-C80F166831CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
201 | {7721AA5D-72CC-4C79-BD6F-C80F166831CD}.Release|Any CPU.Build.0 = Release|Any CPU
202 | EndGlobalSection
203 | GlobalSection(SolutionProperties) = preSolution
204 | HideSolutionNode = FALSE
205 | EndGlobalSection
206 | GlobalSection(NestedProjects) = preSolution
207 | {65DA8780-EEB8-4FB0-8227-843A06045A90} = {F9E3DCB3-6D36-4D88-8B96-CAD52E76619C}
208 | {89F4E9F7-DAF7-4F9C-82AD-5BFE50A4B2B9} = {F9E3DCB3-6D36-4D88-8B96-CAD52E76619C}
209 | {E3111B00-1029-4A63-B5A3-BAF377FFC37C} = {89F4E9F7-DAF7-4F9C-82AD-5BFE50A4B2B9}
210 | {D88FE67B-EC57-4844-AF92-39F66D77ADE4} = {F9E3DCB3-6D36-4D88-8B96-CAD52E76619C}
211 | {D7B31D1F-E544-4CA1-8A1D-5FCF33347749} = {D88FE67B-EC57-4844-AF92-39F66D77ADE4}
212 | {84F2F5E3-E6D6-43C2-AB0C-FB6267A241D3} = {F9E3DCB3-6D36-4D88-8B96-CAD52E76619C}
213 | {AF8EED7C-3B8D-41C8-8F5D-3C67F7991D60} = {84F2F5E3-E6D6-43C2-AB0C-FB6267A241D3}
214 | {86D31135-0E04-4602-BB33-CE971174B2BF} = {F9E3DCB3-6D36-4D88-8B96-CAD52E76619C}
215 | {9D80477A-6FB8-4064-8391-F28423A01608} = {86D31135-0E04-4602-BB33-CE971174B2BF}
216 | {200BF0FA-4606-44AA-9950-7E62E68D66A7} = {969C243F-4510-41D0-87C7-D65E4D6E49B1}
217 | {C7D83C07-1F89-4348-BA58-1914C050BD2E} = {200BF0FA-4606-44AA-9950-7E62E68D66A7}
218 | {A89DC050-CBD1-43EA-BBCA-AE4E29F32F44} = {969C243F-4510-41D0-87C7-D65E4D6E49B1}
219 | {64FC6FFF-7C48-4763-8EFE-0032455FE7FC} = {65DA8780-EEB8-4FB0-8227-843A06045A90}
220 | {40729A03-6AAC-4234-A839-6DFCC02DF51B} = {A89DC050-CBD1-43EA-BBCA-AE4E29F32F44}
221 | {5C4477D0-1B20-4A11-8AC7-3A9842CE3D2D} = {969C243F-4510-41D0-87C7-D65E4D6E49B1}
222 | {133A4C0F-6B42-4906-81B8-934552BD9ACF} = {5C4477D0-1B20-4A11-8AC7-3A9842CE3D2D}
223 | {3502B897-ED57-496D-AF3D-6BE20848BBCC} = {969C243F-4510-41D0-87C7-D65E4D6E49B1}
224 | {2E6B0181-57CF-40AC-832D-7CA7ECCFE709} = {3502B897-ED57-496D-AF3D-6BE20848BBCC}
225 | {F262F211-4BC9-47AB-AFF1-B1EC130C1C26} = {969C243F-4510-41D0-87C7-D65E4D6E49B1}
226 | {29AB6516-5D3A-4EA1-8AD9-430A809CC0CA} = {F262F211-4BC9-47AB-AFF1-B1EC130C1C26}
227 | {49782F6C-B3EE-4AB7-A47E-770602F4E4C0} = {969C243F-4510-41D0-87C7-D65E4D6E49B1}
228 | {4F155EE7-AB7C-4665-B270-AC4578CC98DC} = {49782F6C-B3EE-4AB7-A47E-770602F4E4C0}
229 | {65BBBF48-E306-4AE5-B2C5-50F41EE61CC3} = {969C243F-4510-41D0-87C7-D65E4D6E49B1}
230 | {56D78717-946E-4DCE-9D8A-A7563A904B93} = {65BBBF48-E306-4AE5-B2C5-50F41EE61CC3}
231 | {9032E4E4-A0BC-4CEE-8EC1-65D460E4FB0A} = {3801CE30-47BD-4386-98A3-C07135078CE8}
232 | {33891B8A-9383-4C51-946F-61C193892CBF} = {27FAD6DD-AF05-48D8-8A25-0900F0CDD56C}
233 | {BD1E14C7-44B3-45E4-9153-F20085277391} = {F21C953C-CB85-4DEC-BC16-0C6FB1E9E772}
234 | {F38F9C50-577F-432B-A2C1-3E59B2D2660D} = {329D74A5-1D66-4B60-9BF3-8DB15D2EB2AF}
235 | {07ABD4B1-5904-4215-A95B-F0B316976C5D} = {36DFBF79-6B66-45A9-9535-39D255E6410C}
236 | {9AF7A93E-79A6-4DD8-B08E-C8832564F77B} = {47E0130A-8F26-45B7-87B0-45B5479E9877}
237 | {C7CB0F2C-42D0-485E-9921-EC5348CB3644} = {83671615-23AC-4BF4-A40D-62BB3BA1FA58}
238 | {0D0A3FB4-2E4B-4757-BFC9-2C15223755AD} = {19C0DDF9-A024-4EBA-A6F9-A7B61F500CD5}
239 | {14E2B78F-6608-4979-8231-71A6B7F60B0C} = {7BC9ADF1-688D-444C-9149-94CDDB0AE2BE}
240 | {3801CE30-47BD-4386-98A3-C07135078CE8} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
241 | {27FAD6DD-AF05-48D8-8A25-0900F0CDD56C} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
242 | {C61266C0-E946-4B72-B3B1-FC7ED257A94C} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
243 | {F21C953C-CB85-4DEC-BC16-0C6FB1E9E772} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
244 | {329D74A5-1D66-4B60-9BF3-8DB15D2EB2AF} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
245 | {36DFBF79-6B66-45A9-9535-39D255E6410C} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
246 | {47E0130A-8F26-45B7-87B0-45B5479E9877} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
247 | {83671615-23AC-4BF4-A40D-62BB3BA1FA58} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
248 | {19C0DDF9-A024-4EBA-A6F9-A7B61F500CD5} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
249 | {7BC9ADF1-688D-444C-9149-94CDDB0AE2BE} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
250 | {826493C6-5E8B-48F1-AF67-3874B6769CC0} = {45ED1732-BB3A-4B3A-BC61-40087C473D97}
251 | {C0C86BDE-373A-4E1B-A234-F7AAD6777C37} = {826493C6-5E8B-48F1-AF67-3874B6769CC0}
252 | {7721AA5D-72CC-4C79-BD6F-C80F166831CD} = {C61266C0-E946-4B72-B3B1-FC7ED257A94C}
253 | EndGlobalSection
254 | GlobalSection(ExtensibilityGlobals) = postSolution
255 | SolutionGuid = {4A719260-6F47-4BE9-B8E5-ADE6B8382C2F}
256 | EndGlobalSection
257 | EndGlobal
258 |
--------------------------------------------------------------------------------
/Project/FacadeConsole/Facade/CarFacade.cs:
--------------------------------------------------------------------------------
1 | using FacadeConsole.Subsystem;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace FacadeConsole.Facade
7 | {
8 | public class CarFacade
9 | {
10 | CarModel model;
11 | CarEngine engine;
12 | CarBody body;
13 | CarAccessories accessories;
14 |
15 | public CarFacade()
16 | {
17 | model = new CarModel();
18 | engine = new CarEngine();
19 | body = new CarBody();
20 | accessories = new CarAccessories();
21 | }
22 |
23 | public void CreateCompleteCar()
24 | {
25 | Console.WriteLine("******** Creating a Car **********\n");
26 | model.SetModel();
27 | engine.SetEngine();
28 | body.SetBody();
29 | accessories.SetAccessories();
30 |
31 | Console.WriteLine("\n******** Car creation complete **********");
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/Project/FacadeConsole/FacadeConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/FacadeConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using FacadeConsole.Facade;
2 | using System;
3 |
4 | namespace FacadeConsole
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | CarFacade facade = new CarFacade();
11 |
12 | facade.CreateCompleteCar();
13 |
14 | Console.ReadKey();
15 |
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Project/FacadeConsole/Subsystem/CarAccessories.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FacadeConsole.Subsystem
6 | {
7 | class CarAccessories
8 | {
9 | public void SetAccessories()
10 | {
11 | Console.WriteLine(" CarAccessories - SetAccessories");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Project/FacadeConsole/Subsystem/CarBody.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FacadeConsole.Subsystem
6 | {
7 | class CarBody
8 | {
9 | public void SetBody()
10 | {
11 | Console.WriteLine(" CarBody - SetBody");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Project/FacadeConsole/Subsystem/CarEngine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FacadeConsole.Subsystem
6 | {
7 | class CarEngine
8 | {
9 | public void SetEngine()
10 | {
11 | Console.WriteLine(" CarEngine - SetEngine");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Project/FacadeConsole/Subsystem/CarModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FacadeConsole.Subsystem
6 | {
7 | class CarModel
8 | {
9 | public void SetModel()
10 | {
11 | Console.WriteLine(" CarModel - SetModel");
12 | }
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/Project/FactoryMethodConsole/ConcreateCreator/ConcreteVehicleFactory.cs:
--------------------------------------------------------------------------------
1 | using FactoryMethodConsole.ConcreateProduct;
2 | using FactoryMethodConsole.Creator;
3 | using System;
4 |
5 | namespace FactoryMethodConsole.ConcreateCreator
6 | {
7 | public class ConcreteVehicleFactory : VehicleFactory
8 | {
9 | public override IFactory GetVehicle(string Vehicle)
10 | {
11 | switch (Vehicle)
12 | {
13 | case "Scooter":
14 | return new Scooter();
15 | case "Bike":
16 | return new Bike();
17 | default:
18 | throw new ApplicationException($"Vehicle {Vehicle} cannot be created");
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Project/FactoryMethodConsole/ConcreateProduct/Bike.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FactoryMethodConsole.ConcreateProduct
6 | {
7 | public class Bike : IFactory
8 | {
9 | public void Drive(int miles)
10 | {
11 | Console.WriteLine($"Drive the Bike : {miles} km");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Project/FactoryMethodConsole/ConcreateProduct/Scooter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FactoryMethodConsole.ConcreateProduct
6 | {
7 | public class Scooter : IFactory
8 | {
9 | public void Drive(int miles)
10 | {
11 | Console.WriteLine($"Drive the Scooter : {miles} km");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Project/FactoryMethodConsole/Creator/VehicleFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FactoryMethodConsole.Creator
6 | {
7 | public abstract class VehicleFactory
8 | {
9 | public abstract IFactory GetVehicle(string vehicle);
10 |
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/FactoryMethodConsole/FactoryMethodConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Project/FactoryMethodConsole/Interface/IFactory.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FactoryMethodConsole
6 | {
7 | public interface IFactory
8 | {
9 | void Drive(int miles);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/FactoryMethodConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using FactoryMethodConsole;
2 | using FactoryMethodConsole.ConcreateCreator;
3 | using FactoryMethodConsole.Creator;
4 | using System;
5 |
6 | namespace DesignPatternsConsole
7 | {
8 | class Program
9 | {
10 | static void Main(string[] args)
11 | {
12 | VehicleFactory factory = new ConcreteVehicleFactory();
13 |
14 | IFactory scooter = factory.GetVehicle("Scooter");
15 | scooter.Drive(10);
16 |
17 | IFactory bike = factory.GetVehicle("Bike");
18 | bike.Drive(20);
19 |
20 | Console.ReadKey();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/FlyweightConsole/ConcreteFlyweight/Circle.cs:
--------------------------------------------------------------------------------
1 | using FlyweightConsole.Flyweight;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace FlyweightConsole.ConcreteFlyweight
7 | {
8 | class Circle : IShape
9 | {
10 | public void Print()
11 | {
12 | Console.WriteLine("Printing Circle");
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/FlyweightConsole/ConcreteFlyweight/Rectangle.cs:
--------------------------------------------------------------------------------
1 | using FlyweightConsole.Flyweight;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace FlyweightConsole.ConcreteFlyweight
7 | {
8 | class Rectangle : IShape
9 | {
10 | public void Print()
11 | {
12 | Console.WriteLine("Printing Rectangle");
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/FlyweightConsole/Flyweight/IShape.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace FlyweightConsole.Flyweight
6 | {
7 | interface IShape
8 | {
9 | void Print();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/FlyweightConsole/FlyweightConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/FlyweightConsole/FlyweightFactory/ShapeObjectFactory.cs:
--------------------------------------------------------------------------------
1 | using FlyweightConsole.ConcreteFlyweight;
2 | using FlyweightConsole.Flyweight;
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | namespace FlyweightConsole.FlyweightFactory
7 | {
8 | class ShapeObjectFactory
9 | {
10 | Dictionary shapes = new Dictionary();
11 |
12 | public int TotalObjectsCreated
13 | {
14 | get { return shapes.Count; }
15 | }
16 |
17 | public IShape GetShape(string ShapeName)
18 | {
19 | IShape shape = null;
20 | if (shapes.ContainsKey(ShapeName))
21 | {
22 | shape = shapes[ShapeName];
23 | }
24 | else
25 | {
26 | switch (ShapeName)
27 | {
28 | case "Rectangle":
29 | shape = new Rectangle();
30 | shapes.Add("Rectangle", shape);
31 | break;
32 | case "Circle":
33 | shape = new Circle();
34 | shapes.Add("Circle", shape);
35 | break;
36 | default:
37 | throw new Exception("Factory cannot create the object specified");
38 | }
39 | }
40 | return shape;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Project/FlyweightConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using FlyweightConsole.Flyweight;
2 | using FlyweightConsole.FlyweightFactory;
3 | using System;
4 |
5 | namespace FlyweightConsole
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | ShapeObjectFactory sof = new ShapeObjectFactory();
12 |
13 | IShape shape = sof.GetShape("Rectangle");
14 | shape.Print();
15 | shape = sof.GetShape("Rectangle");
16 | shape.Print();
17 | shape = sof.GetShape("Rectangle");
18 | shape.Print();
19 |
20 | shape = sof.GetShape("Circle");
21 | shape.Print();
22 | shape = sof.GetShape("Circle");
23 | shape.Print();
24 | shape = sof.GetShape("Circle");
25 | shape.Print();
26 |
27 | int NumObjs = sof.TotalObjectsCreated;
28 | Console.WriteLine("\nTotal No of Objects created = {0}", NumObjs);
29 | Console.ReadKey();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Project/InterpreterConsole/Client/Client.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace InterpreterConsole
6 | {
7 | public class Client
8 | {
9 | public void BuildAndInterpretCommands()
10 | {
11 | Context context = new Context("Dot Net context");
12 | NonterminalExpression root = new NonterminalExpression
13 | {
14 | Expression1 = new TerminalExpression(),
15 | Expression2 = new TerminalExpression()
16 | };
17 |
18 | root.Interpret(context);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Project/InterpreterConsole/Context/Context.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace InterpreterConsole
6 | {
7 | public class Context
8 | {
9 | public string Name { get; set; }
10 |
11 | public Context(string name)
12 | {
13 | Name = name;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Project/InterpreterConsole/Expression/IExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace InterpreterConsole
6 | {
7 | public interface IExpression
8 | {
9 | void Interpret(Context context);
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/Project/InterpreterConsole/InterpreterConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/InterpreterConsole/NonterminalExpression/NonterminalExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace InterpreterConsole
6 | {
7 | public class NonterminalExpression : IExpression
8 | {
9 | public IExpression Expression1 { get; set; }
10 |
11 | public IExpression Expression2 { get; set; }
12 |
13 | public void Interpret(Context context)
14 | {
15 | Console.WriteLine($"Nonterminal for {context.Name}.");
16 | Expression1.Interpret(context);
17 | Expression2.Interpret(context);
18 | }
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/Project/InterpreterConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace InterpreterConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Client client = new Client();
10 | client.BuildAndInterpretCommands();
11 |
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Project/InterpreterConsole/TerminalExpression/TerminalExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace InterpreterConsole
6 | {
7 | public class TerminalExpression : IExpression
8 | {
9 | public void Interpret(Context context)
10 | {
11 | Console.WriteLine($"Terminal for {context.Name}.");
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Project/IteratorConsole/Aggregate/IAggregate.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace IteratorConsole
6 | {
7 | public interface IAggregate
8 | {
9 | Iterator CreateIterator();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/IteratorConsole/Client/Client.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace IteratorConsole
6 | {
7 | public class Client
8 | {
9 | public void UseIterator()
10 | {
11 | ConcreteAggregate aggr = new ConcreteAggregate();
12 | aggr.Add("One");
13 | aggr.Add("Two");
14 | aggr.Add("Three");
15 | aggr.Add("Four");
16 | aggr.Add("Five");
17 |
18 | Iterator iterator = aggr.CreateIterator();
19 | while (iterator.Next())
20 | {
21 | string item = (string)iterator.Current;
22 | Console.WriteLine(item);
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Project/IteratorConsole/ConcreteAggregate/ConcreteAggregate.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace IteratorConsole
7 | {
8 | public class ConcreteAggregate : IAggregate
9 | {
10 | private ArrayList items = new ArrayList();
11 |
12 | public Iterator CreateIterator()
13 | {
14 | return new ConcreteIterator(this);
15 | }
16 |
17 | public object this[int index]
18 | {
19 | get { return items[index]; }
20 | }
21 |
22 | public int Count
23 | {
24 | get { return items.Count; }
25 | }
26 |
27 | public void Add(object o)
28 | {
29 | items.Add(o);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Project/IteratorConsole/ConcreteIterator/ConcreteIterator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace IteratorConsole
6 | {
7 | public class ConcreteIterator : Iterator
8 | {
9 | private ConcreteAggregate aggregate;
10 | int index;
11 |
12 | public ConcreteIterator(ConcreteAggregate aggregate)
13 | {
14 | this.aggregate = aggregate;
15 | index = -1;
16 | }
17 |
18 | public bool Next()
19 | {
20 | index++;
21 | return index < aggregate.Count;
22 | }
23 |
24 | public object Current
25 | {
26 | get
27 | {
28 | if (index < aggregate.Count)
29 | return aggregate[index];
30 | else
31 | throw new InvalidOperationException();
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Project/IteratorConsole/Iterator/Iterator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace IteratorConsole
6 | {
7 | public interface Iterator
8 | {
9 | object Current { get; }
10 | bool Next();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/IteratorConsole/IteratorConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/IteratorConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace IteratorConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Client client = new Client();
10 | client.UseIterator();
11 |
12 | Console.WriteLine("Press any key to continue!");
13 | Console.ReadKey();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Project/MediatorConsole/CollegueClasses/Colleague.cs:
--------------------------------------------------------------------------------
1 | using MediatorConsole.Mediator;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace MediatorConsole.CollegueClasses
7 | {
8 | public abstract class Colleague
9 | {
10 | protected IMediator _mediator;
11 |
12 | public Colleague(IMediator mediator)
13 | {
14 | _mediator = mediator;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Project/MediatorConsole/CollegueClasses/ConcreteColleagueA.cs:
--------------------------------------------------------------------------------
1 | using MediatorConsole.Mediator;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace MediatorConsole.CollegueClasses
7 | {
8 | public class ConcreteColleagueA : Colleague
9 | {
10 | public ConcreteColleagueA(IMediator mediator) : base(mediator) { }
11 |
12 | public void Send(string msg)
13 | {
14 | Console.WriteLine($"A send message:{msg}");
15 | _mediator.SendMessage(this, msg);
16 | }
17 |
18 | public void Receive(string msg)
19 | {
20 | Console.WriteLine($"A receive message:{msg}");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/MediatorConsole/CollegueClasses/ConcreteColleagueB.cs:
--------------------------------------------------------------------------------
1 | using MediatorConsole.Mediator;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace MediatorConsole.CollegueClasses
7 | {
8 | public class ConcreteColleagueB : Colleague
9 | {
10 | public ConcreteColleagueB(IMediator mediator) : base(mediator) { }
11 |
12 | public void Send(string msg)
13 | {
14 | Console.WriteLine($"B send message:{msg}");
15 | _mediator.SendMessage(this, msg);
16 | }
17 |
18 | public void Receive(string msg)
19 | {
20 | Console.WriteLine($"B receive message:{msg}");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/MediatorConsole/ConcreteMediator/ConcreteMediator.cs:
--------------------------------------------------------------------------------
1 | using MediatorConsole.CollegueClasses;
2 | using MediatorConsole.Mediator;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace MediatorConsole
8 | {
9 | public class ConcreteMediator : IMediator
10 | {
11 | public ConcreteColleagueA Colleague1 { get; set; }
12 |
13 | public ConcreteColleagueB Colleague2 { get; set; }
14 |
15 | public void SendMessage(Colleague caller, string msg)
16 | {
17 | if (caller == Colleague1)
18 | Colleague2.Receive(msg);
19 | else
20 | Colleague1.Receive(msg);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/MediatorConsole/Mediator/IMediator.cs:
--------------------------------------------------------------------------------
1 | using MediatorConsole.CollegueClasses;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace MediatorConsole.Mediator
7 | {
8 | public interface IMediator
9 | {
10 | void SendMessage(Colleague caller, string msg);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/MediatorConsole/MediatorConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/MediatorConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using MediatorConsole.CollegueClasses;
2 | using MediatorConsole.Mediator;
3 | using System;
4 |
5 | namespace MediatorConsole
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | ConcreteMediator mediator = new ConcreteMediator();
12 |
13 | mediator.Colleague1 = new ConcreteColleagueA(mediator);
14 | mediator.Colleague2 = new ConcreteColleagueB(mediator);
15 |
16 | mediator.SendMessage(mediator.Colleague1, "Message mediator 1");
17 | mediator.SendMessage(mediator.Colleague2, "Message mediator 2");
18 |
19 | Console.WriteLine("Press any key to continue!");
20 | Console.ReadKey();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Project/MementoConsole/Caretaker/Caretaker.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace MementoConsole
7 | {
8 | class Caretaker
9 | {
10 | private List _mementos = new List();
11 |
12 | private Originator _originator = null;
13 |
14 | public Caretaker(Originator originator)
15 | {
16 | this._originator = originator;
17 | }
18 |
19 | public void Backup()
20 | {
21 | Console.WriteLine("\nCaretaker: Saving Originator's state...");
22 | this._mementos.Add(this._originator.Save());
23 | }
24 |
25 | public void Undo()
26 | {
27 | if (this._mementos.Count == 0)
28 | {
29 | return;
30 | }
31 |
32 | var memento = this._mementos.Last();
33 | this._mementos.Remove(memento);
34 |
35 | Console.WriteLine($"Caretaker: Restoring state to: {memento.GetName()}");
36 |
37 | try
38 | {
39 | this._originator.Restore(memento);
40 | }
41 | catch (Exception)
42 | {
43 | this.Undo();
44 | }
45 | }
46 |
47 | public void ShowHistory()
48 | {
49 | Console.WriteLine("Caretaker: Here's the list of mementos:");
50 |
51 | foreach (var memento in this._mementos)
52 | {
53 | Console.WriteLine(memento.GetName());
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Project/MementoConsole/Memento/ConcreteMemento.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MementoConsole
4 | {
5 | class ConcreteMemento : IMemento
6 | {
7 | private string _state;
8 |
9 | private DateTime _date;
10 |
11 | public ConcreteMemento(string state)
12 | {
13 | this._state = state;
14 | this._date = DateTime.Now;
15 | }
16 |
17 | public string GetState()
18 | {
19 | return this._state;
20 | }
21 |
22 | public string GetName()
23 | {
24 | return $"{this._date} / ({this._state.Substring(0, 9)})...";
25 | }
26 |
27 | public DateTime GetDate()
28 | {
29 | return this._date;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Project/MementoConsole/Memento/IMemento.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace MementoConsole
6 | {
7 | public interface IMemento
8 | {
9 | string GetName();
10 |
11 | string GetState();
12 |
13 | DateTime GetDate();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/MementoConsole/MementoConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/MementoConsole/Originator/Originator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Threading;
5 |
6 | namespace MementoConsole
7 | {
8 | public class Originator
9 | {
10 | private string _state;
11 |
12 | public Originator(string state)
13 | {
14 | this._state = state;
15 | Console.WriteLine($"Originator: My initial state is: {state}");
16 | }
17 |
18 | public void DoSomething()
19 | {
20 | Console.WriteLine("Originator: I'm doing something important.");
21 | this._state = this.GenerateRandomString(30);
22 | Console.WriteLine($"Originator: and my state has changed to: {_state}");
23 | }
24 |
25 | private string GenerateRandomString(int length = 10)
26 | {
27 | string allowedSymbols = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
28 | string result = string.Empty;
29 |
30 | while (length > 0)
31 | {
32 | result += allowedSymbols[new Random().Next(0, allowedSymbols.Length)];
33 |
34 | Thread.Sleep(12);
35 |
36 | length--;
37 | }
38 |
39 | return result;
40 | }
41 |
42 | // Saves the current state inside a memento.
43 | public IMemento Save()
44 | {
45 | return new ConcreteMemento(this._state);
46 | }
47 |
48 | // Restores the Originator's state from a memento object.
49 | public void Restore(IMemento memento)
50 | {
51 | if (!(memento is ConcreteMemento))
52 | {
53 | throw new Exception($"Unknown memento class {memento}");
54 | }
55 |
56 | this._state = memento.GetState();
57 | Console.Write($"Originator: My state has changed to: {_state}");
58 | }
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/Project/MementoConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MementoConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // Client code.
10 | Originator originator = new Originator("Super-memento.");
11 | Caretaker caretaker = new Caretaker(originator);
12 |
13 | caretaker.Backup();
14 | originator.DoSomething();
15 |
16 | caretaker.Backup();
17 | originator.DoSomething();
18 |
19 | caretaker.Backup();
20 | originator.DoSomething();
21 |
22 | Console.WriteLine();
23 | caretaker.ShowHistory();
24 |
25 | Console.WriteLine("\nClient: Now, let's rollback!\n");
26 | caretaker.Undo();
27 |
28 | Console.WriteLine("\n\nClient: Once more!\n");
29 | caretaker.Undo();
30 |
31 | Console.WriteLine("Press any key to continue!");
32 | Console.ReadKey();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Project/ObserverConsole/ConcreteObserver/ConcreteObserverA.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace ObserverConsole
6 | {
7 | class ConcreteObserverA : IObserver
8 | {
9 | public void Update(ISubject subject)
10 | {
11 | if ((subject as Subject).State < 3)
12 | {
13 | Console.WriteLine("ConcreteObserverA: Reacted to the event.");
14 | }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Project/ObserverConsole/ConcreteObserver/ConcreteObserverB.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace ObserverConsole
6 | {
7 | class ConcreteObserverB : IObserver
8 | {
9 | public void Update(ISubject subject)
10 | {
11 | if ((subject as Subject).State == 0 || (subject as Subject).State >= 2)
12 | {
13 | Console.WriteLine("ConcreteObserverB: Reacted to the event.");
14 | }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Project/ObserverConsole/Observer/IObserver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace ObserverConsole
6 | {
7 | public interface IObserver
8 | {
9 | void Update(ISubject subject);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/ObserverConsole/ObserverConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/ObserverConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace ObserverConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | // The client code.
10 | var subject = new Subject();
11 | var observerA = new ConcreteObserverA();
12 | subject.Attach(observerA);
13 |
14 | var observerB = new ConcreteObserverB();
15 | subject.Attach(observerB);
16 |
17 | subject.SomeBusinessLogic();
18 | subject.SomeBusinessLogic();
19 |
20 | subject.Detach(observerB);
21 |
22 | subject.SomeBusinessLogic();
23 |
24 | Console.WriteLine("Press any key to continue!");
25 | Console.ReadKey();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Project/ObserverConsole/Subject/ISubject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace ObserverConsole
6 | {
7 | public interface ISubject
8 | {
9 | void Attach(IObserver observer);
10 |
11 | void Detach(IObserver observer);
12 |
13 | void Notify();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Project/ObserverConsole/Subject/Subject.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Threading;
5 |
6 | namespace ObserverConsole
7 | {
8 | public class Subject : ISubject
9 | {
10 | public int State { get; set; } = -0;
11 |
12 | private List _observers = new List();
13 |
14 | public void Attach(IObserver observer)
15 | {
16 | Console.WriteLine("Subject: Attached an observer.");
17 | this._observers.Add(observer);
18 | }
19 |
20 | public void Detach(IObserver observer)
21 | {
22 | this._observers.Remove(observer);
23 | Console.WriteLine("Subject: Detached an observer.");
24 | }
25 |
26 | public void Notify()
27 | {
28 | Console.WriteLine("Subject: Notifying observers...");
29 |
30 | foreach (var observer in _observers)
31 | {
32 | observer.Update(this);
33 | }
34 | }
35 |
36 | public void SomeBusinessLogic()
37 | {
38 | Console.WriteLine("\nSubject: I'm doing something important.");
39 | this.State = new Random().Next(0, 10);
40 |
41 | Thread.Sleep(15);
42 |
43 | Console.WriteLine("Subject: My state has just changed to: " + this.State);
44 | this.Notify();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/Project/PrototypeConsole/Developer .cs:
--------------------------------------------------------------------------------
1 | using PrototypeConsole.Interfaces;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace PrototypeConsole
7 | {
8 | public class Developer : IEmployee
9 | {
10 | public int WordsPerMinute { get; set; }
11 | public string Name { get; set; }
12 | public string Role { get; set; }
13 | public string PreferredLanguage { get; set; }
14 |
15 | public IEmployee Clone()
16 | {
17 | return (IEmployee)MemberwiseClone();
18 | }
19 |
20 | public string GetDetails()
21 | {
22 | return string.Format("{0} - {1} - {2}", Name, Role, PreferredLanguage);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Project/PrototypeConsole/Interfaces/IEmployee.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace PrototypeConsole.Interfaces
6 | {
7 | public interface IEmployee
8 | {
9 | IEmployee Clone();
10 | string GetDetails();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/PrototypeConsole/Manager.cs:
--------------------------------------------------------------------------------
1 | using PrototypeConsole.Interfaces;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace PrototypeConsole
7 | {
8 | public class Manager : IEmployee
9 | {
10 | public int WordsPerMinute { get; set; }
11 | public string Name { get; set; }
12 | public string Role { get; set; }
13 |
14 | public IEmployee Clone()
15 | {
16 | return (IEmployee)MemberwiseClone();
17 | }
18 |
19 | public string GetDetails()
20 | {
21 | return string.Format("{0} - {1} - {2}wpm", Name, Role, WordsPerMinute);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Project/PrototypeConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace PrototypeConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Developer dev = new Developer();
10 | dev.Name = "Cesar Silva";
11 | dev.Role = "Coordenador Ti";
12 | dev.PreferredLanguage = "C#";
13 |
14 | Developer devCopy = (Developer)dev.Clone();
15 | devCopy.Name = "Igor Kawata"; //Not mention Role and PreferredLanguage, it will copy above
16 |
17 | Console.WriteLine(dev.GetDetails());
18 | Console.WriteLine(devCopy.GetDetails());
19 |
20 | Manager manager = new Manager();
21 | manager.Name = "Jones Roberto";
22 | manager.Role = "Gerente";
23 | manager.WordsPerMinute = 120;
24 |
25 | Manager managerCopy = (Manager)manager.Clone();
26 | managerCopy.Name = "Leonidas Leme";
27 | managerCopy.WordsPerMinute = 110;//Not mention Role, it will copy above
28 |
29 | Console.WriteLine(manager.GetDetails());
30 | Console.WriteLine(managerCopy.GetDetails());
31 |
32 | Console.ReadKey();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Project/PrototypeConsole/PrototypeConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/PrototypeConsole/obj/Debug/netcoreapp3.0/PrototypeConsole.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("PrototypeConsole")]
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("PrototypeConsole")]
19 | [assembly: System.Reflection.AssemblyTitleAttribute("PrototypeConsole")]
20 | [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21 |
22 | // Generated by the MSBuild WriteCodeFragment class.
23 |
24 |
--------------------------------------------------------------------------------
/Project/PrototypeConsole/obj/project.assets.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 3,
3 | "targets": {
4 | ".NETCoreApp,Version=v3.0": {}
5 | },
6 | "libraries": {},
7 | "projectFileDependencyGroups": {
8 | ".NETCoreApp,Version=v3.0": []
9 | },
10 | "packageFolders": {
11 | "C:\\Users\\jones\\.nuget\\packages\\": {},
12 | "C:\\Microsoft\\Xamarin\\NuGet\\": {}
13 | },
14 | "project": {
15 | "version": "1.0.0",
16 | "restore": {
17 | "projectUniqueName": "C:\\Git\\design-patterns\\Project\\PrototypeConsole\\PrototypeConsole.csproj",
18 | "projectName": "PrototypeConsole",
19 | "projectPath": "C:\\Git\\design-patterns\\Project\\PrototypeConsole\\PrototypeConsole.csproj",
20 | "packagesPath": "C:\\Users\\jones\\.nuget\\packages\\",
21 | "outputPath": "C:\\Git\\design-patterns\\Project\\PrototypeConsole\\obj\\",
22 | "projectStyle": "PackageReference",
23 | "fallbackFolders": [
24 | "C:\\Microsoft\\Xamarin\\NuGet\\"
25 | ],
26 | "configFilePaths": [
27 | "C:\\Users\\jones\\AppData\\Roaming\\NuGet\\NuGet.Config",
28 | "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config",
29 | "C:\\Program Files (x86)\\NuGet\\Config\\Xamarin.Offline.config"
30 | ],
31 | "originalTargetFrameworks": [
32 | "netcoreapp3.0"
33 | ],
34 | "sources": {
35 | "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
36 | "https://api.nuget.org/v3/index.json": {}
37 | },
38 | "frameworks": {
39 | "netcoreapp3.0": {
40 | "targetAlias": "netcoreapp3.0",
41 | "projectReferences": {}
42 | }
43 | },
44 | "warningProperties": {
45 | "warnAsError": [
46 | "NU1605"
47 | ]
48 | }
49 | },
50 | "frameworks": {
51 | "netcoreapp3.0": {
52 | "targetAlias": "netcoreapp3.0",
53 | "imports": [
54 | "net461",
55 | "net462",
56 | "net47",
57 | "net471",
58 | "net472",
59 | "net48"
60 | ],
61 | "assetTargetFallback": true,
62 | "warn": true,
63 | "downloadDependencies": [
64 | {
65 | "name": "Microsoft.AspNetCore.App.Ref",
66 | "version": "[3.0.1, 3.0.1]"
67 | },
68 | {
69 | "name": "Microsoft.NETCore.App.Host.win-x64",
70 | "version": "[3.0.3, 3.0.3]"
71 | },
72 | {
73 | "name": "Microsoft.NETCore.App.Ref",
74 | "version": "[3.0.0, 3.0.0]"
75 | },
76 | {
77 | "name": "Microsoft.WindowsDesktop.App.Ref",
78 | "version": "[3.0.0, 3.0.0]"
79 | }
80 | ],
81 | "frameworkReferences": {
82 | "Microsoft.NETCore.App": {
83 | "privateAssets": "all"
84 | }
85 | },
86 | "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\5.0.100\\RuntimeIdentifierGraph.json"
87 | }
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/Project/ProxyConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using ProxyConsole.Proxy;
2 | using System;
3 |
4 | namespace ProxyConsole
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | var proxy = new ProxyClient();
11 | Console.WriteLine($"Data from Proxy Client = {proxy.GetData()}");
12 |
13 | Console.WriteLine("Press any key to close!");
14 | Console.ReadKey();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Project/ProxyConsole/Proxy/ProxyClient.cs:
--------------------------------------------------------------------------------
1 | using ProxyConsole.RealSubject;
2 | using ProxyConsole.Subject;
3 | using System;
4 |
5 | namespace ProxyConsole.Proxy
6 | {
7 | public class ProxyClient : IClient
8 | {
9 | RealClient client = new RealClient();
10 | public ProxyClient()
11 | {
12 | Console.WriteLine("ProxyClient: Initialized");
13 | }
14 |
15 | public string GetData()
16 | {
17 | return client.GetData();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Project/ProxyConsole/ProxyConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/ProxyConsole/RealSubject/RealClient.cs:
--------------------------------------------------------------------------------
1 | using ProxyConsole.Subject;
2 | using System;
3 |
4 | namespace ProxyConsole.RealSubject
5 | {
6 | public class RealClient : IClient
7 | {
8 | string Data;
9 | public RealClient()
10 | {
11 | Console.WriteLine("Real Client: Initialized");
12 | Data = "XP Inc. Medium";
13 | }
14 |
15 | public string GetData()
16 | {
17 | return Data;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Project/ProxyConsole/Subject/IClient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace ProxyConsole.Subject
6 | {
7 | public interface IClient
8 | {
9 | string GetData();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/SingletonConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 |
4 | namespace SingletonConsole
5 | {
6 | class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | // The client code.
11 | //Test Safe Mode
12 |
13 | //SafeMode();
14 | WrongMode();
15 |
16 | Console.WriteLine("Pressione um tecla para encerrar");
17 | Console.ReadKey();
18 | }
19 |
20 | static void SafeMode()
21 | {
22 | Console.WriteLine(
23 | "{0}\n{1}\n\n{2}\n",
24 | "Se você estiver vendo o mesmo valor, então o singleton foi reutilizado (oh,yes!!!)",
25 | "Se você estiver vendo valores diferentes, dois singletons serão criados(ops!!!)",
26 | "RESULT:"
27 | );
28 |
29 | Thread process1 = new Thread(() =>
30 | {
31 | TestSingleton("First");
32 | });
33 | Thread process2 = new Thread(() =>
34 | {
35 | TestSingleton("Second");
36 | });
37 |
38 | process1.Start();
39 | process2.Start();
40 |
41 | process1.Join();
42 | process2.Join();
43 | }
44 |
45 | public static void TestSingleton(string value)
46 | {
47 | SingletonThreadSafe singleton = SingletonThreadSafe.GetInstance(value);
48 | Console.WriteLine(singleton.Value);
49 | }
50 |
51 | static void WrongMode()
52 | {
53 | // The client code.
54 | SingletonWrong s1 = SingletonWrong.GetInstance();
55 | SingletonWrong s2 = SingletonWrong.GetInstance();
56 |
57 | if (s1 == s2)
58 | {
59 | Console.WriteLine("Singleton funciona, ambas as variáveis contêm a mesma instância.");
60 | }
61 | else
62 | {
63 | Console.WriteLine("Singleton falhou, variáveis contêm instâncias diferentes.");
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/Project/SingletonConsole/SingletonConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/SingletonConsole/SingletonThreadSafe.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SingletonConsole
6 | {
7 | //Para corrigir o problema, você deve sincronizar os threads durante
8 | //a primeira criação do objeto Singleton.
9 | class SingletonThreadSafe
10 | {
11 | private SingletonThreadSafe() { }
12 |
13 | private static SingletonThreadSafe _instance;
14 |
15 | private static readonly object _lock = new object();
16 |
17 | public static SingletonThreadSafe GetInstance(string value)
18 | {
19 | if (_instance == null)
20 | {
21 | lock (_lock)
22 | {
23 | if (_instance == null)
24 | {
25 | _instance = new SingletonThreadSafe();
26 | _instance.Value = value;
27 | }
28 | }
29 | }
30 | return _instance;
31 | }
32 |
33 | public string Value { get; set; }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Project/SingletonConsole/SingletonWrong.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace SingletonConsole
6 | {
7 | //É muito fácil implementar um Singleton desleixado.
8 | //Você só precisa ocultar o construtor e implementar um método de criação estático.
9 | //A mesma classe se comporta incorretamente em um ambiente multithread.
10 | //Vários threads podem chamar o método de criação simultaneamente e obter várias instâncias da classe Singleton.
11 |
12 | class SingletonWrong
13 | {
14 | private SingletonWrong() { }
15 |
16 | private static SingletonWrong _instance;
17 |
18 | public static SingletonWrong GetInstance()
19 | {
20 | if (_instance == null)
21 | {
22 | _instance = new SingletonWrong();
23 | }
24 | return _instance;
25 | }
26 |
27 | public static void SomeBusinessLogic()
28 | {
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Project/StateConsole/ConcreteState/ConcreteStateA.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StateConsole
6 | {
7 | class ConcreteStateA : State
8 | {
9 | public override void Handle1()
10 | {
11 | Console.WriteLine("ConcreteStateA handles request1.");
12 | Console.WriteLine("ConcreteStateA wants to change the state of the context.");
13 | this._context.TransitionTo(new ConcreteStateB());
14 | }
15 |
16 | public override void Handle2()
17 | {
18 | Console.WriteLine("ConcreteStateA handles request2.");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Project/StateConsole/ConcreteState/ConcreteStateB.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StateConsole
6 | {
7 | class ConcreteStateB : State
8 | {
9 | public override void Handle1()
10 | {
11 | Console.Write("ConcreteStateB handles request1.");
12 | }
13 |
14 | public override void Handle2()
15 | {
16 | Console.WriteLine("ConcreteStateB handles request2.");
17 | Console.WriteLine("ConcreteStateB wants to change the state of the context.");
18 | this._context.TransitionTo(new ConcreteStateA());
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Project/StateConsole/Context/Context.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StateConsole
6 | {
7 | class Context
8 | {
9 | private State _state = null;
10 |
11 | public Context(State state)
12 | {
13 | this.TransitionTo(state);
14 | }
15 |
16 | public void TransitionTo(State state)
17 | {
18 | Console.WriteLine($"Context: Transition to {state.GetType().Name}.");
19 | this._state = state;
20 | this._state.SetContext(this);
21 | }
22 |
23 | public void Request1()
24 | {
25 | this._state.Handle1();
26 | }
27 |
28 | public void Request2()
29 | {
30 | this._state.Handle2();
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Project/StateConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace StateConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | var context = new Context(new ConcreteStateA());
10 | context.Request1();
11 | context.Request2();
12 |
13 | Console.WriteLine("Press any key to continue!");
14 | Console.ReadKey();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Project/StateConsole/State/State.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StateConsole
6 | {
7 | abstract class State
8 | {
9 | protected Context _context;
10 |
11 | public void SetContext(Context context)
12 | {
13 | this._context = context;
14 | }
15 |
16 | public abstract void Handle1();
17 |
18 | public abstract void Handle2();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Project/StateConsole/StateConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/StrategyConsole/ConcreteStrategy/PositionEquities.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StrategyConsole
6 | {
7 | class PositionEquities : IStrategy
8 | {
9 | public CustomerPositionModel GetCustomerPosition(long customerCode)
10 | {
11 | if (customerCode > 0)
12 | {
13 | var result= new CustomerPositionModel
14 | {
15 | Name = $"Cliente {customerCode}",
16 | Value = 100000
17 | };
18 |
19 | Console.WriteLine($"{result.Name} - {result.Value}");
20 |
21 | return result;
22 | }
23 |
24 | return new CustomerPositionModel();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Project/StrategyConsole/ConcreteStrategy/PositionFunds.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StrategyConsole
6 | {
7 | public class PositionFunds : IStrategy
8 | {
9 | public CustomerPositionModel GetCustomerPosition(long customerCode)
10 | {
11 | if (customerCode > 0)
12 | {
13 | var result = new CustomerPositionModel
14 | {
15 | Name = $"Cliente {customerCode}",
16 | Value = 2000
17 | };
18 |
19 | Console.WriteLine($"{result.Name} - {result.Value}");
20 |
21 | return result;
22 | }
23 |
24 | return new CustomerPositionModel();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Project/StrategyConsole/Context/Context.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StrategyConsole
6 | {
7 | class Context
8 | {
9 | private IStrategy _strategy;
10 |
11 | public Context()
12 | { }
13 |
14 | public Context(IStrategy strategy)
15 | {
16 | this._strategy = strategy;
17 | }
18 |
19 | public void SetStrategy(IStrategy strategy)
20 | {
21 | this._strategy = strategy;
22 | }
23 |
24 | public void GetCustomerPosition(long customerCode)
25 | {
26 | var result = this._strategy.GetCustomerPosition(customerCode);
27 |
28 | Console.WriteLine($"Customer: {result.Name} - Position {result.Value}");
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Project/StrategyConsole/Model/CustomerPositionModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StrategyConsole
6 | {
7 | public class CustomerPositionModel
8 | {
9 | public string Name { get; set; }
10 | public decimal Value { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Project/StrategyConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace StrategyConsole
6 | {
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | var context = new Context();
12 |
13 | Console.WriteLine("Client: ");
14 | context.SetStrategy(new PositionEquities());
15 | context.GetCustomerPosition(335962);
16 |
17 | Console.WriteLine();
18 |
19 | Console.WriteLine("Client: ");
20 | context.SetStrategy(new PositionFunds());
21 | context.GetCustomerPosition(335962);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Project/StrategyConsole/Strategy/IStrategy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace StrategyConsole
6 | {
7 | interface IStrategy
8 | {
9 | CustomerPositionModel GetCustomerPosition(long customerCode);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/StrategyConsole/StrategyConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/TemplateMethodConsole/Abstract/AbstractClass.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace TemplateMethodConsole
6 | {
7 | abstract class AbstractClass
8 | {
9 | public void TemplateMethod()
10 | {
11 | this.BaseOperation1();
12 | this.RequiredOperations1();
13 | this.BaseOperation2();
14 | this.Hook1();
15 | this.RequiredOperation2();
16 | this.BaseOperation3();
17 | this.Hook2();
18 | }
19 |
20 | protected void BaseOperation1()
21 | {
22 | Console.WriteLine("AbstractClass says: I am doing the bulk of the work");
23 | }
24 |
25 | protected void BaseOperation2()
26 | {
27 | Console.WriteLine("AbstractClass says: But I let subclasses override some operations");
28 | }
29 |
30 | protected void BaseOperation3()
31 | {
32 | Console.WriteLine("AbstractClass says: But I am doing the bulk of the work anyway");
33 | }
34 |
35 | protected abstract void RequiredOperations1();
36 |
37 | protected abstract void RequiredOperation2();
38 |
39 | protected virtual void Hook1() { }
40 |
41 | protected virtual void Hook2() { }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Project/TemplateMethodConsole/Client/Client.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace TemplateMethodConsole
6 | {
7 | class Client
8 | {
9 | public static void ClientCode(AbstractClass abstractClass)
10 | {
11 | abstractClass.TemplateMethod();
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Project/TemplateMethodConsole/Concrete/ConcreteClass1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace TemplateMethodConsole
6 | {
7 | class ConcreteClass1 : AbstractClass
8 | {
9 | protected override void RequiredOperations1()
10 | {
11 | Console.WriteLine("ConcreteClass1 says: Implemented Operation1");
12 | }
13 |
14 | protected override void RequiredOperation2()
15 | {
16 | Console.WriteLine("ConcreteClass1 says: Implemented Operation2");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Project/TemplateMethodConsole/Concrete/ConcreteClass2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace TemplateMethodConsole
6 | {
7 | class ConcreteClass2 : AbstractClass
8 | {
9 | protected override void RequiredOperations1()
10 | {
11 | Console.WriteLine("ConcreteClass2 says: Implemented Operation1");
12 | }
13 |
14 | protected override void RequiredOperation2()
15 | {
16 | Console.WriteLine("ConcreteClass2 says: Implemented Operation2");
17 | }
18 |
19 | protected override void Hook1()
20 | {
21 | Console.WriteLine("ConcreteClass2 says: Overridden Hook1");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Project/TemplateMethodConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace TemplateMethodConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Console.WriteLine("Same client code can work with different subclasses:");
10 |
11 | Client.ClientCode(new ConcreteClass1());
12 |
13 | Console.Write("\n");
14 |
15 | Console.WriteLine("Same client code can work with different subclasses:");
16 | Client.ClientCode(new ConcreteClass2());
17 |
18 | Console.WriteLine("Press any key to continue!");
19 | Console.ReadKey();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Project/TemplateMethodConsole/TemplateMethodConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/Client/Client.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VisitorConsole
6 | {
7 | public class Client
8 | {
9 | public static void ClientCode(List components, IVisitor visitor)
10 | {
11 | foreach (var component in components)
12 | {
13 | component.Accept(visitor);
14 | }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/ConcreteElement/ConcreteElementA.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VisitorConsole
6 | {
7 | public class ConcreteElementA : IElement
8 | {
9 | public void Accept(IVisitor visitor)
10 | {
11 | visitor.VisitConcreteElementA(this);
12 | }
13 |
14 | public string ExclusiveMethodOfConcreteElementA()
15 | {
16 | return "A";
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/ConcreteElement/ConcreteElementB.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VisitorConsole
6 | {
7 | public class ConcreteElementB : IElement
8 | {
9 | public void Accept(IVisitor visitor)
10 | {
11 | visitor.VisitConcreteElementB(this);
12 | }
13 |
14 | public string SpecialMethodOfConcreteElementB()
15 | {
16 | return "B";
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/ConcreteVisitor/ConcreteVisitor1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VisitorConsole
6 | {
7 | class ConcreteVisitor1 : IVisitor
8 | {
9 | public void VisitConcreteElementA(ConcreteElementA element)
10 | {
11 | Console.WriteLine($"{element.ExclusiveMethodOfConcreteElementA()} ConcreteVisitor1");
12 | }
13 |
14 | public void VisitConcreteElementB(ConcreteElementB element)
15 | {
16 | Console.WriteLine($"{element.SpecialMethodOfConcreteElementB()} ConcreteVisitor1");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/ConcreteVisitor/ConcreteVisitor2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VisitorConsole
6 | {
7 | class ConcreteVisitor2 : IVisitor
8 | {
9 | public void VisitConcreteElementA(ConcreteElementA element)
10 | {
11 | Console.WriteLine($"{element.ExclusiveMethodOfConcreteElementA()} ConcreteVisitor2");
12 | }
13 |
14 | public void VisitConcreteElementB(ConcreteElementB element)
15 | {
16 | Console.WriteLine($"{element.SpecialMethodOfConcreteElementB()} ConcreteVisitor2");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/Element/IElement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VisitorConsole
6 | {
7 | public interface IElement
8 | {
9 | void Accept(IVisitor visitor);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace VisitorConsole
5 | {
6 | //ObjectStructure
7 | class Program
8 | {
9 | static void Main(string[] args)
10 | {
11 | List components = new List
12 | {
13 | new ConcreteElementA(),
14 | new ConcreteElementB()
15 | };
16 |
17 | Console.WriteLine("The client code works with all visitors via the base Visitor interface:");
18 | var visitor1 = new ConcreteVisitor1();
19 | Client.ClientCode(components, visitor1);
20 |
21 | Console.WriteLine();
22 |
23 | Console.WriteLine("It allows the same client code to work with different types of visitors:");
24 | var visitor2 = new ConcreteVisitor2();
25 | Client.ClientCode(components, visitor2);
26 |
27 | Console.WriteLine("Press any key to continue!");
28 | Console.ReadKey();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/Visitor/IVisitor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VisitorConsole
6 | {
7 | public interface IVisitor
8 | {
9 | void VisitConcreteElementA(ConcreteElementA element);
10 |
11 | void VisitConcreteElementB(ConcreteElementB element);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Project/VisitorConsole/VisitorConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.0
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Project/gitignore:
--------------------------------------------------------------------------------
1 | *.swp
2 | *.*~
3 | project.lock.json
4 | .DS_Store
5 | *.pyc
6 | nupkg/
7 |
8 | # Visual Studio Code
9 | .vscode
10 |
11 | # Rider
12 | .idea
13 |
14 | # User-specific files
15 | *.suo
16 | *.user
17 | *.userosscache
18 | *.sln.docstates
19 |
20 | # Build results
21 | [Dd]ebug/
22 | [Dd]ebugPublic/
23 | [Rr]elease/
24 | [Rr]eleases/
25 | x64/
26 | x86/
27 | build/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Oo]ut/
32 | msbuild.log
33 | msbuild.err
34 | msbuild.wrn
35 |
36 | # Visual Studio 2015
37 | .vs/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # design-patterns
2 |
3 | Projeto de exemplo para descrever os 23 padrões de projeto do GOF:
4 |
5 | descritos no medium
6 |
7 | Desing Patterns
8 |
9 | Todos Links da série
10 | https://medium.com/@jonesroberto/design-patterns-34257406b136
11 |
--------------------------------------------------------------------------------