Skip to content

Commit

Permalink
feat: add Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
treveshan committed Aug 2, 2024
1 parent d2c5e4b commit 40b02e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DesignPatterns.Structural.Adapter;
using FluentAssertions;

namespace DesignPatterns.Structural.Tests
{
Expand Down
36 changes: 32 additions & 4 deletions src/DesignPatterns/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using DesignPatterns.Creational.FactoryMethod;
using DesignPatterns.Creational.Prototype;
using DesignPatterns.Creational.Singleton;
using DesignPatterns.Structural.Adapter;
using DesignPatterns.Utils.Display;
using Spectre.Console;

Expand Down Expand Up @@ -31,16 +32,16 @@
Console.Clear();

MainTitle();
var rule = new Rule("[red]Creational[/]");
rule.Justification = Justify.Center;
AnsiConsole.Write(rule);
//var rule = new Rule("[red]Creational[/]");
//rule.Justification = Justify.Center;
//AnsiConsole.Write(rule);

var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Please choose pattern to run:")
.PageSize(10)
.AddChoices(new[] {
"Factory Method","Abstract Factory","Builder","Prototype","Singleton", "Exit"
"Factory Method","Abstract Factory","Builder","Prototype","Singleton","Adapter", "Exit"
}));

switch (choice)
Expand All @@ -60,6 +61,9 @@
case "Singleton":
RunSingletonFactory();
break;
case "Adapter":
RunAdapterFactory();
break;
case "Exit":
exit = true;
break;
Expand Down Expand Up @@ -201,4 +205,28 @@ void RunSingletonFactory()
}
}
}
void RunAdapterFactory()
{
var adapter = new Adapter(new ConsoleOutput());
var exit = false;
while (!exit)
{
var option = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Please choose option:")
.PageSize(10)
.AddChoices(new[] {
"Start", "Exit"
}));
if (!string.IsNullOrEmpty(option))
{
if (option.ToLower() == "exit")
{
exit = true;
break;
}
adapter.Run();
}
}
}

0 comments on commit 40b02e4

Please sign in to comment.