Skip to content

Commit 2b32931

Browse files
Merge pull request #52 from vivopensource/creational-pattern
Merges Creational pattern to dev branch
2 parents b201084 + 9d8bb77 commit 2b32931

54 files changed

Lines changed: 745 additions & 49 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Core/Console/ConsoleLogger.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public virtual void Log(string info)
1616
BaseLogger.LogInformation("{Info}", info);
1717
}
1818

19+
public virtual void Log(string message, object obj)
20+
{
21+
BaseLogger.LogInformation("{Message}: {Obj}", message, obj);
22+
}
23+
1924
public bool LogAndReturnTrue(string info)
2025
{
2126
Log(info);

Core/Console/Interfaces/IConsoleLogger.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ internal interface IConsoleLogger
66
{
77
void Log(string info);
88

9+
void Log(string message, object obj);
10+
911
bool LogAndReturnTrue(string info);
1012

1113
bool LogAndReturnFalse(string info);
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace GofConsoleApp.Examples;
77

8-
internal abstract class AbstractExample
8+
internal abstract class BaseExample
99
{
1010
protected IConsoleLogger Logger { get; private set; } =
1111
new ConsoleLogger(ConsoleExtensions.GetLoggerFactory().CreateLogger(string.Empty));
@@ -43,8 +43,7 @@ protected TEnum AcceptInputEnum<TEnum>(TEnum defaultValue, string identifier, TE
4343

4444
protected string AcceptInputString(string identifier)
4545
{
46-
if (!string.IsNullOrWhiteSpace(identifier))
47-
Logger.Log($"Please enter the {identifier}...");
46+
Logger.Log($"Please enter the {identifier}...");
4847

4948
var input = InputReader.AcceptInput();
5049

@@ -55,8 +54,7 @@ protected string AcceptInputString(string identifier)
5554

5655
protected EnumYesNo AcceptInputYesNo(string identifier = "")
5756
{
58-
if (!string.IsNullOrWhiteSpace(identifier))
59-
Logger.Log($"Please enter the {identifier} (Yes/No)...");
57+
Logger.Log($"Please enter the {identifier} (Yes/No)...");
6058

6159
var input = InputReader.AcceptInput();
6260

@@ -65,8 +63,7 @@ protected EnumYesNo AcceptInputYesNo(string identifier = "")
6563

6664
protected decimal AcceptInputDecimal(string identifier)
6765
{
68-
if (!string.IsNullOrWhiteSpace(identifier))
69-
Logger.Log($"Please enter the {identifier}...");
66+
Logger.Log($"Please enter the {identifier}...");
7067

7168
try
7269
{
@@ -83,7 +80,6 @@ protected decimal AcceptInputDecimal(string identifier)
8380

8481
protected bool IsInvalidOrQuit<TEnum>(TEnum input, TEnum invalid, TEnum quit, out bool output)
8582
{
86-
8783
if (input!.Equals(invalid))
8884
{
8985
output = false;

GofConsoleApp/Examples/Behavioral/CommandPattern/CommandPatternRestaurantExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GofConsoleApp.Examples.Behavioral.CommandPattern;
44

5-
internal class CommandPatternRestaurantExample : AbstractExample
5+
internal class CommandPatternRestaurantExample : BaseExample
66
{
77
protected override bool Execute()
88
{

GofConsoleApp/Examples/Behavioral/CommandPattern/CommandPatternUndoOnlineShopExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace GofConsoleApp.Examples.Behavioral.CommandPattern;
66

7-
internal class CommandPatternUndoOnlineShopExample : AbstractExample
7+
internal class CommandPatternUndoOnlineShopExample : BaseExample
88
{
99
protected override bool Execute()
1010
{

GofConsoleApp/Examples/Behavioral/CorPattern/CorPatternComplexExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace GofConsoleApp.Examples.Behavioral.CorPattern;
1111

12-
internal class CorPatternComplexExample : AbstractExample
12+
internal class CorPatternComplexExample : BaseExample
1313
{
1414
protected override bool Execute()
1515
{

GofConsoleApp/Examples/Behavioral/CorPattern/CorPatternExample.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using GofConsoleApp.Examples.Behavioral.CorPattern.InputExampleComponents;
2-
using GofPatterns.Behavioral.ChainOfResponsibilityPattern.Orchestrators;
3-
using GofPatterns.Behavioral.ChainOfResponsibilityPattern.Orchestrators.Simple;
1+
using Core.Console.Interfaces;
2+
using GofPatterns.Behavioral.ChainOfResponsibilityPattern.Responsibilities;
43
using GofPatterns.Behavioral.ChainOfResponsibilityPattern.Responsibilities.Implementations;
54

65
namespace GofConsoleApp.Examples.Behavioral.CorPattern;
76

8-
internal class CorPatternExample : AbstractExample
7+
internal class CorPatternExample : BaseExample
98
{
109
protected override bool Execute()
1110
{
@@ -16,7 +15,9 @@ protected override bool Execute()
1615

1716
private void ImplementationUsingInterface()
1817
{
19-
var orchestrator = new GofPatterns.Behavioral.ChainOfResponsibilityPattern.Orchestrators.Simple.ResponsibilityChainOrchestrator<string>();
18+
var orchestrator =
19+
new GofPatterns.Behavioral.ChainOfResponsibilityPattern.Orchestrators.Simple.ResponsibilityChainOrchestrator
20+
<string>();
2021

2122
// Responsibility - Foo, Handle - WhenResponsible, Invoke Next >>> WhenNotResponsible
2223
var fooHandler = new ResponsibilityFoo(Logger);
@@ -44,8 +45,9 @@ private void ImplementationUsingInterface()
4445

4546
private void ImplementationUsingConcreteClass()
4647
{
47-
48-
var orchestrator = new GofPatterns.Behavioral.ChainOfResponsibilityPattern.Orchestrators.Simple.ResponsibilityChainOrchestrator<string>();
48+
var orchestrator =
49+
new GofPatterns.Behavioral.ChainOfResponsibilityPattern.Orchestrators.Simple.ResponsibilityChainOrchestrator
50+
<string>();
4951

5052
// Responsibility - Foo, Handle - WhenResponsible, Invoke Next >>> WhenNotResponsible
5153
var executeFoo = new Action<string>(x => Logger.Log($"Handling '{x}' by 'Foo Handler'"));
@@ -72,4 +74,27 @@ private void ImplementationUsingConcreteClass()
7274
// !!! Stops
7375
orchestrator.Execute("Bar");
7476
}
77+
78+
79+
private class ResponsibilityFoo : IResponsibility<string>
80+
{
81+
private readonly IConsoleLogger logger;
82+
83+
public ResponsibilityFoo(IConsoleLogger logger) => this.logger = logger;
84+
85+
public bool IsResponsible(string input) => "Foo".Equals(input);
86+
87+
public void Handle(string input) => logger.Log($"Handled '{input}' by 'FooCoR'");
88+
}
89+
90+
private class ResponsibilityBar : IResponsibility<string>
91+
{
92+
private readonly IConsoleLogger logger;
93+
94+
public ResponsibilityBar(IConsoleLogger logger) => this.logger = logger;
95+
96+
public bool IsResponsible(string input) => "Bar".Equals(input);
97+
98+
public void Handle(string input) => logger.Log($"Handled '{input}' by 'BarCoR'");
99+
}
75100
}

GofConsoleApp/Examples/Behavioral/CorPattern/CorPatternExampleWithOutput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace GofConsoleApp.Examples.Behavioral.CorPattern;
66

7-
internal class CorPatternExampleWithOutput : AbstractExample
7+
internal class CorPatternExampleWithOutput : BaseExample
88
{
99
protected override bool Execute()
1010
{

GofConsoleApp/Examples/Behavioral/MediatorPattern/MediatorPatternExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GofConsoleApp.Examples.Behavioral.MediatorPattern;
44

5-
internal class MediatorPatternExample : AbstractExample
5+
internal class MediatorPatternExample : BaseExample
66
{
77
protected override bool Execute()
88
{

GofConsoleApp/Examples/Behavioral/StatePattern/StatePatternBulbExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace GofConsoleApp.Examples.Behavioral.StatePattern;
77

8-
internal class StatePatternBulbExample : AbstractExample
8+
internal class StatePatternBulbExample : BaseExample
99
{
1010
private readonly IState<BulbStateContext> on = new OnState();
1111
private readonly IState<BulbStateContext> off = new OffState();

0 commit comments

Comments
 (0)