├── .gitattributes ├── .gitignore ├── Behavioral ├── ChainOfResponsibility │ ├── AuthorizationHandler.cs │ ├── BaseHandler.cs │ ├── ChainOfResponsibility.csproj │ ├── IHandler.cs │ ├── Program.cs │ ├── RequestContext.cs │ ├── ResultHandler.cs │ └── ValidationHandler.cs ├── Mediator │ ├── Button.cs │ ├── Checkbox.cs │ ├── Component.cs │ ├── IMediator.cs │ ├── Input.cs │ ├── Mediator.csproj │ ├── Program.cs │ └── RegisterClientView.cs ├── Observer │ ├── ISubscriber.cs │ ├── Observer.csproj │ ├── Program.cs │ ├── Publisher.cs │ └── Subscriber.cs ├── State │ ├── CardInserted.cs │ ├── Context.cs │ ├── NoCard.cs │ ├── NoCash.cs │ ├── PinInserted.cs │ ├── Program.cs │ ├── State.cs │ └── State.csproj ├── Strategy │ ├── BikeStrategy.cs │ ├── CarStrategy.cs │ ├── Coordinate.cs │ ├── IRouteStrategy.cs │ ├── Map.cs │ ├── Program.cs │ ├── Strategy.csproj │ └── WalkStrategy.cs └── TemplateMethod │ ├── CsvGenerator.cs │ ├── ExcelGenerator.cs │ ├── Generator.cs │ ├── PdfGenerator.cs │ ├── Program.cs │ └── TemplateMethod.csproj ├── Creational ├── AbstractFactory │ ├── AbstractFactory.csproj │ ├── Application.cs │ ├── IButton.cs │ ├── ITextbox.cs │ ├── IUIElementFactory.cs │ ├── MacButton.cs │ ├── MacFactory.cs │ ├── MacTextbox.cs │ ├── Program.cs │ ├── WindowTextbox.cs │ ├── WindowsButton.cs │ └── WindowsFactory.cs ├── Builder │ ├── Builder.csproj │ ├── Invoice.cs │ ├── InvoiceBuilder.cs │ └── Program.cs ├── Factory │ ├── Circle.cs │ ├── Factory.csproj │ ├── Program.cs │ ├── Rectangle.cs │ ├── Shape.cs │ ├── ShapeFactory.cs │ ├── ShapeType.cs │ └── Triangle.cs ├── Prototype │ └── Prototype │ │ ├── Border.cs │ │ ├── Circle.cs │ │ ├── Program.cs │ │ ├── Prototype.csproj │ │ ├── Rectangle.cs │ │ ├── Shape.cs │ │ └── Triangle.cs └── Singleton │ ├── Configuration.cs │ ├── Program.cs │ └── Singleton.csproj ├── DesignPatterns.sln ├── SOLID ├── DependencyInversion │ ├── AuthenticationManager.cs │ ├── DependencyInversion.csproj │ ├── EmailNotification.cs │ ├── INotificationSender.cs │ ├── Program.cs │ ├── SmsNotification.cs │ └── User.cs ├── InterfaceSegregation │ ├── Cannon.cs │ ├── HpLaserJet.cs │ ├── IPrinter.cs │ ├── InterfaceSegregation.csproj │ └── Program.cs ├── LiskovSubstitution │ ├── CityDuck.cs │ ├── Duck.cs │ ├── LiskovSubstitution.csproj │ ├── MountainDuck.cs │ ├── Program.cs │ ├── Rectangle.cs │ ├── RubberDuck.cs │ └── Square.cs ├── OpenClose │ ├── Class │ │ ├── IInvoiceSaver.cs │ │ ├── Invoice.cs │ │ ├── InvoiceLogger.cs │ │ ├── InvoicePersistence.CS │ │ ├── LineItem.cs │ │ ├── PdfInvoiceSaver.cs │ │ └── WordInvoiceSaver.cs │ ├── Module │ │ ├── Application.cs │ │ └── ShapeType.cs │ ├── OpenClose.csproj │ └── Program.cs └── SingleResponsibility │ ├── Invoice.cs │ ├── InvoiceLogger.cs │ ├── InvoicePersistence.CS │ ├── LineItem.cs │ ├── Program.cs │ └── SingleResponsibility.csproj └── Structural ├── Adapter ├── Adapter.csproj ├── EmailSender.cs ├── INotificationSender.cs ├── Notification.cs ├── Program.cs ├── PushSender.cs ├── SmsSender.cs └── SmsSenderAdapter.cs ├── Decorator ├── CheesePizzaDecorator.cs ├── Decorator.csproj ├── HamPizzaDecorator.cs ├── IPizza.cs ├── LargePizza.cs ├── MediumPizza.cs ├── PizzaDecorator.cs ├── Program.cs ├── SalamiPizzaDecorator.cs └── SmallPizza.cs ├── Facade ├── DependencyScanner.cs ├── Facade.csproj ├── Program.cs ├── QualityScanner.cs ├── ReportGenerator.cs ├── ScanFacade.cs └── SecurityScanner.cs └── Proxy ├── IYouTubeService.cs ├── Program.cs ├── Proxy.csproj ├── ProxyYouTubeService.cs └── YouTubeService.cs /.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 -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibility/AuthorizationHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ChainOfResponsibility 8 | { 9 | public class AuthorizationHandler : BaseHandler 10 | { 11 | private Dictionary entityOwners = new Dictionary() 12 | { 13 | {100, 13}, 14 | {101, 14}, 15 | }; 16 | public AuthorizationHandler(IHandler next) : base(next) 17 | { 18 | 19 | } 20 | 21 | public override void Handle(RequestContext requestContext) 22 | { 23 | Console.WriteLine("AuthorizationHandler"); 24 | if (requestContext.Request.UserRole == "Admin") 25 | { 26 | _next.Handle(requestContext); 27 | return; 28 | } 29 | 30 | if (entityOwners.TryGetValue(requestContext.Request.EntityId, out int ownerId)) 31 | { 32 | if (ownerId == requestContext.Request.UserId) 33 | { 34 | _next.Handle(requestContext); 35 | return; 36 | 37 | } 38 | } 39 | 40 | requestContext.Response.IsSuccessful = false; 41 | requestContext.Response.Message = "User is not authorized"; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibility/BaseHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ChainOfResponsibility 8 | { 9 | public abstract class BaseHandler : IHandler 10 | { 11 | protected IHandler _next; 12 | 13 | protected BaseHandler(IHandler next) 14 | { 15 | _next = next; 16 | } 17 | 18 | public abstract void Handle(RequestContext requestContext); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibility/ChainOfResponsibility.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibility/IHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ChainOfResponsibility 8 | { 9 | public interface IHandler 10 | { 11 | void Handle(RequestContext requestContext); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibility/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ChainOfResponsibility 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var requestContext = new RequestContext() 10 | { 11 | Request = new Request() 12 | { 13 | EntityId = 101, 14 | UserId = 13, 15 | UserRole = "Admin" 16 | }, 17 | Response = new Response() 18 | 19 | }; 20 | 21 | var resultHandler = new ResultHandler(null); 22 | var validationHandler = new ValidationHandler(resultHandler); 23 | var authorizationHandler = new AuthorizationHandler(validationHandler); 24 | 25 | authorizationHandler.Handle(requestContext); 26 | 27 | Console.WriteLine($"IsSuccessful: {requestContext.Response.IsSuccessful}"); 28 | Console.WriteLine($"Message: {requestContext.Response.Message}"); 29 | Console.WriteLine($"Data: {requestContext.Response.Data}"); 30 | 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibility/RequestContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ChainOfResponsibility 8 | { 9 | public class Request 10 | { 11 | public string UserRole { get; set; } 12 | public int UserId { get; set; } 13 | public int EntityId { get; set; } 14 | } 15 | 16 | public class Response 17 | { 18 | public bool IsSuccessful { get; set; } 19 | public string Message { get; set; } 20 | public object Data { get; set; } 21 | } 22 | 23 | public class RequestContext 24 | { 25 | public Request Request { get; set; } 26 | public Response Response { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibility/ResultHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ChainOfResponsibility 8 | { 9 | public class ResultHandler : BaseHandler 10 | { 11 | public ResultHandler(IHandler next) : base(next) 12 | { 13 | } 14 | 15 | public override void Handle(RequestContext requestContext) 16 | { 17 | Console.WriteLine("ResultHandler"); 18 | 19 | requestContext.Response.IsSuccessful = true; 20 | requestContext.Response.Data = "some value"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Behavioral/ChainOfResponsibility/ValidationHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ChainOfResponsibility 8 | { 9 | public class ValidationHandler : BaseHandler 10 | { 11 | public ValidationHandler(IHandler next) : base(next) 12 | { 13 | } 14 | 15 | public override void Handle(RequestContext requestContext) 16 | { 17 | Console.WriteLine("ValidationHandler"); 18 | 19 | if (requestContext.Request.EntityId > 100) 20 | { 21 | _next.Handle(requestContext); 22 | return; 23 | 24 | } 25 | 26 | requestContext.Response.IsSuccessful = false; 27 | requestContext.Response.Message = "Validation error: EntityId must be greater than 100"; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Button.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Mediator 8 | { 9 | public class Button : Component 10 | { 11 | public void Render() 12 | { 13 | Console.WriteLine("Render button"); 14 | } 15 | 16 | public void Click() 17 | { 18 | Console.WriteLine("Button click"); 19 | 20 | this._mediator.Notify(this, "click"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Checkbox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Mediator 8 | { 9 | public class Checkbox : Component 10 | { 11 | public void Select() 12 | { 13 | Console.WriteLine("checkbox selected"); 14 | 15 | this._mediator.Notify(this, "checkboxSelected"); 16 | } 17 | 18 | public void SaveValue() 19 | { 20 | Console.WriteLine("Checkbox value saved"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Component.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Mediator 8 | { 9 | public abstract class Component 10 | { 11 | protected IMediator _mediator; 12 | 13 | public void SetMediator(IMediator mediator) 14 | { 15 | _mediator = mediator; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Behavioral/Mediator/IMediator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Mediator 8 | { 9 | public interface IMediator 10 | { 11 | void Notify(Component sender, string @event); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Input.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Mediator 8 | { 9 | public class Input : Component 10 | { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Mediator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Behavioral/Mediator/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Mediator 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Button submitButton = new Button(); 10 | Checkbox clientType = new Checkbox(); 11 | 12 | new RegisterClientView(clientType, submitButton); 13 | 14 | 15 | submitButton.Click(); 16 | 17 | clientType.Select(); 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Behavioral/Mediator/RegisterClientView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Mediator 8 | { 9 | public class RegisterClientView : IMediator 10 | { 11 | private Checkbox _clientType; 12 | private Button _submitButton; 13 | 14 | public RegisterClientView(Checkbox clientType, Button submitButton) 15 | { 16 | _submitButton = submitButton; 17 | _clientType = clientType; 18 | 19 | _submitButton.SetMediator(this); 20 | _clientType.SetMediator(this); 21 | } 22 | 23 | public void Notify(Component sender, string @event) 24 | { 25 | if (@event == "checkboxSelected") 26 | { 27 | _submitButton.Render(); 28 | } 29 | else if (@event == "click") 30 | { 31 | _clientType.SaveValue(); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Behavioral/Observer/ISubscriber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Observer 8 | { 9 | public interface ISubscriber 10 | { 11 | void Update(string context); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Behavioral/Observer/Observer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Behavioral/Observer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Observer 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var subscriber1 = new Subscriber("subscriber1"); 10 | var subscriber2 = new Subscriber("subscriber2"); 11 | 12 | var publisher = new Publisher(); 13 | 14 | publisher.Subscribe(subscriber1); 15 | publisher.Subscribe(subscriber2); 16 | 17 | publisher.Notify("test message"); 18 | 19 | publisher.Unsubscribe(subscriber1); 20 | 21 | publisher.Notify("test message2"); 22 | 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Behavioral/Observer/Publisher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Observer 8 | { 9 | public class Publisher 10 | { 11 | private List _subscribers = new List(); 12 | 13 | public void Subscribe(ISubscriber subscriber) 14 | { 15 | _subscribers.Add(subscriber); 16 | } 17 | 18 | public void Unsubscribe(ISubscriber subscriber) 19 | { 20 | _subscribers.Remove(subscriber); 21 | } 22 | 23 | public void Notify(string context) 24 | { 25 | foreach (ISubscriber subscriber in _subscribers) 26 | { 27 | subscriber.Update(context); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Behavioral/Observer/Subscriber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Observer 8 | { 9 | public class Subscriber : ISubscriber 10 | { 11 | public string Name { get; set; } 12 | 13 | public Subscriber(string name) 14 | { 15 | Name = name; 16 | } 17 | 18 | public void Update(string context) 19 | { 20 | Console.WriteLine($"Subscriber {Name} notified: {context}"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Behavioral/State/CardInserted.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace State 8 | { 9 | public class CardInserted : State 10 | { 11 | public CardInserted(Context context) : base(context) 12 | { 13 | } 14 | 15 | public override void InsertCard() 16 | { 17 | Console.WriteLine("You have already inserted a card"); 18 | } 19 | 20 | public override void EjectCard() 21 | { 22 | Console.WriteLine("Card ejected"); 23 | _context.ChangeState(new NoCard(_context)); 24 | } 25 | 26 | public override void InsertPin(int pin) 27 | { 28 | if (pin == 8888) 29 | { 30 | Console.WriteLine("Correct PIN inserted"); 31 | _context.ChangeState(new PinInserted(_context)); 32 | 33 | } 34 | else 35 | { 36 | Console.WriteLine("Incorrect PIN inserted"); 37 | Console.WriteLine("Card ejected"); 38 | _context.ChangeState(new NoCard(_context)); 39 | 40 | } 41 | } 42 | 43 | public override void WithdrawCash(int amount) 44 | { 45 | Console.WriteLine("Insert PIN first"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Behavioral/State/Context.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace State 8 | { 9 | public class Context 10 | { 11 | private State _currentState; 12 | public int AvailableCash { get; set; } = 2000; 13 | 14 | public Context() 15 | { 16 | _currentState = new NoCard(this); 17 | } 18 | 19 | public void ChangeState(State newState) 20 | { 21 | _currentState = newState; 22 | } 23 | 24 | public void InsertCard() 25 | { 26 | _currentState.InsertCard(); 27 | } 28 | 29 | public void EjectCard() 30 | { 31 | _currentState.EjectCard(); 32 | } 33 | 34 | public void InsertPin(int pin) 35 | { 36 | _currentState.InsertPin(pin); 37 | } 38 | 39 | public void WithdrawCash(int amount) 40 | { 41 | _currentState.WithdrawCash(amount); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Behavioral/State/NoCard.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace State 8 | { 9 | public class NoCard : State 10 | { 11 | public NoCard(Context context) : base(context) 12 | { 13 | } 14 | 15 | public override void InsertCard() 16 | { 17 | Console.WriteLine("Card inserted"); 18 | _context.ChangeState(new CardInserted(_context)); 19 | } 20 | 21 | public override void EjectCard() 22 | { 23 | Console.WriteLine("No card inserted yet"); 24 | } 25 | 26 | public override void InsertPin(int pin) 27 | { 28 | Console.WriteLine("No card inserted yet"); 29 | } 30 | 31 | public override void WithdrawCash(int amount) 32 | { 33 | Console.WriteLine("No card inserted yet"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Behavioral/State/NoCash.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace State 8 | { 9 | public class NoCash : State 10 | { 11 | public NoCash(Context context) : base(context) 12 | { 13 | } 14 | 15 | public override void InsertCard() 16 | { 17 | Console.WriteLine("Sorry, we are out of cash"); 18 | } 19 | 20 | public override void EjectCard() 21 | { 22 | Console.WriteLine("Sorry, we are out of cash"); 23 | } 24 | 25 | public override void InsertPin(int pin) 26 | { 27 | Console.WriteLine("Sorry, we are out of cash"); 28 | } 29 | 30 | public override void WithdrawCash(int amount) 31 | { 32 | Console.WriteLine("Sorry, we are out of cash"); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Behavioral/State/PinInserted.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace State 8 | { 9 | public class PinInserted : State 10 | { 11 | public PinInserted(Context context) : base(context) 12 | { 13 | } 14 | 15 | public override void InsertCard() 16 | { 17 | Console.WriteLine("You have already inserted a card"); 18 | } 19 | 20 | public override void EjectCard() 21 | { 22 | Console.WriteLine("Card ejected"); 23 | _context.ChangeState(new NoCard(_context)); 24 | 25 | 26 | } 27 | 28 | public override void InsertPin(int pin) 29 | { 30 | Console.WriteLine("You have already inserted correct PIN"); 31 | } 32 | 33 | public override void WithdrawCash(int amount) 34 | { 35 | if (amount > _context.AvailableCash) 36 | { 37 | Console.WriteLine("That amount of cash is not available"); 38 | 39 | } 40 | else 41 | { 42 | Console.WriteLine($"You have withdraw {amount} from the machine"); 43 | 44 | _context.AvailableCash -= amount; 45 | 46 | if (_context.AvailableCash == 0) 47 | { 48 | _context.ChangeState(new NoCash(_context)); 49 | 50 | 51 | } 52 | else 53 | { 54 | Console.WriteLine("Card ejeceted"); 55 | _context.ChangeState(new NoCard(_context)); 56 | 57 | 58 | } 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Behavioral/State/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace State 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var context = new Context(); 10 | 11 | context.EjectCard(); 12 | 13 | context.InsertCard(); 14 | 15 | context.InsertPin(1111); 16 | 17 | context.InsertCard(); 18 | 19 | context.InsertPin(8888); 20 | 21 | context.WithdrawCash(2000); 22 | 23 | context.InsertCard(); 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Behavioral/State/State.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace State 8 | { 9 | public abstract class State 10 | { 11 | protected Context _context; 12 | 13 | protected State(Context context) 14 | { 15 | _context = context; 16 | } 17 | 18 | public abstract void InsertCard(); 19 | public abstract void EjectCard(); 20 | public abstract void InsertPin(int pin); 21 | public abstract void WithdrawCash(int amount); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Behavioral/State/State.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Behavioral/Strategy/BikeStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Strategy 8 | { 9 | public class BikeStrategy : IRouteStrategy 10 | { 11 | public void CreateRoute(Coordinate start, Coordinate end) 12 | { 13 | Console.WriteLine("Bike strategy"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Behavioral/Strategy/CarStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Strategy 8 | { 9 | public class CarStrategy : IRouteStrategy 10 | { 11 | public void CreateRoute(Coordinate start, Coordinate end) 12 | { 13 | Console.WriteLine("Car strategy"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Behavioral/Strategy/Coordinate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Strategy 8 | { 9 | public class Coordinate 10 | { 11 | public double Long { get; set; } 12 | public double Lat { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Behavioral/Strategy/IRouteStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Strategy 8 | { 9 | public interface IRouteStrategy 10 | { 11 | void CreateRoute(Coordinate start, Coordinate end); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Behavioral/Strategy/Map.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Strategy 8 | { 9 | public class Map 10 | { 11 | private IRouteStrategy _routeStrategy; 12 | 13 | public Map(IRouteStrategy routeStrategy) 14 | { 15 | _routeStrategy = routeStrategy; 16 | } 17 | 18 | public void CreateRoute(Coordinate start, Coordinate end) 19 | { 20 | _routeStrategy.CreateRoute(start, end); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Behavioral/Strategy/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Strategy 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var strategy = new CarStrategy(); 10 | 11 | var map = new Map(strategy); 12 | 13 | var start = new Coordinate(); 14 | var end = new Coordinate(); 15 | 16 | map.CreateRoute(start, end); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Behavioral/Strategy/Strategy.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Behavioral/Strategy/WalkStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Strategy 8 | { 9 | public class WalkStrategy : IRouteStrategy 10 | { 11 | public void CreateRoute(Coordinate start, Coordinate end) 12 | { 13 | Console.WriteLine("Walk strategy"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/CsvGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace TemplateMethod 8 | { 9 | public class CsvGenerator : Generator 10 | { 11 | protected override void PrepareData() 12 | { 13 | Console.WriteLine("Prepare data for csv"); 14 | } 15 | 16 | protected override void GenerateFile() 17 | { 18 | Console.WriteLine("Generate csv file"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/ExcelGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace TemplateMethod 8 | { 9 | public class ExcelGenerator : Generator 10 | { 11 | protected override void PrepareData() 12 | { 13 | Console.WriteLine("Prepare data for excel"); 14 | } 15 | 16 | protected override void GenerateFile() 17 | { 18 | Console.WriteLine("Generate excel file"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/Generator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace TemplateMethod 8 | { 9 | public abstract class Generator 10 | { 11 | public void GenerateReport() 12 | { 13 | GetData(); 14 | PrepareData(); 15 | GenerateFile(); 16 | SendFile(); 17 | } 18 | protected virtual void GetData() 19 | { 20 | Console.WriteLine("Base get data"); 21 | } 22 | 23 | protected abstract void PrepareData(); 24 | protected abstract void GenerateFile(); 25 | 26 | protected void SendFile() 27 | { 28 | Console.WriteLine("Sending generated report"); 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/PdfGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace TemplateMethod 8 | { 9 | public class PdfGenerator : Generator 10 | { 11 | protected override void GetData() 12 | { 13 | Console.WriteLine("Pdf get data override"); 14 | } 15 | 16 | protected override void PrepareData() 17 | { 18 | Console.WriteLine("Prepare data for pdf"); 19 | } 20 | 21 | protected override void GenerateFile() 22 | { 23 | Console.WriteLine("Generate pdf file"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TemplateMethod 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | 11 | var pdfGenerator = new PdfGenerator(); 12 | 13 | Console.WriteLine("** PDF **"); 14 | pdfGenerator.GenerateReport(); 15 | 16 | Console.WriteLine("** CSV **"); 17 | var csvGenerator = new CsvGenerator(); 18 | 19 | csvGenerator.GenerateReport(); 20 | 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Behavioral/TemplateMethod/TemplateMethod.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/AbstractFactory.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/Application.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public class Application 10 | { 11 | private IUIElementFactory _elementFactory; 12 | 13 | public Application(IUIElementFactory elementFactory) 14 | { 15 | _elementFactory = elementFactory; 16 | } 17 | 18 | public void RenderUI() 19 | { 20 | var createNewFileButton = _elementFactory.CreateButton(); 21 | 22 | createNewFileButton.Render(); 23 | 24 | var textbox = _elementFactory.CreateTextbox(); 25 | 26 | textbox.Render(); 27 | 28 | 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/IButton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public interface IButton 10 | { 11 | void Render(); 12 | void HandleClick(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/ITextbox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public interface ITextbox 10 | { 11 | void Render(); 12 | void HandleInput(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/IUIElementFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public interface IUIElementFactory 10 | { 11 | IButton CreateButton(); 12 | ITextbox CreateTextbox(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/MacButton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public class MacButton : IButton 10 | { 11 | public void Render() 12 | { 13 | Console.WriteLine("Render Mac button"); 14 | } 15 | 16 | public void HandleClick() 17 | { 18 | Console.WriteLine("Handle Mac click event"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/MacFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public class MacFactory : IUIElementFactory 10 | { 11 | public IButton CreateButton() 12 | { 13 | return new MacButton(); 14 | } 15 | 16 | public ITextbox CreateTextbox() 17 | { 18 | return new MacTextbox(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/MacTextbox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public class MacTextbox : ITextbox 10 | { 11 | public void Render() 12 | { 13 | Console.WriteLine("Render Mac textbox"); 14 | } 15 | 16 | public void HandleInput() 17 | { 18 | Console.WriteLine("Handle Mac text input"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace AbstractFactory 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var uiApplication = new Application(new MacFactory()); 10 | 11 | uiApplication.RenderUI(); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/WindowTextbox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public class WindowTextbox : ITextbox 10 | { 11 | public void Render() 12 | { 13 | Console.WriteLine("Render windows textbox"); 14 | } 15 | 16 | public void HandleInput() 17 | { 18 | Console.WriteLine("Handle windows text input"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/WindowsButton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public class WindowsButton : IButton 10 | { 11 | public void Render() 12 | { 13 | Console.WriteLine("Render windows button"); 14 | } 15 | 16 | public void HandleClick() 17 | { 18 | Console.WriteLine("Handle windows click event"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Creational/AbstractFactory/WindowsFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace AbstractFactory 8 | { 9 | public class WindowsFactory : IUIElementFactory 10 | { 11 | public IButton CreateButton() 12 | { 13 | return new WindowsButton(); 14 | } 15 | 16 | public ITextbox CreateTextbox() 17 | { 18 | return new WindowTextbox(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Creational/Builder/Builder.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Creational/Builder/Invoice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Builder 8 | { 9 | public class Invoice 10 | { 11 | public string Number { get; set; } 12 | public DateTime Date { get; set; } 13 | public string Vendor { get; set; } 14 | public string Vendee { get; set; } 15 | public IEnumerable LineItems { get; set; } 16 | public string Note { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Creational/Builder/InvoiceBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Builder 8 | { 9 | public class InvoiceBuilder 10 | { 11 | private Invoice _invoice = new Invoice(); 12 | 13 | public Invoice Build() 14 | { 15 | return _invoice; 16 | } 17 | 18 | public InvoiceBuilder SetVendor(string vendor) 19 | { 20 | _invoice.Vendor = vendor; 21 | 22 | return this; 23 | } 24 | public InvoiceBuilder SetVendee(string vendee) 25 | { 26 | _invoice.Vendee = vendee; 27 | return this; 28 | 29 | } 30 | 31 | public InvoiceBuilder SetNote(string note) 32 | { 33 | _invoice.Note = note; 34 | return this; 35 | } 36 | 37 | public InvoiceBuilder SetLineItems(IEnumerable lineItems) 38 | { 39 | _invoice.LineItems = lineItems; 40 | return this; 41 | } 42 | 43 | public InvoiceBuilder SetInvoiceNumber(string number) 44 | { 45 | _invoice.Number = number; 46 | return this; 47 | } 48 | 49 | public InvoiceBuilder SetDate(DateTime date) 50 | { 51 | _invoice.Date = date; 52 | return this; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Creational/Builder/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Builder 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | Console.WriteLine("Hello World!"); 11 | 12 | var builder = new InvoiceBuilder(); 13 | 14 | Invoice invoice = builder.SetDate(new DateTime(2020, 1, 1)) 15 | .SetInvoiceNumber("A1") 16 | .SetVendor("Google..") 17 | .SetVendee("Vendee") 18 | .SetLineItems(new List() {"Line item1", "Line item2" }) 19 | .Build(); 20 | 21 | Console.WriteLine(invoice.Vendee); 22 | Console.WriteLine(invoice.Vendor); 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Creational/Factory/Circle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Factory 8 | { 9 | public class Circle : Shape 10 | { 11 | public override void Render() 12 | { 13 | Console.WriteLine("Render circle"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Creational/Factory/Factory.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Creational/Factory/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Factory 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | var shapeFactory = new ShapeFactory(); 10 | 11 | var circle = shapeFactory.CreateShape(ShapeType.Circle); 12 | 13 | circle.Render(); 14 | 15 | var triangle = shapeFactory.CreateShape(ShapeType.Triangle); 16 | 17 | triangle.Render(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Creational/Factory/Rectangle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Factory 8 | { 9 | public class Rectangle : Shape 10 | { 11 | public override void Render() 12 | { 13 | Console.WriteLine("Render rectangle"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Creational/Factory/Shape.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Factory 8 | { 9 | public abstract class Shape 10 | { 11 | public int X { get; set; } 12 | public int Y { get; set; } 13 | 14 | public abstract void Render(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Creational/Factory/ShapeFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Factory 8 | { 9 | public class ShapeFactory 10 | { 11 | public Shape CreateShape(ShapeType type) 12 | { 13 | switch (type) 14 | { 15 | case ShapeType.Circle: 16 | return new Circle(); 17 | case ShapeType.Rectangle: 18 | return new Rectangle(); 19 | case ShapeType.Triangle: 20 | return new Triangle(); 21 | default: 22 | throw new Exception($"Shape type {type} is not handled"); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Creational/Factory/ShapeType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Factory 8 | { 9 | public enum ShapeType 10 | { 11 | Circle, 12 | Rectangle, 13 | Triangle 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Creational/Factory/Triangle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Factory 8 | { 9 | public class Triangle : Shape 10 | { 11 | public override void Render() 12 | { 13 | Console.WriteLine("Render triangle"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Creational/Prototype/Prototype/Border.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Prototype 8 | { 9 | public class Border 10 | { 11 | public string Color { get; set; } 12 | public string Size { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Creational/Prototype/Prototype/Circle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Prototype 8 | { 9 | public class Circle : Shape 10 | { 11 | public int Radius { get; set; } 12 | public override void Render() 13 | { 14 | Console.WriteLine("Render circle"); 15 | } 16 | 17 | public override Shape Clone() 18 | { 19 | Circle cloneBase = (Circle)this.MemberwiseClone(); 20 | 21 | cloneBase.Border = new Border() 22 | { 23 | Size = Border.Size, 24 | Color = Border.Color 25 | }; 26 | 27 | return cloneBase; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Creational/Prototype/Prototype/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Prototype 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Circle c1 = new Circle() 10 | { 11 | Radius = 5, 12 | X = 1, 13 | Y = 2, 14 | Border = new Border() 15 | { 16 | Color = "Red", 17 | Size = "2px" 18 | } 19 | }; 20 | 21 | Circle c2 = (Circle)c1.Clone(); 22 | 23 | bool referenceEquals = ReferenceEquals(c1, c2); 24 | Console.WriteLine($"ReferenceEquals: {referenceEquals}"); 25 | 26 | bool borderReferenceEquals = ReferenceEquals(c1.Border, c2.Border); 27 | Console.WriteLine($"borderReferenceEquals: {borderReferenceEquals}"); 28 | 29 | Console.WriteLine(); 30 | 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Creational/Prototype/Prototype/Prototype.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Creational/Prototype/Prototype/Rectangle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Prototype 8 | { 9 | public class Rectangle : Shape 10 | { 11 | public override void Render() 12 | { 13 | Console.WriteLine("Render Rectangle"); 14 | } 15 | 16 | public override Shape Clone() 17 | { 18 | Rectangle cloneBase = (Rectangle)this.MemberwiseClone(); 19 | 20 | cloneBase.Border = new Border() 21 | { 22 | Size = Border.Size, 23 | Color = Border.Color 24 | }; 25 | 26 | return cloneBase; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Creational/Prototype/Prototype/Shape.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Prototype 8 | { 9 | public abstract class Shape 10 | { 11 | public int X { get; set; } 12 | public int Y { get; set; } 13 | public Border Border { get; set; } 14 | 15 | public abstract void Render(); 16 | public abstract Shape Clone(); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Creational/Prototype/Prototype/Triangle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Prototype 8 | { 9 | public class Triangle : Shape 10 | { 11 | public override void Render() 12 | { 13 | Console.WriteLine("Render triangle"); 14 | } 15 | 16 | public override Shape Clone() 17 | { 18 | Triangle cloneBase = (Triangle)this.MemberwiseClone(); 19 | 20 | cloneBase.Border = new Border() 21 | { 22 | Size = Border.Size, 23 | Color = Border.Color 24 | }; 25 | 26 | return cloneBase; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Creational/Singleton/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Singleton 8 | { 9 | public class Configuration 10 | { 11 | private static Configuration _instance = null; 12 | private static object obj = new object(); 13 | public string StringProperty { get; set; } 14 | public int IntProperty { get; set; } 15 | 16 | private Configuration() 17 | { 18 | } 19 | 20 | public static Configuration GetInstance() 21 | { 22 | lock (obj) 23 | { 24 | if (_instance == null) 25 | { 26 | _instance = new Configuration(); 27 | } 28 | } 29 | 30 | 31 | return _instance; 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Creational/Singleton/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Singleton 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | 11 | var cfg = Configuration.GetInstance(); 12 | var cfg2 = Configuration.GetInstance(); 13 | 14 | if (ReferenceEquals(cfg, cfg2)) 15 | { 16 | Console.WriteLine("Configuration is a singleton"); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Creational/Singleton/Singleton.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DesignPatterns.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Behavioral", "Behavioral", "{17DEC64A-8236-488A-AA05-F5016F216FF9}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Strategy", "Behavioral\Strategy\Strategy.csproj", "{CA32904F-8850-4D47-9A3E-B39640F8BA68}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Creational", "Creational", "{3D442204-8317-484E-9FA2-4DDBA2B8B187}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Structural", "Structural", "{470CA887-1BDB-42A4-ACBC-ABFF7BDA1C06}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Builder", "Creational\Builder\Builder.csproj", "{5101F764-4792-437C-9DBA-A2CFE4E13F82}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Factory", "Creational\Factory\Factory.csproj", "{AC2F21CA-D794-4EBA-94B5-CC2E88684C1B}" 17 | EndProject 18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Singleton", "Creational\Singleton\Singleton.csproj", "{83F3E389-3BBB-44F5-B92A-A5B487C05274}" 19 | EndProject 20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prototype", "Creational\Prototype\Prototype\Prototype.csproj", "{D074C019-57B6-4F25-8033-B2E5F7CE9758}" 21 | EndProject 22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractFactory", "Creational\AbstractFactory\AbstractFactory.csproj", "{AE409EC0-333B-42FD-83B5-F0E82229C818}" 23 | EndProject 24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Decorator", "Structural\Decorator\Decorator.csproj", "{024D7543-88C9-4A77-8EDA-8918968362B0}" 25 | EndProject 26 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mediator", "Behavioral\Mediator\Mediator.csproj", "{2EA7BB64-CA8D-4BA9-87BF-994A553821CA}" 27 | EndProject 28 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChainOfResponsibility", "Behavioral\ChainOfResponsibility\ChainOfResponsibility.csproj", "{9F75E7FF-E9E3-489E-9537-B5E7A6B90175}" 29 | EndProject 30 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Observer", "Behavioral\Observer\Observer.csproj", "{51DCC2CF-4A94-4993-81EA-17A1BBCA197D}" 31 | EndProject 32 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "State", "Behavioral\State\State.csproj", "{31F73875-560E-4FE2-96EF-A63A1053BCF6}" 33 | EndProject 34 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TemplateMethod", "Behavioral\TemplateMethod\TemplateMethod.csproj", "{B6DBEC8B-F252-4E07-9F9E-6DC87B9FD502}" 35 | EndProject 36 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SOLID", "SOLID", "{093065C0-B7AE-4E4B-A823-EFA4D5AFC611}" 37 | EndProject 38 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SingleResponsibility", "SOLID\SingleResponsibility\SingleResponsibility.csproj", "{A22B9B0F-4495-447C-AEA1-F2121A2B72C7}" 39 | EndProject 40 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiskovSubstitution", "SOLID\LiskovSubstitution\LiskovSubstitution.csproj", "{A2FA94EA-BCE4-43F0-B712-1708A77FCA7E}" 41 | EndProject 42 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DependencyInversion", "SOLID\DependencyInversion\DependencyInversion.csproj", "{A809CDDB-D804-4476-A360-3F2BEAEB373B}" 43 | EndProject 44 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenClose", "SOLID\OpenClose\OpenClose.csproj", "{629F39BD-E70A-4CC7-8286-EFE223E30476}" 45 | EndProject 46 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Proxy", "Structural\Proxy\Proxy.csproj", "{17065C46-C9FB-4F22-8762-15A7364AD0FC}" 47 | EndProject 48 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Facade", "Structural\Facade\Facade.csproj", "{383B9841-CB24-478C-8270-6EA7993CF9D5}" 49 | EndProject 50 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adapter", "Structural\Adapter\Adapter.csproj", "{06A00EA8-C2AC-410B-9E39-732D416FCA66}" 51 | EndProject 52 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InterfaceSegregation", "SOLID\InterfaceSegregation\InterfaceSegregation.csproj", "{27425910-84FF-48BC-8143-2B6E0D354F9B}" 53 | EndProject 54 | Global 55 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 56 | Debug|Any CPU = Debug|Any CPU 57 | Release|Any CPU = Release|Any CPU 58 | EndGlobalSection 59 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 60 | {CA32904F-8850-4D47-9A3E-B39640F8BA68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 61 | {CA32904F-8850-4D47-9A3E-B39640F8BA68}.Debug|Any CPU.Build.0 = Debug|Any CPU 62 | {CA32904F-8850-4D47-9A3E-B39640F8BA68}.Release|Any CPU.ActiveCfg = Release|Any CPU 63 | {CA32904F-8850-4D47-9A3E-B39640F8BA68}.Release|Any CPU.Build.0 = Release|Any CPU 64 | {5101F764-4792-437C-9DBA-A2CFE4E13F82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 65 | {5101F764-4792-437C-9DBA-A2CFE4E13F82}.Debug|Any CPU.Build.0 = Debug|Any CPU 66 | {5101F764-4792-437C-9DBA-A2CFE4E13F82}.Release|Any CPU.ActiveCfg = Release|Any CPU 67 | {5101F764-4792-437C-9DBA-A2CFE4E13F82}.Release|Any CPU.Build.0 = Release|Any CPU 68 | {AC2F21CA-D794-4EBA-94B5-CC2E88684C1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 69 | {AC2F21CA-D794-4EBA-94B5-CC2E88684C1B}.Debug|Any CPU.Build.0 = Debug|Any CPU 70 | {AC2F21CA-D794-4EBA-94B5-CC2E88684C1B}.Release|Any CPU.ActiveCfg = Release|Any CPU 71 | {AC2F21CA-D794-4EBA-94B5-CC2E88684C1B}.Release|Any CPU.Build.0 = Release|Any CPU 72 | {83F3E389-3BBB-44F5-B92A-A5B487C05274}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 73 | {83F3E389-3BBB-44F5-B92A-A5B487C05274}.Debug|Any CPU.Build.0 = Debug|Any CPU 74 | {83F3E389-3BBB-44F5-B92A-A5B487C05274}.Release|Any CPU.ActiveCfg = Release|Any CPU 75 | {83F3E389-3BBB-44F5-B92A-A5B487C05274}.Release|Any CPU.Build.0 = Release|Any CPU 76 | {D074C019-57B6-4F25-8033-B2E5F7CE9758}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 77 | {D074C019-57B6-4F25-8033-B2E5F7CE9758}.Debug|Any CPU.Build.0 = Debug|Any CPU 78 | {D074C019-57B6-4F25-8033-B2E5F7CE9758}.Release|Any CPU.ActiveCfg = Release|Any CPU 79 | {D074C019-57B6-4F25-8033-B2E5F7CE9758}.Release|Any CPU.Build.0 = Release|Any CPU 80 | {AE409EC0-333B-42FD-83B5-F0E82229C818}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 81 | {AE409EC0-333B-42FD-83B5-F0E82229C818}.Debug|Any CPU.Build.0 = Debug|Any CPU 82 | {AE409EC0-333B-42FD-83B5-F0E82229C818}.Release|Any CPU.ActiveCfg = Release|Any CPU 83 | {AE409EC0-333B-42FD-83B5-F0E82229C818}.Release|Any CPU.Build.0 = Release|Any CPU 84 | {024D7543-88C9-4A77-8EDA-8918968362B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 85 | {024D7543-88C9-4A77-8EDA-8918968362B0}.Debug|Any CPU.Build.0 = Debug|Any CPU 86 | {024D7543-88C9-4A77-8EDA-8918968362B0}.Release|Any CPU.ActiveCfg = Release|Any CPU 87 | {024D7543-88C9-4A77-8EDA-8918968362B0}.Release|Any CPU.Build.0 = Release|Any CPU 88 | {2EA7BB64-CA8D-4BA9-87BF-994A553821CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 89 | {2EA7BB64-CA8D-4BA9-87BF-994A553821CA}.Debug|Any CPU.Build.0 = Debug|Any CPU 90 | {2EA7BB64-CA8D-4BA9-87BF-994A553821CA}.Release|Any CPU.ActiveCfg = Release|Any CPU 91 | {2EA7BB64-CA8D-4BA9-87BF-994A553821CA}.Release|Any CPU.Build.0 = Release|Any CPU 92 | {9F75E7FF-E9E3-489E-9537-B5E7A6B90175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 93 | {9F75E7FF-E9E3-489E-9537-B5E7A6B90175}.Debug|Any CPU.Build.0 = Debug|Any CPU 94 | {9F75E7FF-E9E3-489E-9537-B5E7A6B90175}.Release|Any CPU.ActiveCfg = Release|Any CPU 95 | {9F75E7FF-E9E3-489E-9537-B5E7A6B90175}.Release|Any CPU.Build.0 = Release|Any CPU 96 | {51DCC2CF-4A94-4993-81EA-17A1BBCA197D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 97 | {51DCC2CF-4A94-4993-81EA-17A1BBCA197D}.Debug|Any CPU.Build.0 = Debug|Any CPU 98 | {51DCC2CF-4A94-4993-81EA-17A1BBCA197D}.Release|Any CPU.ActiveCfg = Release|Any CPU 99 | {51DCC2CF-4A94-4993-81EA-17A1BBCA197D}.Release|Any CPU.Build.0 = Release|Any CPU 100 | {31F73875-560E-4FE2-96EF-A63A1053BCF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 101 | {31F73875-560E-4FE2-96EF-A63A1053BCF6}.Debug|Any CPU.Build.0 = Debug|Any CPU 102 | {31F73875-560E-4FE2-96EF-A63A1053BCF6}.Release|Any CPU.ActiveCfg = Release|Any CPU 103 | {31F73875-560E-4FE2-96EF-A63A1053BCF6}.Release|Any CPU.Build.0 = Release|Any CPU 104 | {B6DBEC8B-F252-4E07-9F9E-6DC87B9FD502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 105 | {B6DBEC8B-F252-4E07-9F9E-6DC87B9FD502}.Debug|Any CPU.Build.0 = Debug|Any CPU 106 | {B6DBEC8B-F252-4E07-9F9E-6DC87B9FD502}.Release|Any CPU.ActiveCfg = Release|Any CPU 107 | {B6DBEC8B-F252-4E07-9F9E-6DC87B9FD502}.Release|Any CPU.Build.0 = Release|Any CPU 108 | {A22B9B0F-4495-447C-AEA1-F2121A2B72C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 109 | {A22B9B0F-4495-447C-AEA1-F2121A2B72C7}.Debug|Any CPU.Build.0 = Debug|Any CPU 110 | {A22B9B0F-4495-447C-AEA1-F2121A2B72C7}.Release|Any CPU.ActiveCfg = Release|Any CPU 111 | {A22B9B0F-4495-447C-AEA1-F2121A2B72C7}.Release|Any CPU.Build.0 = Release|Any CPU 112 | {A2FA94EA-BCE4-43F0-B712-1708A77FCA7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 113 | {A2FA94EA-BCE4-43F0-B712-1708A77FCA7E}.Debug|Any CPU.Build.0 = Debug|Any CPU 114 | {A2FA94EA-BCE4-43F0-B712-1708A77FCA7E}.Release|Any CPU.ActiveCfg = Release|Any CPU 115 | {A2FA94EA-BCE4-43F0-B712-1708A77FCA7E}.Release|Any CPU.Build.0 = Release|Any CPU 116 | {A809CDDB-D804-4476-A360-3F2BEAEB373B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 117 | {A809CDDB-D804-4476-A360-3F2BEAEB373B}.Debug|Any CPU.Build.0 = Debug|Any CPU 118 | {A809CDDB-D804-4476-A360-3F2BEAEB373B}.Release|Any CPU.ActiveCfg = Release|Any CPU 119 | {A809CDDB-D804-4476-A360-3F2BEAEB373B}.Release|Any CPU.Build.0 = Release|Any CPU 120 | {629F39BD-E70A-4CC7-8286-EFE223E30476}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 121 | {629F39BD-E70A-4CC7-8286-EFE223E30476}.Debug|Any CPU.Build.0 = Debug|Any CPU 122 | {629F39BD-E70A-4CC7-8286-EFE223E30476}.Release|Any CPU.ActiveCfg = Release|Any CPU 123 | {629F39BD-E70A-4CC7-8286-EFE223E30476}.Release|Any CPU.Build.0 = Release|Any CPU 124 | {17065C46-C9FB-4F22-8762-15A7364AD0FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 125 | {17065C46-C9FB-4F22-8762-15A7364AD0FC}.Debug|Any CPU.Build.0 = Debug|Any CPU 126 | {17065C46-C9FB-4F22-8762-15A7364AD0FC}.Release|Any CPU.ActiveCfg = Release|Any CPU 127 | {17065C46-C9FB-4F22-8762-15A7364AD0FC}.Release|Any CPU.Build.0 = Release|Any CPU 128 | {383B9841-CB24-478C-8270-6EA7993CF9D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 129 | {383B9841-CB24-478C-8270-6EA7993CF9D5}.Debug|Any CPU.Build.0 = Debug|Any CPU 130 | {383B9841-CB24-478C-8270-6EA7993CF9D5}.Release|Any CPU.ActiveCfg = Release|Any CPU 131 | {383B9841-CB24-478C-8270-6EA7993CF9D5}.Release|Any CPU.Build.0 = Release|Any CPU 132 | {06A00EA8-C2AC-410B-9E39-732D416FCA66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 133 | {06A00EA8-C2AC-410B-9E39-732D416FCA66}.Debug|Any CPU.Build.0 = Debug|Any CPU 134 | {06A00EA8-C2AC-410B-9E39-732D416FCA66}.Release|Any CPU.ActiveCfg = Release|Any CPU 135 | {06A00EA8-C2AC-410B-9E39-732D416FCA66}.Release|Any CPU.Build.0 = Release|Any CPU 136 | {27425910-84FF-48BC-8143-2B6E0D354F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 137 | {27425910-84FF-48BC-8143-2B6E0D354F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU 138 | {27425910-84FF-48BC-8143-2B6E0D354F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU 139 | {27425910-84FF-48BC-8143-2B6E0D354F9B}.Release|Any CPU.Build.0 = Release|Any CPU 140 | EndGlobalSection 141 | GlobalSection(SolutionProperties) = preSolution 142 | HideSolutionNode = FALSE 143 | EndGlobalSection 144 | GlobalSection(NestedProjects) = preSolution 145 | {CA32904F-8850-4D47-9A3E-B39640F8BA68} = {17DEC64A-8236-488A-AA05-F5016F216FF9} 146 | {5101F764-4792-437C-9DBA-A2CFE4E13F82} = {3D442204-8317-484E-9FA2-4DDBA2B8B187} 147 | {AC2F21CA-D794-4EBA-94B5-CC2E88684C1B} = {3D442204-8317-484E-9FA2-4DDBA2B8B187} 148 | {83F3E389-3BBB-44F5-B92A-A5B487C05274} = {3D442204-8317-484E-9FA2-4DDBA2B8B187} 149 | {D074C019-57B6-4F25-8033-B2E5F7CE9758} = {3D442204-8317-484E-9FA2-4DDBA2B8B187} 150 | {AE409EC0-333B-42FD-83B5-F0E82229C818} = {3D442204-8317-484E-9FA2-4DDBA2B8B187} 151 | {024D7543-88C9-4A77-8EDA-8918968362B0} = {470CA887-1BDB-42A4-ACBC-ABFF7BDA1C06} 152 | {2EA7BB64-CA8D-4BA9-87BF-994A553821CA} = {17DEC64A-8236-488A-AA05-F5016F216FF9} 153 | {9F75E7FF-E9E3-489E-9537-B5E7A6B90175} = {17DEC64A-8236-488A-AA05-F5016F216FF9} 154 | {51DCC2CF-4A94-4993-81EA-17A1BBCA197D} = {17DEC64A-8236-488A-AA05-F5016F216FF9} 155 | {31F73875-560E-4FE2-96EF-A63A1053BCF6} = {17DEC64A-8236-488A-AA05-F5016F216FF9} 156 | {B6DBEC8B-F252-4E07-9F9E-6DC87B9FD502} = {17DEC64A-8236-488A-AA05-F5016F216FF9} 157 | {A22B9B0F-4495-447C-AEA1-F2121A2B72C7} = {093065C0-B7AE-4E4B-A823-EFA4D5AFC611} 158 | {A2FA94EA-BCE4-43F0-B712-1708A77FCA7E} = {093065C0-B7AE-4E4B-A823-EFA4D5AFC611} 159 | {A809CDDB-D804-4476-A360-3F2BEAEB373B} = {093065C0-B7AE-4E4B-A823-EFA4D5AFC611} 160 | {629F39BD-E70A-4CC7-8286-EFE223E30476} = {093065C0-B7AE-4E4B-A823-EFA4D5AFC611} 161 | {17065C46-C9FB-4F22-8762-15A7364AD0FC} = {470CA887-1BDB-42A4-ACBC-ABFF7BDA1C06} 162 | {383B9841-CB24-478C-8270-6EA7993CF9D5} = {470CA887-1BDB-42A4-ACBC-ABFF7BDA1C06} 163 | {06A00EA8-C2AC-410B-9E39-732D416FCA66} = {470CA887-1BDB-42A4-ACBC-ABFF7BDA1C06} 164 | {27425910-84FF-48BC-8143-2B6E0D354F9B} = {093065C0-B7AE-4E4B-A823-EFA4D5AFC611} 165 | EndGlobalSection 166 | GlobalSection(ExtensibilityGlobals) = postSolution 167 | SolutionGuid = {EED30954-1DD4-46B1-AEBC-2A78292061A7} 168 | EndGlobalSection 169 | EndGlobal 170 | -------------------------------------------------------------------------------- /SOLID/DependencyInversion/AuthenticationManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DependencyInversion 8 | { 9 | public class AuthenticationManager 10 | { 11 | private INotificationSender _notificationSender; 12 | 13 | public AuthenticationManager(INotificationSender notificationSender) 14 | { 15 | this._notificationSender = notificationSender; 16 | } 17 | public void Authenticate(User user, string email, string password) 18 | { 19 | if (user.Email == email && user.Password == password) 20 | { 21 | _notificationSender.SendNotification(user); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SOLID/DependencyInversion/DependencyInversion.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SOLID/DependencyInversion/EmailNotification.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DependencyInversion 8 | { 9 | public class EmailNotification : INotificationSender 10 | { 11 | public void SendNotification(User user) 12 | { 13 | Console.WriteLine($"Sending notification to user : {user.Name}"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SOLID/DependencyInversion/INotificationSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DependencyInversion 8 | { 9 | public interface INotificationSender 10 | { 11 | void SendNotification(User user); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SOLID/DependencyInversion/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace DependencyInversion 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SOLID/DependencyInversion/SmsNotification.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DependencyInversion 8 | { 9 | public class SmsNotification : INotificationSender 10 | { 11 | public void SendNotification(User user) 12 | { 13 | Console.WriteLine($"Sending sms notification to {user.Name}"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SOLID/DependencyInversion/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace DependencyInversion 8 | { 9 | public class User 10 | { 11 | public string Name { get; set; } 12 | public string Email { get; set; } 13 | public string Password { get; set; } 14 | public string PhoneNumber { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SOLID/InterfaceSegregation/Cannon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace InterfaceSegregation 8 | { 9 | public class Cannon : IPrinter, IFaxContent 10 | { 11 | public void PrintGrey(string content) 12 | { 13 | Console.WriteLine("Cannon print grey"); 14 | } 15 | 16 | public void PrintColor(string content) 17 | { 18 | Console.WriteLine("Cannon print color"); 19 | } 20 | public void Fax(string content) 21 | { 22 | Console.WriteLine("Cannon print fax"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SOLID/InterfaceSegregation/HpLaserJet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace InterfaceSegregation 8 | { 9 | public class HpLaserJet : IPrinter, IFaxContent, IScanner 10 | { 11 | public void PrintGrey(string content) 12 | { 13 | Console.WriteLine("Hp laser jet print gray"); 14 | } 15 | 16 | public void PrintColor(string content) 17 | { 18 | Console.WriteLine("Hp laser jet print color"); 19 | 20 | } 21 | 22 | public void Scan(string content) 23 | { 24 | Console.WriteLine("Hp laser jet print scan"); 25 | 26 | } 27 | 28 | public void Fax(string content) 29 | { 30 | Console.WriteLine("Hp laser jet print fax"); 31 | 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /SOLID/InterfaceSegregation/IPrinter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace InterfaceSegregation 8 | { 9 | public interface IPrinter 10 | { 11 | void PrintGrey(string content); 12 | void PrintColor(string content); 13 | } 14 | 15 | public interface IScanner 16 | { 17 | void Scan(string content); 18 | 19 | } 20 | 21 | public interface IFaxContent 22 | { 23 | void Fax(string content); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SOLID/InterfaceSegregation/InterfaceSegregation.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SOLID/InterfaceSegregation/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace InterfaceSegregation 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SOLID/LiskovSubstitution/CityDuck.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LiskovSubstitution 8 | { 9 | public class CityDuck : Duck 10 | { 11 | public override void Swim() 12 | { 13 | Console.WriteLine("City duck swim"); 14 | } 15 | 16 | public override void Quack() 17 | { 18 | Console.WriteLine("City duck quack"); 19 | } 20 | 21 | public override void Fly() 22 | { 23 | Console.WriteLine("City duck flies"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SOLID/LiskovSubstitution/Duck.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LiskovSubstitution 8 | { 9 | public abstract class Duck 10 | { 11 | public abstract void Swim(); 12 | public abstract void Quack(); 13 | public abstract void Fly(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /SOLID/LiskovSubstitution/LiskovSubstitution.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SOLID/LiskovSubstitution/MountainDuck.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LiskovSubstitution 8 | { 9 | public class MountainDuck : Duck 10 | { 11 | public override void Swim() 12 | { 13 | Console.WriteLine("Mountain duck swin"); 14 | } 15 | 16 | public override void Quack() 17 | { 18 | Console.WriteLine("Mountain duck quack"); 19 | } 20 | public override void Fly() 21 | { 22 | Console.WriteLine("Mountain duck flies"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SOLID/LiskovSubstitution/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace LiskovSubstitution 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SOLID/LiskovSubstitution/Rectangle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LiskovSubstitution 8 | { 9 | public class Rectangle 10 | { 11 | protected int _height; 12 | protected int _width; 13 | 14 | public virtual void SetHeight(int height) 15 | { 16 | _height = height; 17 | } 18 | 19 | public virtual void SetWidth(int width) 20 | { 21 | _width = width; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SOLID/LiskovSubstitution/RubberDuck.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LiskovSubstitution 8 | { 9 | public class RubberDuck : Duck 10 | { 11 | public override void Swim() 12 | { 13 | Console.WriteLine("Rubber duck swim"); 14 | } 15 | 16 | public override void Quack() 17 | { 18 | Console.WriteLine("Rubber duck quack"); 19 | } 20 | 21 | public override void Fly() 22 | { 23 | throw new NotImplementedException(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SOLID/LiskovSubstitution/Square.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LiskovSubstitution 8 | { 9 | public class Square : Rectangle 10 | { 11 | public override void SetHeight(int height) 12 | { 13 | _width = height; 14 | _height = height; 15 | } 16 | 17 | public override void SetWidth(int width) 18 | { 19 | _width = width; 20 | _height = width; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Class/IInvoiceSaver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OpenClose.Class 8 | { 9 | public interface IInvoiceSaver 10 | { 11 | void Save(Invoice invoice); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Class/Invoice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OpenClose 8 | { 9 | public class Invoice 10 | { 11 | public IEnumerable LineItems { get; set; } 12 | public string Vendor { get; set; } 13 | public string Vendee { get; set; } 14 | public float Total { get; set; } 15 | 16 | public Invoice(IEnumerable lineItems, string vendor, string vendee) 17 | { 18 | LineItems = lineItems; 19 | Vendor = vendor; 20 | Vendee = vendee; 21 | Total = this.CalculateTotal(); 22 | } 23 | 24 | public float CalculateTotal() 25 | { 26 | float total = 0; 27 | foreach (var lineItem in LineItems) 28 | { 29 | total += lineItem.Price * lineItem.Count * (1 + lineItem.TaxRate); 30 | } 31 | 32 | return total; 33 | } 34 | 35 | 36 | 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Class/InvoiceLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OpenClose 8 | { 9 | public class InvoiceLogger 10 | { 11 | private Invoice _invoice; 12 | 13 | public InvoiceLogger(Invoice invoice) 14 | { 15 | _invoice = invoice; 16 | } 17 | 18 | public void Display() 19 | { 20 | Console.WriteLine($"Vendor: {_invoice.Vendor}"); 21 | Console.WriteLine($"Vendee: {_invoice.Vendee}"); 22 | Console.WriteLine($"Total: {_invoice.Total}"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Class/InvoicePersistence.CS: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using OpenClose.Class; 7 | 8 | namespace OpenClose 9 | { 10 | public class InvoicePersistence 11 | { 12 | private Invoice _invoice; 13 | private IInvoiceSaver _invoiceSaver; 14 | 15 | public InvoicePersistence(Invoice invoice, IInvoiceSaver invoiceSaver) 16 | { 17 | _invoice = invoice; 18 | _invoiceSaver = invoiceSaver; 19 | } 20 | 21 | public void Save() 22 | { 23 | _invoiceSaver.Save(_invoice); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Class/LineItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OpenClose 8 | { 9 | public class LineItem 10 | { 11 | public string Name { get; set; } 12 | public float Price { get; set; } 13 | public int Count { get; set; } 14 | public int TaxRate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Class/PdfInvoiceSaver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OpenClose.Class 8 | { 9 | public class PdfInvoiceSaver : IInvoiceSaver 10 | { 11 | public void Save(Invoice invoice) 12 | { 13 | Console.WriteLine("Saving invoice as pdf"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Class/WordInvoiceSaver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OpenClose.Class 8 | { 9 | public class WordInvoiceSaver : IInvoiceSaver 10 | { 11 | public void Save(Invoice invoice) 12 | { 13 | Console.WriteLine("Saving invoice to word file"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Module/Application.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace OpenClose.Class.Module 6 | { 7 | public class Application 8 | { 9 | public void Render(List shapes) 10 | { 11 | for (int i = 0; i < shapes.Count; i++) 12 | { 13 | shapes[i].Render(); 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Module/ShapeType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OpenClose.Class.Module 8 | { 9 | public class Point 10 | { 11 | public int X { get; set; } 12 | public int Y { get; set; } 13 | } 14 | 15 | public class Shape 16 | { 17 | public virtual void Render() 18 | { 19 | 20 | } 21 | } 22 | public class Circle : Shape 23 | { 24 | public int Radius { get; set; } 25 | public Point Center { get; set; } 26 | public override void Render() 27 | { 28 | Console.WriteLine("Render cricle"); 29 | } 30 | } 31 | 32 | public class Rectangle : Shape 33 | { 34 | public int Width { get; set; } 35 | public int Height { get; set; } 36 | public Point TopLeft { get; set; } 37 | public override void Render() 38 | { 39 | Console.WriteLine("Render rectangle"); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /SOLID/OpenClose/OpenClose.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SOLID/OpenClose/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace OpenClose 4 | { 5 | class Program 6 | { 7 | static void Main() 8 | { 9 | } 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /SOLID/SingleResponsibility/Invoice.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SingleResponsibility 8 | { 9 | public class Invoice 10 | { 11 | public IEnumerable LineItems { get; set; } 12 | public string Vendor { get; set; } 13 | public string Vendee { get; set; } 14 | public float Total { get; set; } 15 | 16 | public Invoice(IEnumerable lineItems, string vendor, string vendee) 17 | { 18 | LineItems = lineItems; 19 | Vendor = vendor; 20 | Vendee = vendee; 21 | Total = this.CalculateTotal(); 22 | } 23 | 24 | public float CalculateTotal() 25 | { 26 | float total = 0; 27 | foreach (var lineItem in LineItems) 28 | { 29 | total += lineItem.Price * lineItem.Count * (1 + lineItem.TaxRate); 30 | } 31 | 32 | return total; 33 | } 34 | 35 | 36 | 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /SOLID/SingleResponsibility/InvoiceLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SingleResponsibility 8 | { 9 | public class InvoiceLogger 10 | { 11 | private Invoice _invoice; 12 | 13 | public InvoiceLogger(Invoice invoice) 14 | { 15 | _invoice = invoice; 16 | } 17 | 18 | public void Display() 19 | { 20 | Console.WriteLine($"Vendor: {_invoice.Vendor}"); 21 | Console.WriteLine($"Vendee: {_invoice.Vendee}"); 22 | Console.WriteLine($"Total: {_invoice.Total}"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /SOLID/SingleResponsibility/InvoicePersistence.CS: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SingleResponsibility 8 | { 9 | public class InvoicePersistence 10 | { 11 | private Invoice _invoice; 12 | 13 | public InvoicePersistence(Invoice invoice) 14 | { 15 | _invoice = invoice; 16 | } 17 | 18 | public void SaveToPdf() 19 | { 20 | Console.WriteLine("Saving to pdf"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SOLID/SingleResponsibility/LineItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace SingleResponsibility 8 | { 9 | public class LineItem 10 | { 11 | public string Name { get; set; } 12 | public float Price { get; set; } 13 | public int Count { get; set; } 14 | public int TaxRate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SOLID/SingleResponsibility/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SingleResponsibility 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SOLID/SingleResponsibility/SingleResponsibility.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structural/Adapter/Adapter.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structural/Adapter/EmailSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Adapter 8 | { 9 | public class EmailSender : INotificationSender 10 | { 11 | public void SendNotification(int userId, Notification notification) 12 | { 13 | Console.WriteLine($"Sending email notification, to :{userId}, Titile {notification.Title}, Body: {notification.Body}"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Structural/Adapter/INotificationSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Adapter 8 | { 9 | public interface INotificationSender 10 | { 11 | void SendNotification(int userId, Notification notification); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Structural/Adapter/Notification.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Adapter 8 | { 9 | public class Notification 10 | { 11 | public string Title { get; set; } 12 | public string Body { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Structural/Adapter/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Adapter 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | 11 | INotificationSender notificationSender = new SmsSenderAdapter(); 12 | notificationSender.SendNotification(1, new Notification(){ Title = "Test", Body = "Body"}); 13 | 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Structural/Adapter/PushSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Adapter 8 | { 9 | public class PushSender : INotificationSender 10 | { 11 | public void SendNotification(int userId, Notification notification) 12 | { 13 | Console.WriteLine($"Sending push notification, to :{userId}, Titile {notification.Title}, Body: {notification.Body}"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Structural/Adapter/SmsSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Adapter 8 | { 9 | public class SmsSender 10 | { 11 | public void SendSms(string to, string text) 12 | { 13 | Console.WriteLine($"Sending SMS to : {to}"); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Structural/Adapter/SmsSenderAdapter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Adapter 8 | { 9 | public class SmsSenderAdapter : INotificationSender 10 | { 11 | private SmsSender _smsSender = new SmsSender(); 12 | 13 | public void SendNotification(int userId, Notification notification) 14 | { 15 | string userPhoneNumber = null; // based on userId 16 | _smsSender.SendSms(userPhoneNumber, $"{notification.Title} {notification.Body}"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Structural/Decorator/CheesePizzaDecorator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Decorator 8 | { 9 | public class CheesePizzaDecorator : PizzaDecorator 10 | { 11 | public CheesePizzaDecorator(IPizza pizza) : base(pizza) 12 | { 13 | } 14 | 15 | public override double CalculatePrice() 16 | { 17 | return base.CalculatePrice() + 4.5; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Structural/Decorator/Decorator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structural/Decorator/HamPizzaDecorator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Decorator 8 | { 9 | public class HamPizzaDecorator : PizzaDecorator 10 | { 11 | public HamPizzaDecorator(IPizza pizza) : base(pizza) 12 | { 13 | } 14 | 15 | public override double CalculatePrice() 16 | { 17 | return base.CalculatePrice() + 5; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Structural/Decorator/IPizza.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Decorator 8 | { 9 | public interface IPizza 10 | { 11 | double CalculatePrice(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Structural/Decorator/LargePizza.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Decorator 8 | { 9 | public class LargePizza : IPizza 10 | { 11 | public double CalculatePrice() 12 | { 13 | return 30; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Structural/Decorator/MediumPizza.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Decorator 8 | { 9 | public class MediumPizza : IPizza 10 | { 11 | public double CalculatePrice() 12 | { 13 | return 20; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Structural/Decorator/PizzaDecorator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Decorator 8 | { 9 | public abstract class PizzaDecorator : IPizza 10 | { 11 | private IPizza _pizza; 12 | 13 | protected PizzaDecorator(IPizza pizza) 14 | { 15 | _pizza = pizza; 16 | } 17 | 18 | public virtual double CalculatePrice() 19 | { 20 | return _pizza.CalculatePrice(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Structural/Decorator/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Decorator 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | 11 | var pizzaBase = new MediumPizza(); 12 | 13 | var mediumPizzaWithCheese = new CheesePizzaDecorator(pizzaBase); 14 | 15 | Console.WriteLine($"mediumPizzaWithCheese: {mediumPizzaWithCheese.CalculatePrice()}"); 16 | 17 | var p2 = new SalamiPizzaDecorator(mediumPizzaWithCheese); 18 | Console.WriteLine($"mediumPizzaWithCheese and salami : {p2.CalculatePrice()}"); 19 | 20 | var doubleSalamiCheesePizza = new SalamiPizzaDecorator(p2); 21 | 22 | Console.WriteLine($"doubleSalamiCheesePizza: {doubleSalamiCheesePizza.CalculatePrice()}"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Structural/Decorator/SalamiPizzaDecorator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Decorator 8 | { 9 | public class SalamiPizzaDecorator : PizzaDecorator 10 | { 11 | public SalamiPizzaDecorator(IPizza pizza) : base(pizza) 12 | { 13 | } 14 | 15 | public override double CalculatePrice() 16 | { 17 | return base.CalculatePrice() + 6.5; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Structural/Decorator/SmallPizza.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Decorator 8 | { 9 | public class SmallPizza : IPizza 10 | { 11 | public double CalculatePrice() 12 | { 13 | return 15; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Structural/Facade/DependencyScanner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facade 8 | { 9 | public class DependencyScanner 10 | { 11 | public IEnumerable DependencyScan(string githubUrl) 12 | { 13 | Console.WriteLine("Dependency Scan "); 14 | 15 | return new List() { "DependencyScan Error1"}; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Structural/Facade/Facade.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structural/Facade/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Facade 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Hello World!"); 10 | 11 | 12 | var scanFacade = new ScanFacade(); 13 | 14 | scanFacade.Scan("http://github.com/somerepo"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Structural/Facade/QualityScanner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facade 8 | { 9 | public class QualityScanner 10 | { 11 | public IEnumerable QualityScan(string githubUrl) 12 | { 13 | Console.WriteLine("Quality scan"); 14 | 15 | return new List() { "Error1", "Error2"}; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Structural/Facade/ReportGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facade 8 | { 9 | public class ReportGenerator 10 | { 11 | public void GenerateReport(IEnumerable qualityScanErrors, IEnumerable securityScanErrors, 12 | IEnumerable dependencyScanErrors) 13 | { 14 | Console.WriteLine("Quality Scan Errors:"); 15 | Console.WriteLine(string.Join(", ", qualityScanErrors)); 16 | 17 | Console.WriteLine("Security Scan Errors:"); 18 | Console.WriteLine(string.Join(", ", securityScanErrors)); 19 | 20 | Console.WriteLine("Dependency Scan Errors:"); 21 | Console.WriteLine(string.Join(", ", dependencyScanErrors)); 22 | 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Structural/Facade/ScanFacade.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facade 8 | { 9 | public class ScanFacade 10 | { 11 | private QualityScanner qualityScanner = new QualityScanner(); 12 | private SecurityScanner securityScanner = new SecurityScanner(); 13 | private DependencyScanner dependencyScanner = new DependencyScanner(); 14 | private ReportGenerator reportGenerator = new ReportGenerator(); 15 | 16 | public void Scan(string githubUrl) 17 | { 18 | Console.WriteLine($"Scanning {githubUrl}"); 19 | 20 | var qualityScanErrors = qualityScanner.QualityScan(githubUrl); 21 | var securityScanErrors = securityScanner.SecurityScan(githubUrl); 22 | var dependencyScanErrors = dependencyScanner.DependencyScan(githubUrl); 23 | 24 | Console.WriteLine("Scan report"); 25 | reportGenerator.GenerateReport(qualityScanErrors, securityScanErrors, dependencyScanErrors); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Structural/Facade/SecurityScanner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Facade 8 | { 9 | public class SecurityScanner 10 | { 11 | public IEnumerable SecurityScan(string githubUrl) 12 | { 13 | Console.WriteLine("Security scan"); 14 | 15 | return new List() { "security error1"}; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Structural/Proxy/IYouTubeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Proxy 8 | { 9 | public interface IYouTubeService 10 | { 11 | byte[] GetVideo(int videoId); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Structural/Proxy/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Proxy 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | YouTubeService youTubeService = new YouTubeService(); 10 | 11 | 12 | 13 | ProxyYouTubeService proxyYouTubeService= new ProxyYouTubeService(youTubeService); 14 | proxyYouTubeService.GetVideo(10); 15 | proxyYouTubeService.GetVideo(10); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Structural/Proxy/Proxy.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structural/Proxy/ProxyYouTubeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Proxy 8 | { 9 | public class ProxyYouTubeService : IYouTubeService 10 | { 11 | private YouTubeService _youTubeService; 12 | private Dictionary _cache = new Dictionary(); 13 | 14 | public ProxyYouTubeService(YouTubeService youTubeService) 15 | { 16 | _youTubeService = youTubeService; 17 | } 18 | public byte[] GetVideo(int videoId) 19 | { 20 | Console.WriteLine($"ProxyYouTubeService getting {videoId}"); 21 | 22 | byte[] cachedVideo; 23 | 24 | if (_cache.TryGetValue(videoId, out cachedVideo)) 25 | { 26 | Console.WriteLine($"Getting from cache {videoId}"); 27 | return cachedVideo; 28 | } 29 | 30 | 31 | var video = _youTubeService.GetVideo(videoId); 32 | _cache.Add(videoId, video); 33 | 34 | return video; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Structural/Proxy/YouTubeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Proxy 8 | { 9 | public class YouTubeService : IYouTubeService 10 | { 11 | public byte[] GetVideo(int videoId) 12 | { 13 | Console.WriteLine($"Youtube serivce downloading video: {videoId}"); 14 | 15 | 16 | return new byte[videoId]; 17 | } 18 | } 19 | } 20 | --------------------------------------------------------------------------------