├── .gitattributes ├── .gitignore ├── DesignPatterns ├── .vs │ └── DesignPatterns │ │ └── v16 │ │ ├── .suo │ │ └── TestStore │ │ └── 0 │ │ ├── 000-0000.testlog │ │ └── testlog.manifest ├── BehavioralPatterns │ ├── 5- Chain Of Responsability │ │ ├── ExecuteChainOfResponsability.cs │ │ ├── Middlewares │ │ │ ├── CheckPermissionMiddleware.cs │ │ │ ├── CheckUserMiddleware.cs │ │ │ ├── CheckWeakPasswordMiddleware.cs │ │ │ └── Middleware.cs │ │ └── Servers │ │ │ └── Server.cs │ ├── BehavioralPattern.cs │ └── BehavioralPatterns.csproj ├── CreationPatterns │ ├── 1- Abstract Factory │ │ ├── Example 1 │ │ │ ├── ConcretesFactory │ │ │ │ ├── BankLtda.cs │ │ │ │ └── BrokerageLtda.cs │ │ │ ├── Interface │ │ │ │ ├── IAccountFactory.cs │ │ │ │ └── IInvestimentAccountFactory.cs │ │ │ ├── Model │ │ │ │ ├── Account.cs │ │ │ │ └── InvestimentAccount.cs │ │ │ ├── Product │ │ │ │ ├── FixedIncome .cs │ │ │ │ ├── MultimarketFunds.cs │ │ │ │ ├── PIX.cs │ │ │ │ └── SavingsAccount.cs │ │ │ └── Service │ │ │ │ ├── AccountService.cs │ │ │ │ └── InvestimentService.cs │ │ ├── Example 2 │ │ │ ├── AplicacaoExemplo.cs │ │ │ ├── ConcreteFactory │ │ │ │ ├── ConcreteFactory1.cs │ │ │ │ └── ConcreteFactory2.cs │ │ │ ├── Interface │ │ │ │ ├── IAbstractFactory.cs │ │ │ │ ├── IAbstractProductA.cs │ │ │ │ └── IAbstractProductB.cs │ │ │ └── Product │ │ │ │ ├── ConcreteProductA1.cs │ │ │ │ ├── ConcreteProductA2.cs │ │ │ │ └── ConcreteProductB1.cs │ │ ├── Example 3 │ │ │ ├── Aircrafts │ │ │ │ ├── Airplane.cs │ │ │ │ ├── Drone.cs │ │ │ │ ├── Helicopter.cs │ │ │ │ └── IAircraft.cs │ │ │ ├── ApplicationExecute.cs │ │ │ ├── Factories │ │ │ │ ├── ITransporFactory.cs │ │ │ │ ├── LimeTransport.cs │ │ │ │ ├── NineNineTransport.cs │ │ │ │ └── UberTransport.cs │ │ │ └── Landvehicles │ │ │ │ ├── Car.cs │ │ │ │ ├── ILandvehicle.cs │ │ │ │ ├── Motorcycle.cs │ │ │ │ └── Scotter.cs │ │ └── ExecuteAbstractFactory.cs │ ├── 2- Factory Method │ │ ├── Example 1 │ │ │ ├── Factories │ │ │ │ ├── BikeTransport.cs │ │ │ │ ├── CarTransport.cs │ │ │ │ ├── MotorcycleTransport.cs │ │ │ │ └── Transport.cs │ │ │ ├── Interface │ │ │ │ └── IVehicles.cs │ │ │ └── Vehicles │ │ │ │ ├── Bike.cs │ │ │ │ ├── Car.cs │ │ │ │ └── Motorcycle.cs │ │ ├── Example 2 │ │ │ ├── Banks │ │ │ │ ├── Account.cs │ │ │ │ └── InvestmentAccounts.cs │ │ │ ├── Factories │ │ │ │ ├── AccountFactory.cs │ │ │ │ ├── BankFactory.cs │ │ │ │ └── InvestmentAccountFactory.cs │ │ │ └── Interface │ │ │ │ └── IBanks.cs │ │ ├── Example 3 │ │ │ ├── Factories │ │ │ │ ├── SupplierFactory.cs │ │ │ │ └── SupplierProductsFactory.cs │ │ │ ├── Interface │ │ │ │ └── ISupplier.cs │ │ │ └── SupplierProducts │ │ │ │ └── Suplpiers.cs │ │ └── ExecuteFactoryMethod.cs │ ├── 3- Singleton │ │ └── Singleton.cs │ ├── 4- Builder │ │ ├── Example 1 │ │ │ ├── Builders │ │ │ │ ├── IBuilder.cs │ │ │ │ └── VehicleBuilder.cs │ │ │ ├── Components │ │ │ │ ├── AirBag.cs │ │ │ │ ├── Engine.cs │ │ │ │ ├── Transmission.cs │ │ │ │ └── VehicleType.cs │ │ │ ├── Directors │ │ │ │ └── Director.cs │ │ │ └── Products │ │ │ │ └── Vehicle.cs │ │ └── ExecuteBuilder.cs │ ├── CreationPatterns.csproj │ └── CreationalPatterns.cs ├── DesignPatterns.sln └── StructuralPatterns │ ├── 1- Bridge │ ├── ExecuteBridge.cs │ ├── Plataforms │ │ ├── DLive.cs │ │ ├── Facebook.cs │ │ ├── IPlatform.cs │ │ ├── TwitchTV.cs │ │ └── Youtube.cs │ └── Transmissions │ │ ├── AdvancedLive.cs │ │ ├── ITransmission.cs │ │ └── Live.cs │ ├── 2- Adapter │ ├── Example 1 │ │ ├── ExecuteAdapter.cs │ │ ├── Interface │ │ │ ├── IMercadoPagoPayment.cs │ │ │ ├── IPayonnerPayment.cs │ │ │ └── IPaypalPayment.cs │ │ ├── MercadoPago.cs │ │ ├── MercadoPagoAdapter.cs │ │ ├── Payonner.cs │ │ ├── PayonnerAdapter.cs │ │ ├── Paypal.cs │ │ └── Token.cs │ └── Example 2 │ │ ├── Amazon.cs │ │ ├── AmazonAdapter.cs │ │ ├── ExecuteAdapterEcommerce.cs │ │ ├── Interface │ │ ├── IAmazonSupplier.cs │ │ └── IMagazineLuizaSupplier.cs │ │ └── MagazineLuiza.cs │ ├── StructuralPatterns.cs │ └── StructuralPatterns.csproj └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.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 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /DesignPatterns/.vs/DesignPatterns/v16/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JessicaNathany/design-patterns/ec64f3b8c48d111d2932dd99f6567b07cba54fbf/DesignPatterns/.vs/DesignPatterns/v16/.suo -------------------------------------------------------------------------------- /DesignPatterns/.vs/DesignPatterns/v16/TestStore/0/000-0000.testlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JessicaNathany/design-patterns/ec64f3b8c48d111d2932dd99f6567b07cba54fbf/DesignPatterns/.vs/DesignPatterns/v16/TestStore/0/000-0000.testlog -------------------------------------------------------------------------------- /DesignPatterns/.vs/DesignPatterns/v16/TestStore/0/testlog.manifest: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JessicaNathany/design-patterns/ec64f3b8c48d111d2932dd99f6567b07cba54fbf/DesignPatterns/.vs/DesignPatterns/v16/TestStore/0/testlog.manifest -------------------------------------------------------------------------------- /DesignPatterns/BehavioralPatterns/5- Chain Of Responsability/ExecuteChainOfResponsability.cs: -------------------------------------------------------------------------------- 1 | using BehavioralPatterns._5__Chain_Of_Responsability.Middlewares; 2 | using BehavioralPatterns._5__Chain_Of_Responsability.Servers; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace BehavioralPatterns._5__Chain_Of_Responsability 8 | { 9 | public class ExecuteChainOfResponsability 10 | { 11 | private static Server server; 12 | public void TestMiddleware() 13 | { 14 | Init(); 15 | var done = false; 16 | 17 | do 18 | { 19 | Console.WriteLine("Write your email "); 20 | string email = Console.ReadLine(); 21 | 22 | Console.WriteLine("Write your password "); 23 | string password = Console.ReadLine(); 24 | 25 | done = server.Login(email, password); 26 | 27 | } while (!done); 28 | 29 | Console.ReadLine(); 30 | } 31 | 32 | private void Init() 33 | { 34 | server = new Server(); 35 | server.RegisterUser("master@jncoder.com.br", "admin@12!$"); 36 | server.RegisterUser("user@jncoder.com.br", "user#90L"); 37 | 38 | Middleware middleware = new CheckUserMiddleware(server); 39 | 40 | middleware.LinkWith(new CheckPermissionMiddleware()); 41 | 42 | server.SetMiddleware(middleware); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DesignPatterns/BehavioralPatterns/5- Chain Of Responsability/Middlewares/CheckPermissionMiddleware.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BehavioralPatterns._5__Chain_Of_Responsability.Middlewares 4 | { 5 | public class CheckPermissionMiddleware : Middleware 6 | { 7 | public override bool Check(string email, string password) 8 | { 9 | if (email.Equals("administrador@server1.com.br")) 10 | { 11 | Console.WriteLine("Wellcome to administrator!"); 12 | return true; 13 | } 14 | 15 | Console.WriteLine("Wellcome!"); 16 | return CheckNext(email, password); 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DesignPatterns/BehavioralPatterns/5- Chain Of Responsability/Middlewares/CheckUserMiddleware.cs: -------------------------------------------------------------------------------- 1 | using BehavioralPatterns._5__Chain_Of_Responsability.Servers; 2 | using System; 3 | 4 | namespace BehavioralPatterns._5__Chain_Of_Responsability.Middlewares 5 | { 6 | public class CheckUserMiddleware : Middleware 7 | { 8 | private Server server; 9 | public CheckUserMiddleware(Server server) 10 | { 11 | this.server = server; 12 | } 13 | 14 | public override bool Check(string email, string password) 15 | { 16 | if(!server.HasEmail(email)) 17 | { 18 | Console.WriteLine("Invalid email!"); 19 | return false; 20 | } 21 | 22 | if(!server.IsValidPassword(email, password)) 23 | { 24 | Console.WriteLine("Invalid email or password"); 25 | return false; 26 | } 27 | 28 | return CheckNext(email, password); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DesignPatterns/BehavioralPatterns/5- Chain Of Responsability/Middlewares/CheckWeakPasswordMiddleware.cs: -------------------------------------------------------------------------------- 1 | using BehavioralPatterns._5__Chain_Of_Responsability.Servers; 2 | using System; 3 | 4 | namespace BehavioralPatterns._5__Chain_Of_Responsability.Middlewares 5 | { 6 | public class CheckWeakPasswordMiddleware : Middleware 7 | { 8 | private Server server; 9 | public CheckWeakPasswordMiddleware(Server server) 10 | { 11 | this.server = server; 12 | } 13 | public override bool Check(string email, string password) 14 | { 15 | if (email.Equals("administrador@server1.com.br")) 16 | { 17 | Console.WriteLine("Wellcome to administrator!"); 18 | return true; 19 | } 20 | 21 | Console.WriteLine("Wellcome!"); 22 | return CheckNext(email, password); 23 | } 24 | 25 | // to be continued... 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatterns/BehavioralPatterns/5- Chain Of Responsability/Middlewares/Middleware.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BehavioralPatterns._5__Chain_Of_Responsability.Middlewares 4 | { 5 | public abstract class Middleware 6 | { 7 | private Middleware _next; 8 | public Middleware LinkWith(Middleware next) 9 | { 10 | _next = next; 11 | return _next; 12 | } 13 | 14 | public abstract Boolean Check(string email, string password); 15 | protected Boolean CheckNext(string email, string password) 16 | { 17 | if(_next == null) { return true; } 18 | 19 | return _next.Check(email, password); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /DesignPatterns/BehavioralPatterns/5- Chain Of Responsability/Servers/Server.cs: -------------------------------------------------------------------------------- 1 | using BehavioralPatterns._5__Chain_Of_Responsability.Middlewares; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace BehavioralPatterns._5__Chain_Of_Responsability.Servers 6 | { 7 | public class Server 8 | { 9 | private Dictionary users = new Dictionary(); 10 | private Middleware middleware; 11 | 12 | public void SetMiddleware(Middleware middleware) 13 | { 14 | this.middleware = middleware; 15 | } 16 | 17 | public Boolean Login(string email, string password) 18 | { 19 | if(middleware.Check(email, password)) 20 | { 21 | Console.WriteLine("Authorized success!"); 22 | Console.WriteLine("Wellcome!"); 23 | return true; 24 | } 25 | 26 | return false; 27 | } 28 | 29 | public void RegisterUser(string email, string password) 30 | { 31 | users[email] = password; 32 | } 33 | 34 | public Boolean HasEmail(string email) 35 | { 36 | return users.ContainsKey(email); 37 | } 38 | 39 | public Boolean IsValidPassword(string email, string password) 40 | { 41 | var value = ""; 42 | users.TryGetValue(email, out value); 43 | return password == value; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /DesignPatterns/BehavioralPatterns/BehavioralPattern.cs: -------------------------------------------------------------------------------- 1 | using BehavioralPatterns._5__Chain_Of_Responsability; 2 | using System; 3 | 4 | namespace BehavioralPatterns 5 | { 6 | public class BehavioralPattern 7 | { 8 | static void Main(string[] args) 9 | { 10 | Console.WriteLine("..:: Behavioral Patterns select an option ::.."); 11 | Console.WriteLine(); 12 | Console.WriteLine("1 - Chain Of Responsability Middleware"); 13 | Console.WriteLine(); 14 | Console.WriteLine("2 - Chain Of Responsability Example two"); 15 | Console.WriteLine(); 16 | Console.WriteLine("3 - Chain Of Responsability Example three"); 17 | Console.WriteLine("------------------------"); 18 | 19 | var option = Console.ReadKey(); 20 | 21 | switch (option.KeyChar) 22 | { 23 | case '1': 24 | new ExecuteChainOfResponsability().TestMiddleware(); 25 | break; 26 | 27 | //case '2': 28 | // new ExecuteAbstractFactory().ExampleTwo(); 29 | // break; 30 | 31 | //case '3': 32 | // new ExecuteAbstractFactory().ExampleThree(); 33 | // break; 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DesignPatterns/BehavioralPatterns/BehavioralPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/ConcretesFactory/BankLtda.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface; 2 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 3 | using System; 4 | 5 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.ConcretesFactory 6 | { 7 | /// 8 | /// Concrete Factory 9 | /// This is class about Bank current or Savings 10 | /// 11 | public class BankLtda : IAccountFactory 12 | { 13 | public void Deposit(Account account, double value) 14 | { 15 | throw new NotImplementedException(); 16 | } 17 | public string GetService() 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | 22 | public void Transfer(double value, Account destinationAccount) 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/ConcretesFactory/BrokerageLtda.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface; 2 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.ConcretesFactory 7 | { 8 | /// 9 | /// Concrete Factory 10 | /// This is class about Investiment Broker 11 | /// 12 | public class BrokerageLtda : IInvestimentAccountFactory 13 | { 14 | public string GetInvestiment() 15 | { 16 | throw new NotImplementedException(); 17 | } 18 | 19 | public double GetInvestimentforMonth(int id) 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | 24 | public void Invest(InvestimentAccount typeInvestiment, double value) 25 | { 26 | throw new NotImplementedException(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Interface/IAccountFactory.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 2 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface 3 | { 4 | /// 5 | /// Abstract Factory it's same IBaseGenericRepository for all SavingsAccount 6 | /// 7 | public interface IAccountFactory 8 | { 9 | void Deposit(Account account, double value); 10 | void Transfer(double value, Account destinationAccount); 11 | 12 | string GetService(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Interface/IInvestimentAccountFactory.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 2 | 3 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface 4 | { 5 | /// 6 | /// Abstract Factory it's same IBaseGenericRepository for all InvestimentAccount 7 | /// 8 | public interface IInvestimentAccountFactory 9 | { 10 | double GetInvestimentforMonth(int id); 11 | void Invest(InvestimentAccount typeInvestiment, double value); 12 | string GetInvestiment(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Model/Account.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1 2 | { 3 | public class Account 4 | { 5 | public string Name { get ; set; } 6 | public string Document { get; set; } 7 | public string Address { get; set; } 8 | public int Agency { get; set; } 9 | public int AccountNumber { get; set; } 10 | public int Digit { get; set; } 11 | 12 | public TypeAccount TypeAccount { get; set; } 13 | } 14 | public enum TypeAccount 15 | { 16 | CurrentAccount = 1, 17 | Savings = 2 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Model/InvestimentAccount.cs: -------------------------------------------------------------------------------- 1 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1 2 | { 3 | public class InvestimentAccount 4 | { 5 | public string Name { get; set; } 6 | public string Document { get; set; } 7 | public string Address { get; set; } 8 | public double Finance { get; set; } 9 | public TypeInvestiment TypeInvestiment { get; set; } 10 | } 11 | public enum TypeInvestiment 12 | { 13 | NationalTreasuryBonds = 1, 14 | Debentures = 2, 15 | MultimarketFunds = 3, 16 | CDB = 4, 17 | LCI = 5, 18 | BDR = 6, 19 | COE = 7, 20 | LCA = 8, 21 | CRI = 9, 22 | CRA = 10, 23 | FI = 11, 24 | PP = 12, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Product/FixedIncome .cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface; 2 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 3 | using System; 4 | 5 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1 6 | { 7 | /// 8 | /// Product B1 9 | /// 10 | public class FixedIncome : IInvestimentAccountFactory 11 | { 12 | public string GetInvestiment() 13 | { 14 | return "Fixed Income"; 15 | } 16 | 17 | public double GetInvestimentforMonth(int id) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | 22 | public void Invest(InvestimentAccount typeInvestiment, double value) 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Product/MultimarketFunds.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface; 2 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 3 | using System; 4 | 5 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1 6 | { 7 | /// 8 | /// Product B2 9 | /// 10 | public class MultimarketFunds : IInvestimentAccountFactory 11 | { 12 | public string GetInvestiment() 13 | { 14 | return "Multimarket funds"; 15 | } 16 | 17 | public double GetInvestimentforMonth(int id) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | 22 | public void Invest(InvestimentAccount typeInvestiment, double value) 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Product/PIX.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface; 2 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 3 | using System; 4 | 5 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1 6 | { 7 | /// 8 | /// Product A1 9 | /// 10 | public class PIX : IAccountFactory 11 | { 12 | public void Deposit(InvestimentAccount typeAccount, double value) 13 | { 14 | throw new NotImplementedException(); 15 | } 16 | 17 | public void Deposit(Account account, double value) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | 22 | public string GetService() 23 | { 24 | return "PIX - Service"; 25 | } 26 | 27 | public void Transfer(double value, Account destinationAccount) 28 | { 29 | throw new NotImplementedException(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Product/SavingsAccount.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface; 2 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 3 | using System; 4 | 5 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1 6 | { 7 | /// 8 | /// Product A2 9 | /// 10 | public class SavingsAccount : IAccountFactory 11 | { 12 | public void Deposit(Account account, double value) 13 | { 14 | throw new NotImplementedException(); 15 | } 16 | 17 | public string GetService() 18 | { 19 | return "Savings Account - Service"; 20 | } 21 | 22 | public void Transfer(double value, Account destinyAccount) 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Service/AccountService.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface; 2 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 3 | using System; 4 | 5 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1 6 | { 7 | public class AccountService 8 | { 9 | IAccountFactory _accountFactory; 10 | public AccountService(IAccountFactory accountFactory) 11 | { 12 | _accountFactory = accountFactory; 13 | } 14 | 15 | private void Deposit(double value) 16 | { 17 | var account = new Account(); 18 | 19 | _accountFactory.Deposit(account, value); 20 | } 21 | 22 | private void Transfer(double value, Account destinyAccount) 23 | { 24 | _accountFactory.Transfer(value, destinyAccount); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 1/Service/InvestimentService.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1__Abstract_Factory.Example_1.Interface; 2 | using DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_1; 3 | 4 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Example_1 5 | { 6 | public class InvestimentService 7 | { 8 | IInvestimentAccountFactory _investimentAccountFactory; 9 | 10 | public InvestimentService(IInvestimentAccountFactory investimentAccountFactory) 11 | { 12 | _investimentAccountFactory = investimentAccountFactory; 13 | } 14 | 15 | public void Invest(InvestimentAccount investimentAccount, double value) 16 | { 17 | _investimentAccountFactory.Invest(investimentAccount, value); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/AplicacaoExemplo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace DesignPatterns._1__Creational._1__Abstract_Factory.Exemplo_3 3 | { 4 | /// 5 | /// Exemplo tirado do site https://www.dofactory.com/net/abstract-factory-design-pattern 6 | /// 7 | public class AplicacaoExemplo 8 | { 9 | //public static void Main() 10 | //{ 11 | // // Abstract factory #1 12 | 13 | // AbstractFactory factory1 = new ConcreteFactory1(); 14 | // Cliente cliente1 = new Cliente(factory1); 15 | // cliente1.Run(); 16 | 17 | // // Abstract factory #2 18 | 19 | // AbstractFactory factory2 = new ConcreteFactory2(); 20 | // Cliente cliente2 = new Cliente(factory2); 21 | // cliente2.Run(); 22 | 23 | // Console.ReadKey(); 24 | //} 25 | } 26 | 27 | /// 28 | /// Classe abastrata 'AbstractFactory' 29 | /// 30 | abstract class AbstractFactory 31 | { 32 | public abstract AbstractProductA CriaProdutoA(); 33 | public abstract AbstractProductB CriaProdutoB(); 34 | } 35 | 36 | /// 37 | /// Classe 'ConcreteFactory1' 38 | /// 39 | class ConcreteFactory1 : AbstractFactory 40 | { 41 | public override AbstractProductA CriaProdutoA() 42 | { 43 | return new ProdutoA1(); 44 | } 45 | public override AbstractProductB CriaProdutoB() 46 | { 47 | return new ProdutoB1(); 48 | } 49 | } 50 | 51 | /// 52 | /// The 'ConcreteFactory2' class 53 | /// 54 | 55 | class ConcreteFactory2 : AbstractFactory 56 | { 57 | public override AbstractProductA CriaProdutoA() 58 | { 59 | return new ProductA2(); 60 | } 61 | public override AbstractProductB CriaProdutoB() 62 | { 63 | return new ProductB2(); 64 | } 65 | } 66 | 67 | /// 68 | /// Classe AbstractProductA 69 | /// 70 | 71 | abstract class AbstractProductA 72 | { 73 | } 74 | 75 | /// 76 | /// 77 | /// Classe AbstractProductB 78 | /// 79 | abstract class AbstractProductB 80 | { 81 | public abstract void Interact(AbstractProductA a); 82 | } 83 | 84 | /// 85 | /// Classe ProdutoA1 86 | /// 87 | class ProdutoA1 : AbstractProductA 88 | { 89 | 90 | } 91 | 92 | /// 93 | /// Classe ProdutoB1 94 | /// 95 | class ProdutoB1 : AbstractProductB 96 | { 97 | public override void Interact(AbstractProductA a) 98 | { 99 | Console.WriteLine(this.GetType().Name + " interage com " + a.GetType().Name); 100 | } 101 | } 102 | 103 | /// 104 | /// Classe ProdutoA2 105 | /// 106 | class ProductA2 : AbstractProductA 107 | { 108 | } 109 | 110 | /// 111 | /// Classe ProdutoB2 112 | /// 113 | class ProductB2 : AbstractProductB 114 | { 115 | public override void Interact(AbstractProductA a) 116 | { 117 | Console.WriteLine(this.GetType().Name + " interage com " + a.GetType().Name); 118 | } 119 | } 120 | 121 | /// 122 | /// A classe Cliente interage com os produtos 123 | /// 124 | class Cliente 125 | { 126 | private AbstractProductA _abstractProductA; 127 | private AbstractProductB _abstractProductB; 128 | 129 | // Constructor 130 | 131 | public Cliente(AbstractFactory factory) 132 | { 133 | _abstractProductB = factory.CriaProdutoB(); 134 | _abstractProductA = factory.CriaProdutoA(); 135 | } 136 | 137 | public void Run() 138 | { 139 | _abstractProductB.Interact(_abstractProductA); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/ConcreteFactory/ConcreteFactory1.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_2.Interface; 2 | using CreationPatterns._1__Abstract_Factory.Example_2.Product; 3 | 4 | namespace CreationPatterns._1__Abstract_Factory.Example_2.ConcreteFactory 5 | { 6 | 7 | public class ConcreteFactory1 : IAbstractFactory 8 | { 9 | public IAbstractProductA CreateProductA() 10 | { 11 | return new ConcreteProductA1(); 12 | } 13 | 14 | public IAbstractProductB CreateProductB() 15 | { 16 | return new ConcreteProductB1(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/ConcreteFactory/ConcreteFactory2.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_2.Interface; 2 | using CreationPatterns._1__Abstract_Factory.Example_2.Product; 3 | using System; 4 | 5 | namespace CreationPatterns._1__Abstract_Factory.Example_2.ConcreteFactory 6 | { 7 | // Each Concrete Factory has a corresponding product variant. 8 | public class ConcreteFactory2 : IAbstractFactory 9 | { 10 | public IAbstractProductA CreateProductA() 11 | { 12 | return new ConcreteProductA2(); 13 | } 14 | 15 | public IAbstractProductB CreateProductB() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/Interface/IAbstractFactory.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._1__Abstract_Factory.Example_2.Interface 2 | { 3 | public interface IAbstractFactory 4 | { 5 | IAbstractProductA CreateProductA(); 6 | IAbstractProductB CreateProductB(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/Interface/IAbstractProductA.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._1__Abstract_Factory.Example_2.Interface 2 | { 3 | public interface IAbstractProductA 4 | { 5 | string UsefulFunctionA(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/Interface/IAbstractProductB.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._1__Abstract_Factory.Example_2.Interface 2 | { 3 | /// 4 | /// Here's the the base interface of another product. All products can 5 | /// interact with each other, but proper interaction is possible only between 6 | /// products of the same concrete variant. 7 | /// 8 | public interface IAbstractProductB 9 | { 10 | string UsefulFunctionB(); 11 | 12 | string AnotherUsefulFunctionB(IAbstractProductA collaborator); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/Product/ConcreteProductA1.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_2.Interface; 2 | 3 | namespace CreationPatterns._1__Abstract_Factory.Example_2.Product 4 | { 5 | public class ConcreteProductA1 : IAbstractProductA 6 | { 7 | public string UsefulFunctionA() 8 | { 9 | return "The result of the product A1."; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/Product/ConcreteProductA2.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_2.Interface; 2 | 3 | namespace CreationPatterns._1__Abstract_Factory.Example_2.Product 4 | { 5 | public class ConcreteProductA2 : IAbstractProductA 6 | { 7 | public string UsefulFunctionA() 8 | { 9 | return "The result of the product A2."; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 2/Product/ConcreteProductB1.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_2.Interface; 2 | 3 | namespace CreationPatterns._1__Abstract_Factory.Example_2.Product 4 | { 5 | public class ConcreteProductB1 : IAbstractProductB 6 | { 7 | public string AnotherUsefulFunctionB(IAbstractProductA collaborator) 8 | { 9 | var result = collaborator.UsefulFunctionA(); 10 | 11 | return $"The result of the B1 collaborating with the ({result})"; 12 | } 13 | 14 | public string UsefulFunctionB() 15 | { 16 | return "The result of the product B1."; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Aircrafts/Airplane.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts 3 | { 4 | class Airplane : IAircraft 5 | { 6 | public void CheckWind() 7 | { 8 | Console.WriteLine("check the winds, 25km winds ok!"); 9 | } 10 | 11 | public void GetCargo() 12 | { 13 | Console.WriteLine("Passengers on board. flight authorized"); 14 | } 15 | 16 | public void StartRoute() 17 | { 18 | CheckWind(); 19 | GetCargo(); 20 | Console.WriteLine("Starting the takeoff."); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Aircrafts/Drone.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts 3 | { 4 | public class Drone : IAircraft 5 | { 6 | public void CheckWind() 7 | { 8 | Console.WriteLine("Turn on!"); 9 | } 10 | 11 | public void GetCargo() 12 | { 13 | Console.WriteLine("Check camera, propeller Check propeller ok!"); 14 | } 15 | 16 | public void StartRoute() 17 | { 18 | CheckWind(); 19 | GetCargo(); 20 | Console.WriteLine("Starting the takeoff."); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Aircrafts/Helicopter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts 4 | { 5 | class Helicopter : IAircraft 6 | { 7 | public void CheckWind() 8 | { 9 | Console.WriteLine("check the winds, southeast ok!"); 10 | } 11 | 12 | public void GetCargo() 13 | { 14 | Console.WriteLine("Passengers ok, turning on the propellers!"); 15 | } 16 | 17 | public void StartRoute() 18 | { 19 | CheckWind(); 20 | GetCargo(); 21 | Console.WriteLine("Starting the takeoff!"); 22 | 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Aircrafts/IAircraft.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts 2 | { 3 | public interface IAircraft 4 | { 5 | void CheckWind(); 6 | void StartRoute(); 7 | void GetCargo(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/ApplicationExecute.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts; 2 | using CreationPatterns._1__Abstract_Factory.Example_3.Factories; 3 | using CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles; 4 | 5 | namespace CreationPatterns._1__Abstract_Factory.Example_3 6 | { 7 | public class ApplicationExecute 8 | { 9 | private IAircraft aircraft; 10 | private ILandvehicle vehicle; 11 | 12 | public ApplicationExecute(ITransporFactory factory) 13 | { 14 | vehicle = factory.CreateTransportVehicle(); 15 | aircraft = factory.CreateTransportAirCraft(); 16 | } 17 | 18 | public void StartRoute() 19 | { 20 | vehicle.StartRoute(); 21 | aircraft.StartRoute(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Factories/ITransporFactory.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts; 2 | using CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles; 3 | 4 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Factories 5 | { 6 | public interface ITransporFactory 7 | { 8 | IAircraft CreateTransportAirCraft(); 9 | ILandvehicle CreateTransportVehicle(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Factories/LimeTransport.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts; 2 | using CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles; 3 | 4 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Factories 5 | { 6 | public class LimeTransport : ITransporFactory 7 | { 8 | public IAircraft CreateTransportAirCraft() 9 | { 10 | return new Drone(); 11 | } 12 | 13 | public ILandvehicle CreateTransportVehicle() 14 | { 15 | return new Scotter(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Factories/NineNineTransport.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts; 2 | using CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles; 3 | 4 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Factories 5 | { 6 | 7 | class NineNineTransport : ITransporFactory 8 | { 9 | public IAircraft CreateTransportAirCraft() 10 | { 11 | return new Helicopter(); 12 | } 13 | 14 | public ILandvehicle CreateTransportVehicle() 15 | { 16 | return new Motorcycle(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Factories/UberTransport.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_3.Aircrafts; 2 | using CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles; 3 | 4 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Factories 5 | { 6 | class UberTransport : ITransporFactory 7 | { 8 | public IAircraft CreateTransportAirCraft() 9 | { 10 | return new Airplane(); 11 | } 12 | 13 | public ILandvehicle CreateTransportVehicle() 14 | { 15 | return new Car(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Landvehicles/Car.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles 3 | { 4 | class Car : ILandvehicle 5 | { 6 | public void GetCargo() 7 | { 8 | Console.WriteLine("We pick up the passengers and we are at the point"); 9 | } 10 | 11 | public void StartRoute() 12 | { 13 | GetCargo(); 14 | Console.WriteLine("Starting the path"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Landvehicles/ILandvehicle.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles 2 | { 3 | public interface ILandvehicle 4 | { 5 | void StartRoute(); 6 | void GetCargo(); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Landvehicles/Motorcycle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles 4 | { 5 | class Motorcycle : ILandvehicle 6 | { 7 | public void GetCargo() 8 | { 9 | Console.WriteLine("We pick up the package."); 10 | } 11 | 12 | public void StartRoute() 13 | { 14 | GetCargo(); 15 | Console.WriteLine("Starting the deilvery."); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/Example 3/Landvehicles/Scotter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace CreationPatterns._1__Abstract_Factory.Example_3.Landvehicles 3 | { 4 | public class Scotter : ILandvehicle 5 | { 6 | public void GetCargo() 7 | { 8 | Console.WriteLine("We pick up the package."); 9 | } 10 | 11 | public void StartRoute() 12 | { 13 | GetCargo(); 14 | Console.WriteLine("Starting the deilvery."); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/1- Abstract Factory/ExecuteAbstractFactory.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._1__Abstract_Factory.Example_2.ConcreteFactory; 2 | using CreationPatterns._1__Abstract_Factory.Example_2.Interface; 3 | using CreationPatterns._1__Abstract_Factory.Example_3; 4 | using CreationPatterns._1__Abstract_Factory.Example_3.Factories; 5 | using System; 6 | 7 | namespace DesignPatterns_1_Creational_1_Abstract_Factory 8 | { 9 | /// 10 | /// Here we can call kinde examples the Abstract Factory 11 | /// 12 | public class ExecuteAbstractFactory 13 | { 14 | ITransporFactory factory; 15 | public void ExampleOne() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public void Products() 21 | { 22 | // This an example two the RefactoringGuru for more information, visit the repository link bellow 23 | // https://github.com/RefactoringGuru/design-patterns-csharp 24 | 25 | // EN: The client code can work with any concrete factory class. 26 | Console.WriteLine("Client: Testing client code with the first factory type..."); 27 | ExampleTwoClientMethod(new ConcreteFactory1()); 28 | Console.WriteLine(); 29 | 30 | Console.WriteLine("Client: Testing the same client code with the second factory type..."); 31 | ExampleTwoClientMethod(new ConcreteFactory2()); 32 | } 33 | 34 | public void Transport() 35 | { 36 | ApplicationExecute application = ConfigureApplication(); 37 | 38 | application.StartRoute(); 39 | Console.ReadLine(); 40 | } 41 | 42 | private ApplicationExecute ConfigureApplication() 43 | { 44 | ApplicationExecute app; 45 | 46 | Console.WriteLine("Select a service the type of service"); 47 | Console.WriteLine(); 48 | Console.WriteLine("1- Uber"); 49 | Console.WriteLine("2- 99"); 50 | Console.WriteLine("3- Lime"); 51 | 52 | var company = Console.ReadKey(); 53 | Console.WriteLine(); 54 | 55 | switch (company.KeyChar) 56 | { 57 | case '1': 58 | factory = new UberTransport(); 59 | break; 60 | 61 | case '2': 62 | factory = new NineNineTransport(); 63 | break; 64 | 65 | case '3': 66 | factory = new LimeTransport(); 67 | break; 68 | } 69 | 70 | app = new ApplicationExecute(factory); 71 | 72 | return app; 73 | } 74 | 75 | private void ExampleTwoClientMethod(IAbstractFactory factory) 76 | { 77 | // this is method reference example two Abstract Factory 78 | 79 | var productA = factory.CreateProductA(); 80 | var productB = factory.CreateProductB(); 81 | 82 | Console.WriteLine(productB.UsefulFunctionB()); 83 | Console.WriteLine(productB.AnotherUsefulFunctionB(productA)); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 1/Factories/BikeTransport.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_1.Interface; 2 | using CreationPatterns._2__Factory_Method.Example_1.Vehicles; 3 | 4 | namespace CreationPatterns._2__Factory_Method.Example_1.Factories 5 | { 6 | class BikeTransport : Transport 7 | { 8 | protected override IVehicles CreateTransport() 9 | { 10 | return new Bike(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 1/Factories/CarTransport.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_1.Interface; 2 | namespace CreationPatterns._2__Factory_Method.Example_1.Factories 3 | { 4 | class CarTransport : Transport 5 | { 6 | protected override IVehicles CreateTransport() 7 | { 8 | return new Car(); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 1/Factories/MotorcycleTransport.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_1.Interface; 2 | using CreationPatterns._2__Factory_Method.Example_1.Vehicles; 3 | 4 | namespace CreationPatterns._2__Factory_Method.Example_1.Factories 5 | { 6 | class MotorcycleTransport : Transport 7 | { 8 | protected override IVehicles CreateTransport() 9 | { 10 | return new Motorcycle(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 1/Factories/Transport.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_1.Interface; 2 | namespace CreationPatterns._2__Factory_Method.Example_1.Factories 3 | { 4 | abstract class Transport 5 | { 6 | public void StartTransport() 7 | { 8 | IVehicles vehicles = CreateTransport(); 9 | vehicles.StartRoute(); 10 | } 11 | 12 | protected abstract IVehicles CreateTransport(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 1/Interface/IVehicles.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._2__Factory_Method.Example_1.Interface 2 | { 3 | public interface IVehicles 4 | { 5 | void GetCargo(); 6 | void StartRoute(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 1/Vehicles/Bike.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_1.Interface; 2 | using System; 3 | 4 | namespace CreationPatterns._2__Factory_Method.Example_1.Vehicles 5 | { 6 | public class Bike : IVehicles 7 | { 8 | public void GetCargo() 9 | { 10 | Console.WriteLine("Get package"); 11 | } 12 | 13 | public void StartRoute() 14 | { 15 | GetCargo(); 16 | Console.WriteLine("Start delivery"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 1/Vehicles/Car.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_1.Interface; 2 | using System; 3 | 4 | namespace CreationPatterns._2__Factory_Method.Example_1 5 | { 6 | public class Car : IVehicles 7 | { 8 | public void GetCargo() 9 | { 10 | Console.WriteLine("Get passangers"); 11 | } 12 | 13 | public void StartRoute() 14 | { 15 | GetCargo(); 16 | Console.WriteLine("Start the route"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 1/Vehicles/Motorcycle.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_1.Interface; 2 | using System; 3 | 4 | namespace CreationPatterns._2__Factory_Method.Example_1.Vehicles 5 | { 6 | public class Motorcycle : IVehicles 7 | { 8 | public void GetCargo() 9 | { 10 | Console.WriteLine("Get food"); 11 | } 12 | 13 | public void StartRoute() 14 | { 15 | GetCargo(); 16 | Console.WriteLine("Start delivery"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 2/Banks/Account.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_2.Interface; 2 | using System; 3 | 4 | namespace CreationPatterns._2__Factory_Method.Example_2.Banks 5 | { 6 | public class Account : IBanks 7 | { 8 | public void GetBalance() 9 | { 10 | Console.WriteLine("Your balance account is: 1,500U$"); 11 | } 12 | 13 | public void Transfer() 14 | { 15 | GetBalance(); 16 | Console.WriteLine("Transfer was successful"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 2/Banks/InvestmentAccounts.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_2.Interface; 2 | using System; 3 | 4 | namespace CreationPatterns._2__Factory_Method.Example_2.Banks 5 | { 6 | public class InvestmentAccounts : IBanks 7 | { 8 | public void GetBalance() 9 | { 10 | Console.WriteLine("The total value of your assets is: 10,500U$"); 11 | } 12 | 13 | public void Transfer() 14 | { 15 | GetBalance(); 16 | Console.WriteLine("Transfer was successful"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 2/Factories/AccountFactory.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_2.Banks; 2 | using CreationPatterns._2__Factory_Method.Example_2.Factories; 3 | using CreationPatterns._2__Factory_Method.Example_2.Interface; 4 | 5 | namespace CreationPatterns._2__Factory_Method.Example_2.Factory 6 | { 7 | class AccountFactory : BankFactory 8 | { 9 | protected override IBanks CreateAccount() 10 | { 11 | return new Account(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 2/Factories/BankFactory.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_2.Interface; 2 | 3 | namespace CreationPatterns._2__Factory_Method.Example_2.Factories 4 | { 5 | abstract class BankFactory 6 | { 7 | public void GetMoney() 8 | { 9 | IBanks banks = CreateAccount(); 10 | banks.Transfer(); 11 | } 12 | 13 | protected abstract IBanks CreateAccount(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 2/Factories/InvestmentAccountFactory.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_2.Banks; 2 | using CreationPatterns._2__Factory_Method.Example_2.Interface; 3 | 4 | namespace CreationPatterns._2__Factory_Method.Example_2.Factories 5 | { 6 | class InvestmentAccountFactory : BankFactory 7 | { 8 | protected override IBanks CreateAccount() 9 | { 10 | return new InvestmentAccounts(); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 2/Interface/IBanks.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._2__Factory_Method.Example_2.Interface 2 | { 3 | public interface IBanks 4 | { 5 | void GetBalance(); 6 | void Transfer(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 3/Factories/SupplierFactory.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_3.SupplierProducts; 2 | 3 | namespace CreationPatterns._2__Factory_Method.Example_3.Factories 4 | { 5 | class SupplierFactory : SupplierProductsFactory 6 | { 7 | protected override ISupplier GetProductsPriceUpdate() 8 | { 9 | return new Suplpiers(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 3/Factories/SupplierProductsFactory.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_3.SupplierProducts; 2 | 3 | namespace CreationPatterns._2__Factory_Method.Example_3.Factories 4 | { 5 | abstract class SupplierProductsFactory 6 | { 7 | public void GetProductsSupplier() 8 | { 9 | ISupplier supplier = GetProductsPriceUpdate(); 10 | supplier.UpdateSupplierProductPrice(); 11 | } 12 | 13 | protected abstract ISupplier GetProductsPriceUpdate(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 3/Interface/ISupplier.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._2__Factory_Method.Example_3.SupplierProducts 2 | { 3 | public interface ISupplier 4 | { 5 | void GetSupplier(); 6 | void UpdateSupplierProductPrice(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/Example 3/SupplierProducts/Suplpiers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace CreationPatterns._2__Factory_Method.Example_3.SupplierProducts 4 | { 5 | public class Suplpiers : ISupplier 6 | { 7 | public void GetSupplier() 8 | { 9 | Console.WriteLine(" \n The Supplier is: \n Amazon, \n Alibaba, \n Shopee \n AliExpress \n "); 10 | } 11 | 12 | public void UpdateSupplierProductPrice() 13 | { 14 | GetSupplier(); 15 | Console.WriteLine("Supplier update was successful!"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/2- Factory Method/ExecuteFactoryMethod.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._2__Factory_Method.Example_1.Factories; 2 | using CreationPatterns._2__Factory_Method.Example_2.Factories; 3 | using CreationPatterns._2__Factory_Method.Example_2.Factory; 4 | using CreationPatterns._2__Factory_Method.Example_3.Factories; 5 | using System; 6 | 7 | namespace DesignPatterns._1__Creational._1._2_Factory_Method 8 | { 9 | public class ExecuteFactoryMethod 10 | { 11 | public void Transport() 12 | { 13 | Console.WriteLine("Select a service the type of service"); 14 | Console.WriteLine(); 15 | Console.WriteLine("1- Uber"); 16 | Console.WriteLine("2- Loggi"); 17 | Console.WriteLine("3- Bike"); 18 | 19 | var option = Console.ReadKey(); 20 | Transport transport = null; 21 | 22 | switch (option.KeyChar) 23 | { 24 | case '1': 25 | transport = new CarTransport(); 26 | break; 27 | 28 | case '2': 29 | transport = new MotorcycleTransport(); 30 | break; 31 | 32 | case '3': 33 | transport = new BikeTransport(); 34 | break; 35 | } 36 | 37 | if (transport != null) { transport.StartTransport(); } 38 | 39 | Console.ReadLine(); 40 | } 41 | 42 | public void Banks() 43 | { 44 | Console.WriteLine("Select an account"); 45 | Console.WriteLine(); 46 | Console.WriteLine("1- Account"); 47 | Console.WriteLine("2- Investment Account"); 48 | 49 | var option = Console.ReadKey(); 50 | BankFactory bank = null; 51 | 52 | switch (option.KeyChar) 53 | { 54 | case '1': 55 | bank = new AccountFactory(); 56 | break; 57 | 58 | case '2': 59 | bank = new InvestmentAccountFactory(); 60 | break; 61 | 62 | } 63 | 64 | if (bank != null) { bank.GetMoney(); } 65 | 66 | Console.ReadLine(); 67 | } 68 | 69 | public void Suppliers() 70 | { 71 | Console.WriteLine("type 1 to enter"); 72 | Console.WriteLine(); 73 | 74 | var option = Console.ReadKey(); 75 | SupplierProductsFactory supplierProducts = null; 76 | 77 | switch (option.KeyChar) 78 | { 79 | case '1': 80 | supplierProducts = new SupplierFactory(); 81 | break; 82 | } 83 | 84 | if (supplierProducts != null) 85 | supplierProducts.GetProductsSupplier(); 86 | 87 | Console.ReadLine(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/3- Singleton/Singleton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace DesignPatterns._1__Creational._1._3_Singleton 6 | { 7 | public class Singleton 8 | { 9 | public static void Execute() 10 | { 11 | throw new NotImplementedException(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/Example 1/Builders/IBuilder.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._4__Builder.Example_1.Components; 2 | using CreationPatterns._4__Builder.Example_1.Products; 3 | 4 | namespace CreationPatterns._4__Builder.Example_1.Builders 5 | { 6 | interface IBuilder 7 | { 8 | void Reset(); 9 | Vehicle GetVehicle(); 10 | void SetSeats(int seats); 11 | void SetEngine(Engine engine); 12 | void SetTransmission(Transmission transmission); 13 | void SetVehicleType(VehicleType vehicleType); 14 | void SetAirBagType(AirBag airBag); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/Example 1/Builders/VehicleBuilder.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._4__Builder.Example_1.Components; 2 | using CreationPatterns._4__Builder.Example_1.Products; 3 | 4 | namespace CreationPatterns._4__Builder.Example_1.Builders 5 | { 6 | class VehicleBuilder : IBuilder 7 | { 8 | private Vehicle vehicle = new Vehicle(); 9 | 10 | public Vehicle GetVehicle() 11 | { 12 | Vehicle result = vehicle; 13 | Reset(); 14 | return result; 15 | } 16 | 17 | public void Reset() 18 | { 19 | vehicle = new Vehicle(); 20 | } 21 | 22 | public void SetAirBagType(AirBag airBag) 23 | { 24 | vehicle.AirBag = airBag; 25 | } 26 | 27 | public void SetEngine(Engine engine) 28 | { 29 | vehicle.Engine = engine; 30 | } 31 | 32 | public void SetSeats(int seats) 33 | { 34 | vehicle.Seats = seats; 35 | } 36 | 37 | public void SetTransmission(Transmission transmission) 38 | { 39 | vehicle.Transmission = transmission; 40 | } 41 | 42 | public void SetVehicleType(VehicleType vehicleType) 43 | { 44 | vehicle.VehicleType = vehicleType; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/Example 1/Components/AirBag.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._4__Builder.Example_1.Components 2 | { 3 | enum AirBag 4 | { 5 | AIRBAGS_FRONT, 6 | AIRBAGS_SIDE, 7 | AIRBAGS_SIDE_CURTAIN, 8 | AIRBAGS_SIDE_KNEE, 9 | AIRBAGS_SIDE_CENTRAL, 10 | AIRBAGS_SIDE_BELT, 11 | AIRBAGS_SIDE_HOOD 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/Example 1/Components/Engine.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._4__Builder.Example_1.Components 2 | { 3 | public class Engine 4 | { 5 | private int power; 6 | public int Power { get => power; set => power = value; } 7 | 8 | public Engine(int power) 9 | { 10 | this.Power = power; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/Example 1/Components/Transmission.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._4__Builder.Example_1.Components 2 | { 3 | enum Transmission 4 | { 5 | MANUAL, 6 | AUTOMATIC, 7 | AUTOMATIC_SEQUENTIAL 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/Example 1/Components/VehicleType.cs: -------------------------------------------------------------------------------- 1 | namespace CreationPatterns._4__Builder.Example_1.Components 2 | { 3 | enum VehicleType 4 | { 5 | SEDAN, 6 | SPORTCAR, 7 | PICKUPTRUCK, 8 | TRUCK, 9 | SUV 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/Example 1/Directors/Director.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._4__Builder.Example_1.Builders; 2 | using CreationPatterns._4__Builder.Example_1.Components; 3 | 4 | namespace CreationPatterns._4__Builder.Example_1.Directors 5 | { 6 | class Director 7 | { 8 | IBuilder builder; 9 | 10 | public Director(IBuilder builder) 11 | { 12 | this.builder = builder; 13 | } 14 | 15 | public void ConstructSedanCar() 16 | { 17 | builder.SetVehicleType(VehicleType.SEDAN); 18 | builder.SetEngine(new Engine(2000)); 19 | builder.SetSeats(5); 20 | builder.SetTransmission(Transmission.AUTOMATIC); 21 | } 22 | 23 | public void ConstructTruck() 24 | { 25 | builder.SetVehicleType(VehicleType.TRUCK); 26 | builder.SetEngine(new Engine(4000)); 27 | builder.SetSeats(2); 28 | builder.SetTransmission(Transmission.MANUAL); 29 | } 30 | public void ConstructSUV() 31 | { 32 | builder.SetVehicleType(VehicleType.SUV); 33 | builder.SetEngine(new Engine(2000)); 34 | builder.SetSeats(6); 35 | builder.SetTransmission(Transmission.AUTOMATIC_SEQUENTIAL); 36 | builder.SetAirBagType(AirBag.AIRBAGS_FRONT); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/Example 1/Products/Vehicle.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._4__Builder.Example_1.Components; 2 | 3 | namespace CreationPatterns._4__Builder.Example_1.Products 4 | { 5 | class Vehicle 6 | { 7 | private VehicleType vehicleType; 8 | private int seats; 9 | private Engine engine; 10 | private Transmission transmission; 11 | private AirBag airBag; 12 | 13 | public VehicleType VehicleType 14 | { 15 | get => vehicleType; 16 | set => vehicleType = value; 17 | } 18 | 19 | public int Seats 20 | { 21 | get => seats; 22 | set => seats = value; 23 | } 24 | 25 | public Engine Engine 26 | { 27 | get => engine; 28 | set => engine = value; 29 | } 30 | 31 | public Transmission Transmission 32 | { 33 | get => transmission; 34 | set => transmission = value; 35 | } 36 | 37 | public AirBag AirBag 38 | { 39 | get => airBag; 40 | set => airBag = value; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/4- Builder/ExecuteBuilder.cs: -------------------------------------------------------------------------------- 1 | using CreationPatterns._4__Builder.Example_1.Builders; 2 | using CreationPatterns._4__Builder.Example_1.Directors; 3 | using CreationPatterns._4__Builder.Example_1.Products; 4 | using System; 5 | 6 | namespace DesignPatterns._1__Creational._1._2_Builder 7 | { 8 | public class ExecuteBuilder 9 | { 10 | public void Vehicle() 11 | { 12 | VehicleBuilder builder = new VehicleBuilder(); 13 | Director director = new Director(builder); 14 | 15 | director.ConstructSedanCar(); 16 | director.ConstructTruck(); 17 | director.ConstructSUV(); 18 | 19 | Vehicle sedan = builder.GetVehicle(); 20 | Vehicle truck = builder.GetVehicle(); 21 | Vehicle suv = builder.GetVehicle(); 22 | 23 | Console.WriteLine($"Created an vehicle of type: {sedan.VehicleType}"); 24 | Console.WriteLine($"Created an vehicle of type: {truck.VehicleType}"); 25 | Console.WriteLine($"Created an vehicle of type: {suv.VehicleType}"); 26 | Console.Read(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/CreationPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DesignPatterns/CreationPatterns/CreationalPatterns.cs: -------------------------------------------------------------------------------- 1 | using DesignPatterns._1__Creational._1._2_Factory_Method; 2 | using DesignPatterns_1_Creational_1_Abstract_Factory; 3 | using DesignPatterns._1__Creational._1._2_Builder; 4 | using System; 5 | 6 | namespace CreationPatterns 7 | { 8 | public class CreationalPatterns 9 | { 10 | static void Main(string[] args) 11 | { 12 | Console.WriteLine("..:: Creational Patterns select an option ::.."); 13 | Console.WriteLine(); 14 | Console.WriteLine("1 - Abstract Factory - Example Bank"); 15 | Console.WriteLine("2 - Abstract Factory - Example Products"); 16 | Console.WriteLine("3 - Abstract Factory - Example Transport"); 17 | Console.WriteLine("4 - Factory Method - Example Transport"); 18 | Console.WriteLine("5 - Factory Method - Example Banks"); 19 | Console.WriteLine("6 - Factory Method - Example Supplier"); 20 | Console.WriteLine("7 - Builder - Example Vehicle"); 21 | Console.WriteLine(); 22 | 23 | var option = Console.ReadKey(); 24 | Console.WriteLine(); 25 | 26 | switch (option.KeyChar) 27 | { 28 | case '1': 29 | new ExecuteAbstractFactory().ExampleOne(); 30 | break; 31 | 32 | case '2': 33 | new ExecuteAbstractFactory().Products(); 34 | break; 35 | 36 | case '3': 37 | new ExecuteAbstractFactory().Transport(); 38 | break; 39 | 40 | case '4': 41 | new ExecuteFactoryMethod().Transport(); 42 | break; 43 | 44 | case '5': 45 | new ExecuteFactoryMethod().Banks(); 46 | break; 47 | 48 | 49 | case '6': 50 | new ExecuteFactoryMethod().Suppliers(); 51 | break; 52 | 53 | case '7': 54 | new ExecuteBuilder().Vehicle(); 55 | break; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /DesignPatterns/DesignPatterns.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29609.76 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreationPatterns", "CreationPatterns\CreationPatterns.csproj", "{E6223F98-0B14-4436-8BB4-A0C033093A1F}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructuralPatterns", "StructuralPatterns\StructuralPatterns.csproj", "{0D19D411-5D2E-43BF-BA95-D339B13659FC}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BehavioralPatterns", "BehavioralPatterns\BehavioralPatterns.csproj", "{679B5AD9-EC78-49AE-B8E7-1DFDFB793B9D}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E6223F98-0B14-4436-8BB4-A0C033093A1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {E6223F98-0B14-4436-8BB4-A0C033093A1F}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {E6223F98-0B14-4436-8BB4-A0C033093A1F}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {E6223F98-0B14-4436-8BB4-A0C033093A1F}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {0D19D411-5D2E-43BF-BA95-D339B13659FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {0D19D411-5D2E-43BF-BA95-D339B13659FC}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {0D19D411-5D2E-43BF-BA95-D339B13659FC}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {0D19D411-5D2E-43BF-BA95-D339B13659FC}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {679B5AD9-EC78-49AE-B8E7-1DFDFB793B9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {679B5AD9-EC78-49AE-B8E7-1DFDFB793B9D}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {679B5AD9-EC78-49AE-B8E7-1DFDFB793B9D}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {679B5AD9-EC78-49AE-B8E7-1DFDFB793B9D}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {C3F19568-9A12-4487-8D42-9E7F96BFD473} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/ExecuteBridge.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._1__Bridge.Plataforms; 2 | using StructuralPatterns._1__Bridge.Plataforms.Interface; 3 | using StructuralPatterns._1__Bridge.Transmissions; 4 | using System; 5 | 6 | namespace StructuralPatterns._1__Bridge 7 | { 8 | public class ExecuteBridge 9 | { 10 | public void TestBridgePlatform() 11 | { 12 | StartLive(new Youtube()); 13 | StartLive(new Facebook()); 14 | StartLiveAdvanced(new TwitchTV()); 15 | StartLiveAdvanced(new DLive()); 16 | Console.ReadLine(); 17 | } 18 | 19 | private void StartLive(IPlatform platform) 20 | { 21 | Console.WriteLine("Please wait"); 22 | Live live = new Live(platform); 23 | 24 | live.Broadcasting(); 25 | live.Result(); 26 | } 27 | private void StartLiveAdvanced(IPlatform platform) 28 | { 29 | Console.WriteLine("Please wait"); 30 | AdvancedLive live = new AdvancedLive(platform); 31 | 32 | live.Broadcasting(); 33 | live.Subtitle(); 34 | live.Comments(); 35 | live.Record(); 36 | live.Result(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/Plataforms/DLive.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._1__Bridge.Plataforms.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._1__Bridge.Plataforms 5 | { 6 | public class DLive : IPlatform 7 | { 8 | public DLive() 9 | { 10 | ConfigureRMTP(); 11 | Console.WriteLine("Facebook: Transmission started"); 12 | } 13 | public void AuthToken() 14 | { 15 | Console.WriteLine("Facebook: Authorized application"); 16 | } 17 | 18 | public void ConfigureRMTP() 19 | { 20 | AuthToken(); 21 | Console.WriteLine("DLive: Configuring RMTP server"); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/Plataforms/Facebook.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._1__Bridge.Plataforms.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._1__Bridge.Plataforms 5 | { 6 | public class Facebook : IPlatform 7 | { 8 | public Facebook() 9 | { 10 | ConfigureRMTP(); 11 | Console.WriteLine("Facebook: Transmission started"); 12 | } 13 | 14 | public void AuthToken() 15 | { 16 | Console.WriteLine("Facebook: Authorized application"); 17 | } 18 | 19 | public void ConfigureRMTP() 20 | { 21 | AuthToken(); 22 | Console.WriteLine("Facebook: Configuring RMTP server"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/Plataforms/IPlatform.cs: -------------------------------------------------------------------------------- 1 | namespace StructuralPatterns._1__Bridge.Plataforms.Interface 2 | { 3 | public interface IPlatform 4 | { 5 | void ConfigureRMTP(); 6 | void AuthToken(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/Plataforms/TwitchTV.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._1__Bridge.Plataforms.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._1__Bridge.Plataforms 5 | { 6 | public class TwitchTV : IPlatform 7 | { 8 | public TwitchTV() 9 | { 10 | ConfigureRMTP(); 11 | Console.WriteLine("TwitchTV: Transmission started"); 12 | } 13 | 14 | public void AuthToken() 15 | { 16 | Console.WriteLine("TwitchTV: Authorized application"); 17 | } 18 | 19 | public void ConfigureRMTP() 20 | { 21 | AuthToken(); 22 | Console.WriteLine("TwitchTV: Configuring RMTP server"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/Plataforms/Youtube.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._1__Bridge.Plataforms.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._1__Bridge.Plataforms 5 | { 6 | public class Youtube : IPlatform 7 | { 8 | public Youtube() 9 | { 10 | ConfigureRMTP(); 11 | Console.WriteLine("Youtube: Transmission started"); 12 | } 13 | 14 | public void AuthToken() 15 | { 16 | Console.WriteLine("Youtube: Authorized application"); 17 | } 18 | 19 | public void ConfigureRMTP() 20 | { 21 | AuthToken(); 22 | Console.WriteLine("Youtube: Configuring RMTP server"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/Transmissions/AdvancedLive.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._1__Bridge.Plataforms.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._1__Bridge.Transmissions 5 | { 6 | public class AdvancedLive : Live 7 | { 8 | public AdvancedLive(IPlatform platform): base(platform) 9 | { 10 | } 11 | 12 | public void Subtitle() 13 | { 14 | Console.WriteLine("-- Active subtitles in the broadcast --"); 15 | } 16 | 17 | public void Comments() 18 | { 19 | Console.WriteLine("-- Comments released on live --"); 20 | } 21 | 22 | public void Record() 23 | { 24 | Console.WriteLine("-- Ready to record --"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/Transmissions/ITransmission.cs: -------------------------------------------------------------------------------- 1 | namespace StructuralPatterns._1__Bridge.Transmissions 2 | { 3 | public interface ITransmission 4 | { 5 | void Broadcasting(); 6 | void Result(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/1- Bridge/Transmissions/Live.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._1__Bridge.Plataforms.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._1__Bridge.Transmissions 5 | { 6 | public class Live : ITransmission 7 | { 8 | protected IPlatform _platform; 9 | public Live(IPlatform plataform) 10 | { 11 | _platform = plataform; 12 | } 13 | public void Broadcasting() 14 | { 15 | Console.WriteLine($"Starting the transmission in {_platform}"); 16 | } 17 | 18 | public void Result() 19 | { 20 | Console.WriteLine("-- On AIR ---"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/ExecuteAdapter.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._2__Adapter 5 | { 6 | public class ExecuteAdapter 7 | { 8 | public void Payment() 9 | { 10 | //Paypal payment = new Paypal(); 11 | //payment.PayPalPayment(); 12 | //payment.PayPalReceive(); 13 | 14 | //IPaypalPayment payment = new PayonnerAdapter(new Payonner()); 15 | //payment.PayPalPayment(); 16 | //payment.PayPalReceive(); 17 | 18 | IMercadoPagoPayment payment = new MercadoPagoAdapter(new MercadoPago()); 19 | payment.BlocksPayment(); 20 | payment.SendPayment(); 21 | payment.ValidateBank(); 22 | 23 | Console.ReadLine(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/Interface/IMercadoPagoPayment.cs: -------------------------------------------------------------------------------- 1 | namespace StructuralPatterns._2__Adapter.Interface 2 | { 3 | interface IMercadoPagoPayment 4 | { 5 | Token AuthToken(); 6 | 7 | void SendPayment(); 8 | void ValidateBank(); 9 | void ReceivePayment(); 10 | void BlocksPayment(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/Interface/IPayonnerPayment.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace StructuralPatterns._2__Adapter.Interface 3 | { 4 | public interface IPayonnerPayment 5 | { 6 | Token AuthToken(); 7 | void SendPayment(); 8 | void ReceivePayment(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/Interface/IPaypalPayment.cs: -------------------------------------------------------------------------------- 1 | namespace StructuralPatterns._2__Adapter.Interface 2 | { 3 | public interface IPaypalPayment 4 | { 5 | Token AuthToken(); 6 | void PayPalPayment(); 7 | void PayPalReceive(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/MercadoPago.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._2__Adapter 5 | { 6 | public class MercadoPago : IMercadoPagoPayment 7 | { 8 | private Token token; 9 | public Token AuthToken() 10 | { 11 | return new Token(); 12 | } 13 | 14 | public void BlocksPayment() 15 | { 16 | Console.WriteLine("Payment blocked to be analyzed"); 17 | } 18 | 19 | public void ReceivePayment() 20 | { 21 | token = AuthToken(); 22 | Console.WriteLine("Receiving payment with Payonner"); 23 | } 24 | 25 | public void SendPayment() 26 | { 27 | token = AuthToken(); 28 | Console.WriteLine("Sending payment with Payonner"); 29 | } 30 | 31 | public void ValidateBank() 32 | { 33 | Console.WriteLine("Validating Bank"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/MercadoPagoAdapter.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._2__Adapter 5 | { 6 | public class MercadoPagoAdapter : IMercadoPagoPayment 7 | { 8 | private MercadoPago _mercadoPago; 9 | 10 | public MercadoPagoAdapter(MercadoPago mercadoPago) 11 | { 12 | _mercadoPago = mercadoPago; 13 | Console.WriteLine("Making the MercadoPago Adaptation to Paypal methods"); 14 | } 15 | public Token AuthToken() 16 | { 17 | return _mercadoPago.AuthToken(); 18 | } 19 | 20 | public void BlocksPayment() 21 | { 22 | _mercadoPago.BlocksPayment(); 23 | } 24 | 25 | public void ReceivePayment() 26 | { 27 | _mercadoPago.ReceivePayment(); 28 | } 29 | 30 | public void SendPayment() 31 | { 32 | _mercadoPago.SendPayment(); 33 | } 34 | 35 | public void ValidateBank() 36 | { 37 | _mercadoPago.ValidateBank(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/Payonner.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._2__Adapter 5 | { 6 | public class Payonner : IPayonnerPayment 7 | { 8 | private Token token; 9 | 10 | public Token AuthToken() 11 | { 12 | return new Token(); 13 | } 14 | 15 | public void ReceivePayment() 16 | { 17 | token = AuthToken(); 18 | Console.WriteLine("Receiving payment with Payonner"); 19 | } 20 | 21 | public void SendPayment() 22 | { 23 | token = AuthToken(); 24 | Console.WriteLine("Sending payment with Payonner"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/PayonnerAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace StructuralPatterns._2__Adapter.Interface 4 | { 5 | class PayonnerAdapter : IPaypalPayment 6 | { 7 | private Payonner _payonner; 8 | public PayonnerAdapter(Payonner payonner) 9 | { 10 | _payonner = payonner; 11 | Console.WriteLine("Making the Payonner Adaptation to Paypal methods"); 12 | } 13 | public Token AuthToken() 14 | { 15 | return _payonner.AuthToken(); 16 | } 17 | 18 | public void PayPalPayment() 19 | { 20 | _payonner.SendPayment(); 21 | } 22 | 23 | public void PayPalReceive() 24 | { 25 | _payonner.ReceivePayment(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/Paypal.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._2__Adapter 5 | { 6 | class Paypal : IPaypalPayment 7 | { 8 | private Token token; 9 | public Token AuthToken() 10 | { 11 | return new Token(); 12 | } 13 | 14 | public void PayPalPayment() 15 | { 16 | token = AuthToken(); 17 | Console.WriteLine("Send payment with Paypal"); 18 | } 19 | 20 | public void PayPalReceive() 21 | { 22 | Console.WriteLine("Receiving payment with Paypal"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 1/Token.cs: -------------------------------------------------------------------------------- 1 | namespace StructuralPatterns._2__Adapter 2 | { 3 | public class Token 4 | { 5 | private string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9.-S-mbb4Jey64PEPOvsNNRyO5QXDksdT9H91csGHpa6A"; 6 | public string GetToken() 7 | { 8 | return token; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 2/Amazon.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Example_2.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._2__Adapter.Example_2 5 | { 6 | public class Amazon : IAmazonSupplier 7 | { 8 | public void SendProduct() 9 | { 10 | Console.WriteLine("Send the product"); 11 | } 12 | public void ValidateProductPrice() 13 | { 14 | Console.WriteLine("Validating product"); 15 | } 16 | 17 | public void SendProductPrice() 18 | { 19 | Console.WriteLine("Send the product price"); 20 | } 21 | 22 | public void UpdateStock() 23 | { 24 | Console.WriteLine("Update Stock"); 25 | } 26 | 27 | public void UpdateStore() 28 | { 29 | Console.WriteLine("Update Store"); 30 | } 31 | 32 | public void UpdateWarehouse() 33 | { 34 | Console.WriteLine("Update Warehouse"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 2/AmazonAdapter.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Example_2.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._2__Adapter.Example_2 5 | { 6 | public class AmazonAdapter : IAmazonSupplier 7 | { 8 | private Amazon _amazon; 9 | 10 | public AmazonAdapter(Amazon amazon) 11 | { 12 | _amazon = amazon; 13 | Console.WriteLine("Making the Amazon Adaptation to MagazineLuiza methods"); 14 | } 15 | 16 | public void SendProduct() 17 | { 18 | _amazon.SendProduct(); 19 | } 20 | public void ValidateProductPrice() 21 | { 22 | _amazon.ValidateProductPrice(); 23 | } 24 | 25 | public void SendProductPrice() 26 | { 27 | _amazon.SendProductPrice(); 28 | } 29 | 30 | public void UpdateStock() 31 | { 32 | _amazon.UpdateStock(); 33 | } 34 | 35 | public void UpdateStore() 36 | { 37 | _amazon.UpdateStore(); 38 | } 39 | 40 | public void UpdateWarehouse() 41 | { 42 | _amazon.UpdateWarehouse(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 2/ExecuteAdapterEcommerce.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Example_2.Interface; 2 | 3 | namespace StructuralPatterns._2__Adapter.Example_2 4 | { 5 | public class ExecuteAdapterEcommerce 6 | { 7 | public void Ecommerce() 8 | { 9 | //MagazineLuiza magazineLuiza = new MagazineLuiza(); 10 | //magazineLuiza.SendProduct(); 11 | //magazineLuiza.ValidateProductPrice(); 12 | //magazineLuiza.SendProductPrice(); 13 | //magazineLuiza.UpdateStock(); 14 | 15 | IAmazonSupplier amazon = new AmazonAdapter(new Amazon()); 16 | amazon.SendProduct(); 17 | amazon.ValidateProductPrice(); 18 | amazon.SendProductPrice(); 19 | amazon.UpdateStock(); 20 | amazon.UpdateStore(); 21 | amazon.UpdateWarehouse(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 2/Interface/IAmazonSupplier.cs: -------------------------------------------------------------------------------- 1 | namespace StructuralPatterns._2__Adapter.Example_2.Interface 2 | { 3 | public interface IAmazonSupplier 4 | { 5 | void SendProduct(); 6 | void ValidateProductPrice(); 7 | void SendProductPrice(); 8 | void UpdateStock(); 9 | void UpdateWarehouse(); 10 | void UpdateStore(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 2/Interface/IMagazineLuizaSupplier.cs: -------------------------------------------------------------------------------- 1 | namespace StructuralPatterns._2__Adapter.Example_2.Interface 2 | { 3 | public interface IMagazineLuizaSupplier 4 | { 5 | void SendProduct(); 6 | void ValidateProductPrice(); 7 | void SendProductPrice(); 8 | void UpdateStock(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/2- Adapter/Example 2/MagazineLuiza.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._2__Adapter.Example_2.Interface; 2 | using System; 3 | 4 | namespace StructuralPatterns._2__Adapter.Example_2 5 | { 6 | public class MagazineLuiza : IMagazineLuizaSupplier 7 | { 8 | public void SendProduct() 9 | { 10 | Console.WriteLine("Send the product"); 11 | } 12 | public void ValidateProductPrice() 13 | { 14 | Console.WriteLine("Validating product"); 15 | } 16 | public void SendProductPrice() 17 | { 18 | Console.WriteLine("Send the product price"); 19 | } 20 | 21 | public void UpdateStock() 22 | { 23 | Console.WriteLine("Validating stock"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/StructuralPatterns.cs: -------------------------------------------------------------------------------- 1 | using StructuralPatterns._1__Bridge; 2 | using StructuralPatterns._2__Adapter; 3 | using StructuralPatterns._2__Adapter.Example_2; 4 | using System; 5 | 6 | namespace StructuralPatterns 7 | { 8 | class StructuralPatterns 9 | { 10 | static void Main(string[] args) 11 | { 12 | Console.WriteLine("..:: Structural Patterns select an option ::.."); 13 | Console.WriteLine(); 14 | Console.WriteLine("1 - Adapter Example Payment"); 15 | Console.WriteLine(); 16 | Console.WriteLine("2 - Adapter Example Ecommerce"); 17 | Console.WriteLine(); 18 | Console.WriteLine("3 - Bridge Platform"); 19 | Console.WriteLine(); 20 | Console.WriteLine("------------------------"); 21 | 22 | var option = Console.ReadKey(); 23 | 24 | switch (option.KeyChar) 25 | { 26 | case '1': 27 | new ExecuteAdapter().Payment(); 28 | break; 29 | 30 | case '2': 31 | new ExecuteAdapterEcommerce().Ecommerce(); 32 | break; 33 | 34 | case '3': 35 | new ExecuteBridge().TestBridgePlatform(); 36 | break; 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /DesignPatterns/StructuralPatterns/StructuralPatterns.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # :computer: :blue_book: Design-Patterns 2 | 3 | ##### Este repositório para quem tem interesse de se aprofundar mais em design patterns. Não coloquei todos os patterns, mas como vocês podem ver deixei os links de referência para poder consultar todos os patterns. 4 | 5 | #### Referências úteis: 6 | * :orange_book: Livro Mergulho nos Padrões de Projeto - (https://refactoring.guru/pt-br) 7 | * :video_camera: Arquitetura e Desenvolvimento de Software Plataforma Dev.IO - (https://desenvolvedor.io/) 8 | * :bookmark_tabs: Dofactory - (https://www.dofactory.com/net/abstract-factory-design-pattern) 9 | * :bookmark_tabs: Sourcemaking -https://sourcemaking.com/design_patterns 10 | 11 | ### 🛠 Tecnologias 12 | 13 | As seguintes ferramentas foram usadas na construção do projeto: 14 | 15 | - [C#](https://docs.microsoft.com/pt-br/dotnet/csharp/) 16 | 17 |

18 | 🚧 Projetos 🚀 Em construção... 🚧 19 |

20 | 21 | ## Creation Patterns 22 | ##### Os padrões criacionais fornecem vários mecanismos de criação de objetos, que aumentam a flexibilidade e reutilização de código já existente. 23 | 24 | ### Abstract Factory 25 | ##### Cria uma instância de diversas famílias de classes. É um padrão de projeto criacional que permite que você produza famílias de objetos relacionados sem ter que especificar suas classes concretas. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/abstract-factory) 26 | 27 | 28 | ### Factory Method 29 | ##### Cria uma instância de diversas derivações de classes. É um padrão criacional de projeto que fornece uma interface para criar objetos em uma superclasse, mas permite que as subclasses alterem o tipo de objetos que serão criados. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/factory-method) 30 | 31 | ### Singleton 32 | ##### Cria uma única instância que será utilizada por recursos. É um padrão de projeto criacional que permite a você garantir que uma classe tenha apenas uma instância, enquanto provê um ponto de acesso global para essa instância. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/singleton) 33 | 34 | 35 | 36 | ## Structural Patterns 37 | ##### Os padrões estruturais explicam como montar objetos e classes em estruturas maiores mas ainda mantendo essas estruturas flexíveis e eficientes. 38 | 39 | ### Bridge 40 | ##### O Bridge é um padrão de projeto estrutural que permite que você divida uma classe grande ou um conjunto de classes intimamente ligadas em duas hierarquias separadas—abstração e implementação—que podem ser desenvolvidas independentemente umas das outras. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/bridge) 41 | 42 | ### Adpter 43 | ##### O Adapter é um padrão de projeto estrutural que permite objetos com interfaces incompatíveis colaborarem entre si. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/adapter) 44 | 45 | ### Composite 46 | ##### O Composite é um padrão de projeto estrutural que permite que você componha objetos em estruturas de árvores e então trabalhe com essas estruturas como se elas fossem objetos individuais. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/composite) 47 | 48 | ### Decorator 49 | ##### O Decorator é um padrão de projeto estrutural que permite que você acople novos comportamentos para objetos ao colocá-los dentro de invólucros de objetos que contém os comportamentos. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/decorator) 50 | 51 | ### Facade 52 | ##### O Facade é um padrão de projeto estrutural que fornece uma interface simplificada para uma biblioteca, um framework, ou qualquer conjunto complexo de classes. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/facade) 53 | 54 | 55 | 56 | ## Behavioral Patterns 57 | #### Padrões comportamentais são voltados aos algoritmos e a designação de responsabilidades entre objetos. 58 | 59 | ### Iterator 60 | ##### O Iterator é um padrão de projeto comportamental que permite a você percorrer elementos de uma coleção sem expor as representações dele (lista, pilha, árvore, etc.). [Saiba mais](https://refactoring.guru/pt-br/design-patterns/iterator) 61 | 62 | ### Strategy 63 | ##### O Strategy é um padrão de projeto comportamental que permite que você defina uma família de algoritmos, coloque-os em classes separadas, e faça os objetos deles intercambiáveis. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/strategy) 64 | 65 | ### Mediator 66 | ##### O Mediator é um padrão de projeto comportamental que permite que você reduza as dependências caóticas entre objetos. O padrão restringe comunicações diretas entre objetos e os força a colaborar apenas através do objeto mediador. [Saiba mais](https://refactoring.guru/pt-br/design-patterns/mediator) 67 | 68 | 69 | 70 | 71 |
72 | 73 | ##### This repository is interested go deeper more into design patterns. I didn't put them all patterns, but as you can see I left some references links for consulation. 74 | 75 | #### References: 76 | * :orange_book: Designer Patterns book - (https://refactoring.guru/pt-br) 77 | * :bookmark_tabs: Dofactory - (https://www.dofactory.com/net/abstract-factory-design-pattern) 78 | * :bookmark_tabs: Sourcemaking -https://sourcemaking.com/design_patterns 79 | 80 | 81 | ## Creation Patterns 82 | ##### The creation patterns provide various object creation mechanisms with increase flexibility and reuse of existing code [Read more](https://refactoring.guru/design-patterns/creational-patterns) 83 | 84 | ### Abstract Factory 85 | ##### The Abstract Factory is a creational design pattern that lets you produce families of related objects wihout specifying ther concrete classes. [Read more](https://refactoring.guru/design-patterns/abstract-factory) 86 | 87 | ### Factory Method 88 | ##### The Factory Method is a creational design pattern that provides an interface of creating objects in a superclass, but allows subclass to alter the type of objects that will created. [Read more](https://refactoring.guru/design-patterns/factory-method) 89 | 90 | ### Singleton 91 | ##### The Singleton is a creational design pattern that lets you ensure that a class has only one instance, while priving a global access point to this instance.[Read more](https://refactoring.guru/design-patterns/singleton) 92 | 93 | 94 | ## Structural Patterns 95 | ##### Structural Patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient. 96 | 97 | ### Bridge 98 | ##### The Bridge is a structural design pattern that lets you split a large class or a set of closely releated classes into two separate hierarchies-abstraction and implementation-which can be developed independently of each other. [Read more](https://refactoring.guru/design-patterns/bridge) 99 | 100 | ### Adpter 101 | ##### The Adapter is a structural design pattern that allows objects with incompatible interfaces to collaborate. [Read more](https://refactoring.guru/design-patterns/adapter) 102 | 103 | ### Composite 104 | ##### The Composite is a structural design pattern that lets you compose objects into tree structures and then work with these structures as if they were individual objects. [Read more](https://refactoring.guru/design-patterns/composite) 105 | 106 | ### Decorator 107 | ##### The Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors. [Read more](https://refactoring.guru/design-patterns/decorator) 108 | 109 | ### Facade 110 | ##### The Facade is a structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of classes. [Read more](https://refactoring.guru/design-patterns/facade) 111 | 112 | --------------------------------------------------------------------------------