├── .gitignore ├── .vs └── slnx.sqlite ├── Examples ├── Examples.csproj └── Examples.sln ├── ExternalClassLibrary ├── ExternalClassLibrary.csproj └── Truck.cs ├── Payment ├── Payment.csproj ├── Program.cs ├── Readme.md └── Request.cs └── UserCode ├── Program.cs └── UserCode.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from `dotnet new gitignore` 5 | 6 | # dotenv files 7 | .env 8 | 9 | # User-specific files 10 | *.rsuser 11 | *.suo 12 | *.user 13 | *.userosscache 14 | *.sln.docstates 15 | 16 | # User-specific files (MonoDevelop/Xamarin Studio) 17 | *.userprefs 18 | 19 | # Mono auto generated files 20 | mono_crash.* 21 | 22 | # Build results 23 | [Dd]ebug/ 24 | [Dd]ebugPublic/ 25 | [Rr]elease/ 26 | [Rr]eleases/ 27 | x64/ 28 | x86/ 29 | [Ww][Ii][Nn]32/ 30 | [Aa][Rr][Mm]/ 31 | [Aa][Rr][Mm]64/ 32 | bld/ 33 | [Bb]in/ 34 | [Oo]bj/ 35 | [Ll]og/ 36 | [Ll]ogs/ 37 | 38 | # Visual Studio 2015/2017 cache/options directory 39 | .vs/ 40 | # Uncomment if you have tasks that create the project's static files in wwwroot 41 | #wwwroot/ 42 | 43 | # Visual Studio 2017 auto generated files 44 | Generated\ Files/ 45 | 46 | # MSTest test Results 47 | [Tt]est[Rr]esult*/ 48 | [Bb]uild[Ll]og.* 49 | 50 | # NUnit 51 | *.VisualState.xml 52 | TestResult.xml 53 | nunit-*.xml 54 | 55 | # Build Results of an ATL Project 56 | [Dd]ebugPS/ 57 | [Rr]eleasePS/ 58 | dlldata.c 59 | 60 | # Benchmark Results 61 | BenchmarkDotNet.Artifacts/ 62 | 63 | # .NET 64 | project.lock.json 65 | project.fragment.lock.json 66 | artifacts/ 67 | 68 | # Tye 69 | .tye/ 70 | 71 | # ASP.NET Scaffolding 72 | ScaffoldingReadMe.txt 73 | 74 | # StyleCop 75 | StyleCopReport.xml 76 | 77 | # Files built by Visual Studio 78 | *_i.c 79 | *_p.c 80 | *_h.h 81 | *.ilk 82 | *.meta 83 | *.obj 84 | *.iobj 85 | *.pch 86 | *.pdb 87 | *.ipdb 88 | *.pgc 89 | *.pgd 90 | *.rsp 91 | *.sbr 92 | *.tlb 93 | *.tli 94 | *.tlh 95 | *.tmp 96 | *.tmp_proj 97 | *_wpftmp.csproj 98 | *.log 99 | *.tlog 100 | *.vspscc 101 | *.vssscc 102 | .builds 103 | *.pidb 104 | *.svclog 105 | *.scc 106 | 107 | # Chutzpah Test files 108 | _Chutzpah* 109 | 110 | # Visual C++ cache files 111 | ipch/ 112 | *.aps 113 | *.ncb 114 | *.opendb 115 | *.opensdf 116 | *.sdf 117 | *.cachefile 118 | *.VC.db 119 | *.VC.VC.opendb 120 | 121 | # Visual Studio profiler 122 | *.psess 123 | *.vsp 124 | *.vspx 125 | *.sap 126 | 127 | # Visual Studio Trace Files 128 | *.e2e 129 | 130 | # TFS 2012 Local Workspace 131 | $tf/ 132 | 133 | # Guidance Automation Toolkit 134 | *.gpState 135 | 136 | # ReSharper is a .NET coding add-in 137 | _ReSharper*/ 138 | *.[Rr]e[Ss]harper 139 | *.DotSettings.user 140 | 141 | # TeamCity is a build add-in 142 | _TeamCity* 143 | 144 | # DotCover is a Code Coverage Tool 145 | *.dotCover 146 | 147 | # AxoCover is a Code Coverage Tool 148 | .axoCover/* 149 | !.axoCover/settings.json 150 | 151 | # Coverlet is a free, cross platform Code Coverage Tool 152 | coverage*.json 153 | coverage*.xml 154 | coverage*.info 155 | 156 | # Visual Studio code coverage results 157 | *.coverage 158 | *.coveragexml 159 | 160 | # NCrunch 161 | _NCrunch_* 162 | .*crunch*.local.xml 163 | nCrunchTemp_* 164 | 165 | # MightyMoose 166 | *.mm.* 167 | AutoTest.Net/ 168 | 169 | # Web workbench (sass) 170 | .sass-cache/ 171 | 172 | # Installshield output folder 173 | [Ee]xpress/ 174 | 175 | # DocProject is a documentation generator add-in 176 | DocProject/buildhelp/ 177 | DocProject/Help/*.HxT 178 | DocProject/Help/*.HxC 179 | DocProject/Help/*.hhc 180 | DocProject/Help/*.hhk 181 | DocProject/Help/*.hhp 182 | DocProject/Help/Html2 183 | DocProject/Help/html 184 | 185 | # Click-Once directory 186 | publish/ 187 | 188 | # Publish Web Output 189 | *.[Pp]ublish.xml 190 | *.azurePubxml 191 | # Note: Comment the next line if you want to checkin your web deploy settings, 192 | # but database connection strings (with potential passwords) will be unencrypted 193 | *.pubxml 194 | *.publishproj 195 | 196 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 197 | # checkin your Azure Web App publish settings, but sensitive information contained 198 | # in these scripts will be unencrypted 199 | PublishScripts/ 200 | 201 | # NuGet Packages 202 | *.nupkg 203 | # NuGet Symbol Packages 204 | *.snupkg 205 | # The packages folder can be ignored because of Package Restore 206 | **/[Pp]ackages/* 207 | # except build/, which is used as an MSBuild target. 208 | !**/[Pp]ackages/build/ 209 | # Uncomment if necessary however generally it will be regenerated when needed 210 | #!**/[Pp]ackages/repositories.config 211 | # NuGet v3's project.json files produces more ignorable files 212 | *.nuget.props 213 | *.nuget.targets 214 | 215 | # Microsoft Azure Build Output 216 | csx/ 217 | *.build.csdef 218 | 219 | # Microsoft Azure Emulator 220 | ecf/ 221 | rcf/ 222 | 223 | # Windows Store app package directories and files 224 | AppPackages/ 225 | BundleArtifacts/ 226 | Package.StoreAssociation.xml 227 | _pkginfo.txt 228 | *.appx 229 | *.appxbundle 230 | *.appxupload 231 | 232 | # Visual Studio cache files 233 | # files ending in .cache can be ignored 234 | *.[Cc]ache 235 | # but keep track of directories ending in .cache 236 | !?*.[Cc]ache/ 237 | 238 | # Others 239 | ClientBin/ 240 | ~$* 241 | *~ 242 | *.dbmdl 243 | *.dbproj.schemaview 244 | *.jfm 245 | *.pfx 246 | *.publishsettings 247 | orleans.codegen.cs 248 | 249 | # Including strong name files can present a security risk 250 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 251 | #*.snk 252 | 253 | # Since there are multiple workflows, uncomment next line to ignore bower_components 254 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 255 | #bower_components/ 256 | 257 | # RIA/Silverlight projects 258 | Generated_Code/ 259 | 260 | # Backup & report files from converting an old project file 261 | # to a newer Visual Studio version. Backup files are not needed, 262 | # because we have git ;-) 263 | _UpgradeReport_Files/ 264 | Backup*/ 265 | UpgradeLog*.XML 266 | UpgradeLog*.htm 267 | ServiceFabricBackup/ 268 | *.rptproj.bak 269 | 270 | # SQL Server files 271 | *.mdf 272 | *.ldf 273 | *.ndf 274 | 275 | # Business Intelligence projects 276 | *.rdl.data 277 | *.bim.layout 278 | *.bim_*.settings 279 | *.rptproj.rsuser 280 | *- [Bb]ackup.rdl 281 | *- [Bb]ackup ([0-9]).rdl 282 | *- [Bb]ackup ([0-9][0-9]).rdl 283 | 284 | # Microsoft Fakes 285 | FakesAssemblies/ 286 | 287 | # GhostDoc plugin setting file 288 | *.GhostDoc.xml 289 | 290 | # Node.js Tools for Visual Studio 291 | .ntvs_analysis.dat 292 | node_modules/ 293 | 294 | # Visual Studio 6 build log 295 | *.plg 296 | 297 | # Visual Studio 6 workspace options file 298 | *.opt 299 | 300 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 301 | *.vbw 302 | 303 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 304 | *.vbp 305 | 306 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 307 | *.dsw 308 | *.dsp 309 | 310 | # Visual Studio 6 technical files 311 | *.ncb 312 | *.aps 313 | 314 | # Visual Studio LightSwitch build output 315 | **/*.HTMLClient/GeneratedArtifacts 316 | **/*.DesktopClient/GeneratedArtifacts 317 | **/*.DesktopClient/ModelManifest.xml 318 | **/*.Server/GeneratedArtifacts 319 | **/*.Server/ModelManifest.xml 320 | _Pvt_Extensions 321 | 322 | # Paket dependency manager 323 | .paket/paket.exe 324 | paket-files/ 325 | 326 | # FAKE - F# Make 327 | .fake/ 328 | 329 | # CodeRush personal settings 330 | .cr/personal 331 | 332 | # Python Tools for Visual Studio (PTVS) 333 | __pycache__/ 334 | *.pyc 335 | 336 | # Cake - Uncomment if you are using it 337 | # tools/** 338 | # !tools/packages.config 339 | 340 | # Tabs Studio 341 | *.tss 342 | 343 | # Telerik's JustMock configuration file 344 | *.jmconfig 345 | 346 | # BizTalk build output 347 | *.btp.cs 348 | *.btm.cs 349 | *.odx.cs 350 | *.xsd.cs 351 | 352 | # OpenCover UI analysis results 353 | OpenCover/ 354 | 355 | # Azure Stream Analytics local run output 356 | ASALocalRun/ 357 | 358 | # MSBuild Binary and Structured Log 359 | *.binlog 360 | 361 | # NVidia Nsight GPU debugger configuration file 362 | *.nvuser 363 | 364 | # MFractors (Xamarin productivity tool) working folder 365 | .mfractor/ 366 | 367 | # Local History for Visual Studio 368 | .localhistory/ 369 | 370 | # Visual Studio History (VSHistory) files 371 | .vshistory/ 372 | 373 | # BeatPulse healthcheck temp database 374 | healthchecksdb 375 | 376 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 377 | MigrationBackup/ 378 | 379 | # Ionide (cross platform F# VS Code tools) working folder 380 | .ionide/ 381 | 382 | # Fody - auto-generated XML schema 383 | FodyWeavers.xsd 384 | 385 | # VS Code files for those working on multiple tools 386 | .vscode/* 387 | !.vscode/settings.json 388 | !.vscode/tasks.json 389 | !.vscode/launch.json 390 | !.vscode/extensions.json 391 | *.code-workspace 392 | 393 | # Local History for Visual Studio Code 394 | .history/ 395 | 396 | # Windows Installer files from build outputs 397 | *.cab 398 | *.msi 399 | *.msix 400 | *.msm 401 | *.msp 402 | 403 | # JetBrains Rider 404 | *.sln.iml 405 | .idea 406 | 407 | ## 408 | ## Visual studio for Mac 409 | ## 410 | 411 | 412 | # globs 413 | Makefile.in 414 | *.userprefs 415 | *.usertasks 416 | config.make 417 | config.status 418 | aclocal.m4 419 | install-sh 420 | autom4te.cache/ 421 | *.tar.gz 422 | tarballs/ 423 | test-results/ 424 | 425 | # Mac bundle stuff 426 | *.dmg 427 | *.app 428 | 429 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 430 | # General 431 | .DS_Store 432 | .AppleDouble 433 | .LSOverride 434 | 435 | # Icon must end with two \r 436 | Icon 437 | 438 | 439 | # Thumbnails 440 | ._* 441 | 442 | # Files that might appear in the root of a volume 443 | .DocumentRevisions-V100 444 | .fseventsd 445 | .Spotlight-V100 446 | .TemporaryItems 447 | .Trashes 448 | .VolumeIcon.icns 449 | .com.apple.timemachine.donotpresent 450 | 451 | # Directories potentially created on remote AFP share 452 | .AppleDB 453 | .AppleDesktop 454 | Network Trash Folder 455 | Temporary Items 456 | .apdisk 457 | 458 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore 459 | # Windows thumbnail cache files 460 | Thumbs.db 461 | ehthumbs.db 462 | ehthumbs_vista.db 463 | 464 | # Dump file 465 | *.stackdump 466 | 467 | # Folder config file 468 | [Dd]esktop.ini 469 | 470 | # Recycle Bin used on file shares 471 | $RECYCLE.BIN/ 472 | 473 | # Windows Installer files 474 | *.cab 475 | *.msi 476 | *.msix 477 | *.msm 478 | *.msp 479 | 480 | # Windows shortcuts 481 | *.lnk 482 | -------------------------------------------------------------------------------- /.vs/slnx.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iCodeNext/DesignPattern/dc08db0c9d080417111a31d50c03c9ec5c08755d/.vs/slnx.sqlite -------------------------------------------------------------------------------- /Examples/Examples.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Library 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Examples/Examples.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.35430.204 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserCode", "..\UserCode\UserCode.csproj", "{03E39C4B-5B4C-4FD2-A79D-AC86704AF3DC}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExternalClassLibrary", "..\ExternalClassLibrary\ExternalClassLibrary.csproj", "{B77A43A4-BF8D-44E1-B3E8-8F6DD365DEAB}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RealExample", "RealExample", "{BEFC8EDE-A568-4AC3-B3EA-B68427103370}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Payment", "..\Payment\Payment.csproj", "{E7F0B3A7-6105-43CB-B4E1-3733111D4EB8}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {03E39C4B-5B4C-4FD2-A79D-AC86704AF3DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {03E39C4B-5B4C-4FD2-A79D-AC86704AF3DC}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {03E39C4B-5B4C-4FD2-A79D-AC86704AF3DC}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {03E39C4B-5B4C-4FD2-A79D-AC86704AF3DC}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {B77A43A4-BF8D-44E1-B3E8-8F6DD365DEAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {B77A43A4-BF8D-44E1-B3E8-8F6DD365DEAB}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {B77A43A4-BF8D-44E1-B3E8-8F6DD365DEAB}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {B77A43A4-BF8D-44E1-B3E8-8F6DD365DEAB}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {E7F0B3A7-6105-43CB-B4E1-3733111D4EB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {E7F0B3A7-6105-43CB-B4E1-3733111D4EB8}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {E7F0B3A7-6105-43CB-B4E1-3733111D4EB8}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {E7F0B3A7-6105-43CB-B4E1-3733111D4EB8}.Release|Any CPU.Build.0 = Release|Any CPU 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | GlobalSection(NestedProjects) = preSolution 37 | {E7F0B3A7-6105-43CB-B4E1-3733111D4EB8} = {BEFC8EDE-A568-4AC3-B3EA-B68427103370} 38 | EndGlobalSection 39 | GlobalSection(ExtensibilityGlobals) = postSolution 40 | SolutionGuid = {22B9C537-2B7B-4D6D-B152-E2C4BA31F193} 41 | EndGlobalSection 42 | EndGlobal 43 | -------------------------------------------------------------------------------- /ExternalClassLibrary/ExternalClassLibrary.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ExternalClassLibrary/Truck.cs: -------------------------------------------------------------------------------- 1 | namespace ExternalClassLibrary; 2 | 3 | // External library class (inaccessible for modification) 4 | public class Truck(int price, string from) 5 | { 6 | public void Deliver() 7 | { 8 | Console.WriteLine("Deliver package by truck ..."); 9 | } 10 | } -------------------------------------------------------------------------------- /Payment/Payment.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Payment/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ChainOfResponsibilityExample; 4 | 5 | 6 | public class SupportTicket 7 | { 8 | public string Issue { get; } 9 | public int Severity { get; } 10 | 11 | public SupportTicket(string issue, int severity) 12 | { 13 | Issue = issue; 14 | Severity = severity; // 1 = Basic, 2 = Technical, 3 = Managerial 15 | } 16 | } 17 | 18 | // Abstract Handler 19 | public abstract class SupportHandler 20 | { 21 | protected SupportHandler? NextHandler { get; set; } 22 | 23 | public void SetNext(SupportHandler handler) 24 | { 25 | NextHandler = handler; 26 | } 27 | 28 | public void Handle(SupportTicket ticket) 29 | { 30 | if (CanHandle(ticket)) 31 | { 32 | Process(ticket); 33 | } 34 | else if (NextHandler != null) 35 | { 36 | Console.WriteLine($"{GetType().Name} passed the ticket to {NextHandler.GetType().Name}"); 37 | NextHandler.Handle(ticket); 38 | } 39 | else 40 | { 41 | Console.WriteLine("No handler was able to process the ticket."); 42 | } 43 | } 44 | 45 | protected abstract bool CanHandle(SupportTicket ticket); 46 | protected abstract void Process(SupportTicket ticket); 47 | } 48 | 49 | public class BasicSupportHandler : SupportHandler 50 | { 51 | protected override bool CanHandle(SupportTicket ticket) 52 | { 53 | return ticket.Severity == 1; 54 | } 55 | 56 | protected override void Process(SupportTicket ticket) 57 | { 58 | Console.WriteLine($"Basic Support handled the issue: {ticket.Issue}"); 59 | } 60 | } 61 | 62 | public class TechnicalSupportHandler : SupportHandler 63 | { 64 | protected override bool CanHandle(SupportTicket ticket) 65 | { 66 | return ticket.Severity == 2; 67 | } 68 | 69 | protected override void Process(SupportTicket ticket) 70 | { 71 | Console.WriteLine($"Technical Support handled the issue: {ticket.Issue}"); 72 | } 73 | } 74 | 75 | public class ProductSupportHandler : SupportHandler 76 | { 77 | protected override bool CanHandle(SupportTicket ticket) 78 | { 79 | return ticket.Severity == 5; 80 | } 81 | 82 | protected override void Process(SupportTicket ticket) 83 | { 84 | Console.WriteLine($"Manager handled the issue: {ticket.Issue}"); 85 | } 86 | } 87 | 88 | public class ManagerSupportHandler : SupportHandler 89 | { 90 | protected override bool CanHandle(SupportTicket ticket) 91 | { 92 | return ticket.Severity == 3; 93 | } 94 | 95 | protected override void Process(SupportTicket ticket) 96 | { 97 | Console.WriteLine($"Manager handled the issue: {ticket.Issue}"); 98 | } 99 | } 100 | 101 | 102 | public class Program 103 | { 104 | public static void Main(string[] args) 105 | { 106 | var basicSupport = new BasicSupportHandler(); 107 | var technicalSupport = new TechnicalSupportHandler(); 108 | var managerSupport = new ManagerSupportHandler(); 109 | var productSupport = new ProductSupportHandler(); 110 | 111 | basicSupport.SetNext(technicalSupport); 112 | technicalSupport.SetNext(productSupport); 113 | productSupport.SetNext(managerSupport); 114 | 115 | var tickets = new[] 116 | { 117 | new SupportTicket("Password reset request", 1), 118 | new SupportTicket("System crash during operation", 2), 119 | new SupportTicket("Budget approval for software purchase", 3), 120 | new SupportTicket("Unknown severe issue", 4) 121 | }; 122 | 123 | foreach (var ticket in tickets) 124 | { 125 | Console.WriteLine($"\nProcessing ticket: {ticket.Issue}"); 126 | basicSupport.Handle(ticket); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Payment/Readme.md: -------------------------------------------------------------------------------- 1 | ## Description: 2 | You are building an e-commerce application where users can pay using multiple payment methods: CreditCard, PayPal, and CryptoCurrency. 3 | 4 | The CryptoCurrency payment system comes from a third-party library, and it is incompatible with your IPaymentProcessor interface. 5 | You want to support a dynamic pricing strategy where discounts or additional fees are applied based on the payment method. 6 | If the user selects an unsupported payment method, the system should default to a NullPaymentProcessor that logs an error gracefully. 7 | 8 | 9 | ## Input: 10 | 11 | Payment Method: CreditCard 12 |
13 | Amount: 100 14 | 15 | ### Output: 16 | Applying 2% fee for credit card payment. 17 |
18 | Processing credit card payment of $102.00 19 | 20 | 21 | ## Input: 22 | 23 | Payment Method: CryptoCurrency 24 |
25 | Amount: 200 26 | 27 | ### Output: 28 | No adjustment for the selected payment method. 29 |
30 | Processing cryptocurrency payment of $200.00 via third-party library 31 | 32 | 33 | ## Input: 34 | 35 | Payment Method: Unsupported 36 |
37 | Amount: 150 38 | 39 | ### Output: 40 | No adjustment for the selected payment method. 41 |
42 | Payment method not supported. Unable to process $150.00. -------------------------------------------------------------------------------- /Payment/Request.cs: -------------------------------------------------------------------------------- 1 | public class Request 2 | { 3 | public string Condition { get; internal set; } 4 | } -------------------------------------------------------------------------------- /UserCode/Program.cs: -------------------------------------------------------------------------------- 1 | //#region Simple 2 | //public class Program 3 | //{ 4 | // public static void Main() 5 | // { 6 | // var type = Console.ReadLine(); 7 | 8 | // switch (type) 9 | // { 10 | // case "Air": 11 | // { 12 | // Console.WriteLine("Send package by air ..."); 13 | // break; 14 | // } 15 | // case "Train": 16 | // { 17 | // Console.WriteLine("Send package by Train ..."); 18 | // break; 19 | // } 20 | // default: 21 | // break; 22 | // } 23 | // } 24 | //} 25 | //#endregion 26 | 27 | 28 | 29 | //#region 1.1 30 | 31 | //public class Program 32 | //{ 33 | // public static void Main() 34 | // { 35 | // var type = Console.ReadLine(); 36 | 37 | // switch (type) 38 | // { 39 | // case "Air": 40 | // { 41 | // var instance = new Air(); 42 | // instance.SendByAir(); 43 | // break; 44 | // } 45 | // case "Train": 46 | // { 47 | // var train = new Train(); 48 | // train.SendIt(); 49 | // break; 50 | // } 51 | // default: 52 | // break; 53 | // } 54 | // } 55 | //} 56 | 57 | //public class Air 58 | //{ 59 | // public void SendByAir() 60 | // { 61 | // Console.WriteLine("Send package by air ..."); 62 | // } 63 | //} 64 | 65 | //public class Train 66 | //{ 67 | // public void SendIt() 68 | // { 69 | // Console.WriteLine("Send package by Train ..."); 70 | // } 71 | //} 72 | 73 | //#endregion 74 | 75 | //#region 1.2 76 | 77 | //public class Program 78 | //{ 79 | // public static void Main() 80 | // { 81 | // var type = Console.ReadLine(); 82 | // TransportService.Send(type); 83 | // } 84 | //} 85 | 86 | //public class TransportService 87 | //{ 88 | // public static void Send(string type) 89 | // { 90 | // switch (type) 91 | // { 92 | // case "Air": 93 | // { 94 | // var instance = new Air(); 95 | // instance.SendByAir(); 96 | // break; 97 | // } 98 | // case "Train": 99 | // { 100 | // var train = new Train(); 101 | // train.SendIt(); 102 | // break; 103 | // } 104 | // default: 105 | // break; 106 | // } 107 | // } 108 | //} 109 | 110 | //public class Air 111 | //{ 112 | // public void SendByAir() 113 | // { 114 | // Console.WriteLine("Send package by air ..."); 115 | // } 116 | //} 117 | 118 | //public class Train 119 | //{ 120 | // public void SendIt() 121 | // { 122 | // Console.WriteLine("Send package by Train ..."); 123 | // } 124 | //} 125 | 126 | //#endregion 127 | 128 | //#region 1.3 129 | 130 | //public class Program 131 | //{ 132 | // public static void Main() 133 | // { 134 | // var type = Console.ReadLine(); 135 | // TransportService.Send(type); 136 | // } 137 | //} 138 | 139 | //public class TransportService 140 | //{ 141 | // public static void Send(string type) 142 | // { 143 | // switch (type) 144 | // { 145 | // case "Air": 146 | // { 147 | // ITransport instance = new Air(); 148 | // instance.Send(); 149 | // break; 150 | // } 151 | // case "Train": 152 | // { 153 | // ITransport train = new Train(); 154 | // train.Send(); 155 | // break; 156 | // } 157 | // default: 158 | // break; 159 | // } 160 | // } 161 | //} 162 | 163 | //public interface ITransport 164 | //{ 165 | // void Send(); 166 | //} 167 | 168 | //public class Air : ITransport 169 | //{ 170 | // public void Send() 171 | // { 172 | // Console.WriteLine("Send package by air ..."); 173 | // } 174 | //} 175 | 176 | //public class Train : ITransport 177 | //{ 178 | // public void Send() 179 | // { 180 | // Console.WriteLine("Send package by Train ..."); 181 | // } 182 | //} 183 | 184 | //public class Truck : ITransport 185 | //{ 186 | // public void Send() 187 | // { 188 | // throw new NotImplementedException(); 189 | // } 190 | //} 191 | 192 | //#endregion 193 | 194 | 195 | 196 | 197 | //#region 1.4 198 | 199 | //public class Program 200 | //{ 201 | // public static void Main() 202 | // { 203 | // var type = Console.ReadLine(); 204 | // ITransport transport = TransportService.Create(type); 205 | // transport.Send(); 206 | // } 207 | //} 208 | 209 | //public class TransportService 210 | //{ 211 | // public static ITransport Create(string type) 212 | // { 213 | // switch (type) 214 | // { 215 | // case "Air": 216 | // { 217 | // return new Air(); 218 | // } 219 | // case "Train": 220 | // { 221 | // return new Train(); 222 | // } 223 | // default: 224 | // throw new NotImplementedException(); 225 | // } 226 | // } 227 | //} 228 | 229 | //public interface ITransport 230 | //{ 231 | // void Send(); 232 | //} 233 | 234 | //public class Air : ITransport 235 | //{ 236 | // public void Send() 237 | // { 238 | // Console.WriteLine("Send package by air ..."); 239 | // } 240 | //} 241 | 242 | //public class Train : ITransport 243 | //{ 244 | // public void Send() 245 | // { 246 | // Console.WriteLine("Send package by Train ..."); 247 | // } 248 | //} 249 | 250 | //#endregion 251 | 252 | //#region 1.5 253 | 254 | //public class Program 255 | //{ 256 | // public static void Main() 257 | // { 258 | // var type = Console.ReadLine(); 259 | // ITransport transport = TransportService.Create(type); 260 | // transport.Send(); 261 | // } 262 | //} 263 | 264 | //public class TransportService 265 | //{ 266 | // public static ITransport Create(string type) 267 | // { 268 | // switch (type) 269 | // { 270 | // case "Air": 271 | // { 272 | // var factory = new AirFactory(); 273 | // return factory.Create(); 274 | // } 275 | // case "Train": 276 | // { 277 | // var factory = new TrainFactory(); 278 | // return factory.CreateTrain(); 279 | // } 280 | // default: 281 | // throw new NotImplementedException(); 282 | // } 283 | // } 284 | //} 285 | 286 | //public interface ITransport 287 | //{ 288 | // void Send(); 289 | //} 290 | 291 | //public class Air : ITransport 292 | //{ 293 | // public void Send() 294 | // { 295 | // Console.WriteLine("Send package by air ..."); 296 | // } 297 | //} 298 | 299 | //public class Train : ITransport 300 | //{ 301 | // public void Send() 302 | // { 303 | // Console.WriteLine("Send package by Train ..."); 304 | // } 305 | //} 306 | 307 | //public class AirFactory 308 | //{ 309 | // public ITransport Create() 310 | // { 311 | // //manage instance -> single 312 | // return new Air(); 313 | // } 314 | //} 315 | 316 | //public class TrainFactory 317 | //{ 318 | // public ITransport CreateTrain() 319 | // { 320 | // //manage instance -> pool 321 | // return new Train(); 322 | // } 323 | //} 324 | 325 | //#endregion 326 | 327 | //#region 1.6 328 | 329 | //public class Program 330 | //{ 331 | // public static void Main() 332 | // { 333 | // var type = Console.ReadLine(); 334 | // ITransport transport = TransportService.Create(type); 335 | // transport.Send(); 336 | // } 337 | //} 338 | 339 | //public class TransportService 340 | //{ 341 | // public static ITransport Create(string type) 342 | // { 343 | // switch (type) 344 | // { 345 | // case "Air": 346 | // { 347 | // var factory = new AirFactory(); 348 | // return factory.CreateInstance(); 349 | // } 350 | // case "Train": 351 | // { 352 | // var factory = new TrainFactory(); 353 | // return factory.CreateInstance(); 354 | // } 355 | // case "Truck": 356 | // { 357 | // var factory = new TruckFactory(); 358 | // return factory.CreateInstance(); 359 | // } 360 | // default: 361 | // throw new NotImplementedException(); 362 | // } 363 | // } 364 | //} 365 | 366 | //public interface ITransport 367 | //{ 368 | // void Send(); 369 | //} 370 | 371 | //public class Air : ITransport 372 | //{ 373 | // public void Send() 374 | // { 375 | // Console.WriteLine("Send package by air ..."); 376 | // } 377 | //} 378 | 379 | //public class Train : ITransport 380 | //{ 381 | // public void Send() 382 | // { 383 | // Console.WriteLine("Send package by Train ..."); 384 | // } 385 | //} 386 | 387 | //public class Truck : ITransport 388 | //{ 389 | // public void Send() 390 | // { 391 | // Console.WriteLine("Send package by Truck ..."); 392 | // } 393 | //} 394 | 395 | 396 | //public interface ITransportFactory 397 | //{ 398 | // ITransport CreateInstance(); 399 | //} 400 | 401 | //public class AirFactory : ITransportFactory 402 | //{ 403 | // public ITransport CreateInstance() 404 | // { 405 | // manage instance 406 | // return new Air(); 407 | // } 408 | //} 409 | 410 | //public class TrainFactory : ITransportFactory 411 | //{ 412 | // public ITransport CreateInstance() 413 | // { 414 | // manage instance 415 | // return new Train(); 416 | // } 417 | //} 418 | 419 | //public class TruckFactory : ITransportFactory 420 | //{ 421 | // public ITransport CreateInstance() 422 | // { 423 | // manage instance 424 | // return new Truck(); 425 | // } 426 | //} 427 | 428 | //#endregion 429 | 430 | //#region 1.7 431 | 432 | //public class Program 433 | //{ 434 | // public static void Main() 435 | // { 436 | // var type = Console.ReadLine(); 437 | // ITransport transport = new TransportService("Truck", new TruckFactory()) 438 | // .Create(type); 439 | // transport.Send(); 440 | // } 441 | //} 442 | 443 | //#region ...dll 444 | 445 | //public class TransportService 446 | //{ 447 | // Dictionary _factories = []; 448 | // public TransportService() 449 | // { 450 | // _factories.Add("Air", new AirFactory()); 451 | // _factories.Add("Train", new TrainFactory()); 452 | // } 453 | 454 | // public TransportService(string type, ITransportFactory transportFactory) 455 | // { 456 | // _factories.Add(type, transportFactory); 457 | // } 458 | 459 | // public ITransport Create(string type) 460 | // { 461 | // return _factories[type].CreateInstance(); 462 | // } 463 | //} 464 | 465 | //public interface ITransport 466 | //{ 467 | // void Send(); 468 | //} 469 | 470 | //public class Air : ITransport 471 | //{ 472 | // public void Send() 473 | // { 474 | // Console.WriteLine("Send package by air ..."); 475 | // } 476 | //} 477 | 478 | //public class Train : ITransport 479 | //{ 480 | // public void Send() 481 | // { 482 | // Console.WriteLine("Send package by Train ..."); 483 | // } 484 | //} 485 | 486 | 487 | 488 | //public interface ITransportFactory 489 | //{ 490 | // ITransport CreateInstance(); 491 | //} 492 | 493 | //public class AirFactory : ITransportFactory 494 | //{ 495 | // public ITransport CreateInstance() 496 | // { 497 | // //manage instance 498 | // return new Air(); 499 | // } 500 | //} 501 | 502 | //public class TrainFactory : ITransportFactory 503 | //{ 504 | // public ITransport CreateInstance() 505 | // { 506 | // //manage instance 507 | // return new Train(); 508 | // } 509 | //} 510 | 511 | 512 | //#endregion 513 | 514 | //public class TruckFactory : ITransportFactory 515 | //{ 516 | // public ITransport CreateInstance() 517 | // { 518 | // return new Truck(); 519 | // } 520 | //} 521 | 522 | //public class Truck : ITransport 523 | //{ 524 | // public void Send() 525 | // { 526 | // throw new NotImplementedException(); 527 | // } 528 | //} 529 | 530 | //#endregion 531 | 532 | 533 | #region 1.8 534 | 535 | using ExternalClassLibrary; 536 | 537 | public class Program 538 | { 539 | public static void Main() 540 | { 541 | var type = Console.ReadLine(); 542 | ITransport transport = TransportService.Create(type); 543 | transport.Send(); 544 | } 545 | } 546 | 547 | public class TransportService 548 | { 549 | public static ITransport Create(string type) 550 | { 551 | switch (type) 552 | { 553 | case "Air": 554 | { 555 | var factory = new AirFactory(); 556 | return factory.CreateInstance(); 557 | } 558 | case "Train": 559 | { 560 | var factory = new TrainFactory(); 561 | return factory.CreateInstance(); 562 | } 563 | 564 | case "Truck": 565 | { 566 | return new TruckAdapter(); 567 | } 568 | default: 569 | throw new NotImplementedException(); 570 | } 571 | } 572 | } 573 | 574 | public interface ITransport 575 | { 576 | void Send(); 577 | } 578 | 579 | public class Air : ITransport 580 | { 581 | public void Send() 582 | { 583 | Console.WriteLine("Send package by air ..."); 584 | } 585 | } 586 | 587 | public class Train : ITransport 588 | { 589 | public void Send() 590 | { 591 | Console.WriteLine("Send package by Train ..."); 592 | } 593 | } 594 | 595 | public class TruckAdapter : ITransport 596 | { 597 | private readonly Truck _truck; 598 | 599 | public TruckAdapter() 600 | { 601 | _truck = new Truck(5,"THR"); 602 | } 603 | 604 | public void Send() 605 | { 606 | // Delegate the call to the Truck class's Deliver method 607 | // string -> xml nodes 608 | // 609 | // ............ 610 | // 611 | _truck.Deliver(); 612 | } 613 | } 614 | 615 | public interface ITransportFactory 616 | { 617 | ITransport CreateInstance(); 618 | } 619 | 620 | public class AirFactory : ITransportFactory 621 | { 622 | public ITransport CreateInstance() 623 | { 624 | //manage instance 625 | return new Air(); 626 | } 627 | } 628 | 629 | public class TrainFactory : ITransportFactory 630 | { 631 | public ITransport CreateInstance() 632 | { 633 | //manage instance 634 | return new Train(); 635 | } 636 | } 637 | 638 | #endregion -------------------------------------------------------------------------------- /UserCode/UserCode.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------