Skip to content

Commit f36d1c5

Browse files
Merge pull request #73 from vivopensource/dev
Merges Dev to Main V-1.3.4
2 parents 4545ba5 + 513c7bb commit f36d1c5

File tree

22 files changed

+596
-75
lines changed

22 files changed

+596
-75
lines changed

.github/workflows/pull_request.yml

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ name: Pull Request
33

44
on:
55
pull_request:
6-
branches:
7-
- 'dev'
86

97
jobs:
108

11-
test-linux:
9+
test-pr:
1210

1311
runs-on: ubuntu-latest
1412

@@ -36,7 +34,7 @@ jobs:
3634
- name: Test
3735
run: dotnet test --configuration Debug --no-build --verbosity normal --collect:"XPlat Code Coverage" --results-directory ./coverage
3836

39-
- name: Code Coverage Result MD
37+
- name: Code Coverage Result
4038
uses: irongut/CodeCoverageSummary@v1.3.0
4139
with:
4240
filename: coverage/**/coverage.cobertura.xml
@@ -49,47 +47,11 @@ jobs:
4947
output: both
5048
thresholds: '80 90'
5149

52-
- name: Code Coverage Result MD
50+
- name: Code Coverage Result Markdown
5351
uses: marocchino/sticky-pull-request-comment@v2
5452
with:
5553
recreate: true
5654
path: code-coverage-results.md
5755

5856
- name: Write to Job Summary
59-
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
60-
61-
test-windows:
62-
63-
runs-on: windows-latest
64-
65-
env:
66-
Solution_Name: GofPatterns.sln
67-
Test_Project_Path: GofPatternsTests\GofPatternsTests.csproj
68-
69-
steps:
70-
- name: Checkout
71-
uses: actions/checkout@v3
72-
with:
73-
fetch-depth: 0
74-
75-
- name: Install .NET Core
76-
uses: actions/setup-dotnet@v3
77-
with:
78-
dotnet-version: 6.0.x
79-
80-
- name: Setup MSBuild.exe
81-
uses: microsoft/setup-msbuild@v1.0.2
82-
83-
- name: Restore dependencies
84-
run: dotnet restore
85-
86-
- name: Build
87-
run: dotnet build
88-
89-
- name: Test
90-
run: dotnet test
91-
92-
- name: Restore the application
93-
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
94-
env:
95-
Configuration: Debug
57+
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ jobs:
6161
run: dotnet pack GofPatterns/GofPatterns.csproj -c Release --no-restore --no-build --include-symbols -p:SymbolPackageFormat=snupkg -o .
6262

6363
# Push to NuGet
64-
- name: Deploy
64+
- name: Publish
6565
run: dotnet nuget push *.nupkg --skip-duplicate -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}}

GofConsoleApp/Examples/ExecutionHelpers/PatternOptions.cs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using GofConsoleApp.Examples.Creational.FactoryPattern;
1010
using GofConsoleApp.Examples.Structural.AdapterPattern;
1111
using GofConsoleApp.Examples.Structural.BridgePattern;
12+
using GofConsoleApp.Examples.Structural.CompositePattern;
1213
using GofConsoleApp.Examples.Structural.DecoratorPattern;
1314
using GofConsoleApp.Examples.Structural.FlyweightPattern;
1415
using GofConsoleApp.Examples.Structural.ProxyPattern;
@@ -25,9 +26,11 @@ internal static class PatternOptions
2526
internal const string ProxyPatternOptionBoundedInputOutput = "12.3";
2627
internal const string AdapterPatternOption = "13";
2728
internal const string FlyweightPatternOption = "14";
28-
internal const string MediatorPatternOption = "15";
29-
internal const string ObserverPatternOption = "16.1";
30-
internal const string ObserverPatternOptionWithType = "16.2";
29+
internal const string BridgePatterOptionSingleImplementations = "15";
30+
internal const string BridgePatterOptionMultipleImplementations = "15.2";
31+
internal const string BridgePatterOptionMarker = "15.3";
32+
internal const string CompositePatternOptionWithInput = "16.1";
33+
internal const string CompositePatternOptionWithoutInput = "16.2";
3134

3235
internal const string ChainOfResponsibilityPatternOption = "21";
3336
internal const string ChainOfResponsibilityPatternOption2 = "21.2";
@@ -38,9 +41,9 @@ internal static class PatternOptions
3841
internal const string StatePatternOptionDriveExample = "23.2";
3942
internal const string StrategyPatternOptionSender = "24";
4043
internal const string StrategyPatternOptionPayment = "24.2";
41-
internal const string BridgePatterOptionSingleImplementations = "25";
42-
internal const string BridgePatterOptionMultipleImplementations = "25.2";
43-
internal const string BridgePatterOptionMarker = "25.3";
44+
internal const string MediatorPatternOption = "25";
45+
internal const string ObserverPatternOption = "26.1";
46+
internal const string ObserverPatternOptionWithType = "26.2";
4447

4548
internal const string FactoryOption = "31";
4649
internal const string AbstractFactoryOption = "32";
@@ -79,17 +82,26 @@ internal static class PatternOptions
7982
new PatternExampleMap("Flyweight Pattern >> Drawing shapes", new FlyweightPatternExample())
8083
},
8184
{
82-
MediatorPatternOption,
83-
new PatternExampleMap("Flyweight Pattern >> Drawing shapes", new MediatorPatternExample())
85+
BridgePatterOptionSingleImplementations,
86+
new PatternExampleMap("Bridge Pattern >> With Single Implementation",
87+
new BridgePatternExampleSingleImplementations())
8488
},
8589
{
86-
ObserverPatternOption,
87-
new PatternExampleMap("Observer Pattern >> News Publisher", new ObserverPatternExample())
90+
BridgePatterOptionMultipleImplementations,
91+
new PatternExampleMap("Bridge Pattern >> With Multiple Implementations",
92+
new BridgePatternExampleMultipleImplementations())
8893
},
8994
{
90-
ObserverPatternOptionWithType,
91-
new PatternExampleMap("Observer Pattern >> News Publisher with type",
92-
new ObserverPatternExampleWithCategory())
95+
BridgePatterOptionMarker,
96+
new PatternExampleMap("Bridge Pattern >> With Marker", new BridgePatternExampleWithMarker())
97+
},
98+
{
99+
CompositePatternOptionWithInput,
100+
new PatternExampleMap("CompositePattern >> With Input", new CompositePatternExampleWithInput())
101+
},
102+
{
103+
CompositePatternOptionWithoutInput,
104+
new PatternExampleMap("CompositePattern >> Without Input", new CompositePatternExampleWithoutInput())
93105
},
94106

95107
// Behavioral Patterns
@@ -133,18 +145,17 @@ internal static class PatternOptions
133145
new PatternExampleMap("Strategy Pattern >> Payment Example", new StrategyPatternPaymentExample())
134146
},
135147
{
136-
BridgePatterOptionSingleImplementations,
137-
new PatternExampleMap("Bridge Pattern >> With Single Implementation",
138-
new BridgePatternExampleSingleImplementations())
148+
MediatorPatternOption,
149+
new PatternExampleMap("Flyweight Pattern >> Drawing shapes", new MediatorPatternExample())
139150
},
140151
{
141-
BridgePatterOptionMultipleImplementations,
142-
new PatternExampleMap("Bridge Pattern >> With Multiple Implementations",
143-
new BridgePatternExampleMultipleImplementations())
152+
ObserverPatternOption,
153+
new PatternExampleMap("Observer Pattern >> News Publisher", new ObserverPatternExample())
144154
},
145155
{
146-
BridgePatterOptionMarker,
147-
new PatternExampleMap("Bridge Pattern >> With Marker", new BridgePatternExampleWithMarker())
156+
ObserverPatternOptionWithType,
157+
new PatternExampleMap("Observer Pattern >> News Publisher with type",
158+
new ObserverPatternExampleWithCategory())
148159
},
149160

150161
// Creational Patterns
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace GofConsoleApp.Examples.Structural.CompositePattern;
2+
3+
internal class CompositePatternExampleWithInput : BaseExample
4+
{
5+
protected override bool Execute()
6+
{
7+
// Accessories
8+
IDeliveryItem bag = new DeliveryProduct("Bag", Logger);
9+
IDeliveryItem shoes = new DeliveryProduct("Shoes", Logger);
10+
var accessories = new DeliveryBox(50, 40, 40, Logger);
11+
accessories.Add(bag, shoes);
12+
13+
// Clothes
14+
IDeliveryItem shirt = new DeliveryProduct("Shirt", Logger);
15+
IDeliveryItem pants = new DeliveryProduct("Pants", Logger);
16+
var clothes = new DeliveryBox(40, 30, 20, Logger);
17+
clothes.Add(shirt, pants);
18+
19+
// Delivery
20+
var delivery = new DeliveryBox(100, 80, 60, Logger);
21+
delivery.Add(accessories, clothes);
22+
delivery.Process("Berlin");
23+
24+
return true;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace GofConsoleApp.Examples.Structural.CompositePattern;
2+
3+
internal class CompositePatternExampleWithoutInput : BaseExample
4+
{
5+
protected override bool Execute()
6+
{
7+
// Installation team
8+
IResource employeeJack = new Employee("Jack", Logger);
9+
IResource employeeJill = new Employee("Jill", Logger);
10+
var installers = new Team("Product Installation", Logger);
11+
installers.Add(employeeJack, employeeJill);
12+
13+
// Specialist team
14+
IResource employeeJohn = new Employee("John", Logger);
15+
IResource employeeJane = new Employee("Jane", Logger);
16+
var specialists = new Team("Product Specialist", Logger);
17+
specialists.Add(employeeJohn, employeeJane);
18+
19+
// Support team
20+
var support = new Team("Product Support", Logger);
21+
support.Add(specialists, installers);
22+
support.Process();
23+
24+
return true;
25+
}
26+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Core.Console.Interfaces;
2+
using GofPatterns.Structural.CompositePattern;
3+
4+
namespace GofConsoleApp.Examples.Structural.CompositePattern;
5+
6+
internal interface IDeliveryItem : IComponent<string> { }
7+
8+
internal class DeliveryProduct : ILeaf<string>, IDeliveryItem
9+
{
10+
private readonly string name;
11+
12+
public DeliveryProduct(string name, IConsoleLogger logger)
13+
{
14+
this.name = name;
15+
logger.Log($"Packaging: {name}.");
16+
}
17+
18+
public void Process(string city) => Console.WriteLine($"Sending '{name}' to {city}.");
19+
}
20+
21+
internal class DeliveryBox : Composite<string>, IDeliveryItem
22+
{
23+
private readonly int len;
24+
private readonly int width;
25+
private readonly int height;
26+
private readonly IConsoleLogger logger;
27+
28+
public DeliveryBox(int len, int width, int height, IConsoleLogger logger)
29+
{
30+
this.len = len;
31+
this.width = width;
32+
this.height = height;
33+
this.logger = logger;
34+
Console.WriteLine($"Packaging Box: {len}x{width}x{height} cms.");
35+
}
36+
37+
public override void Process(string city)
38+
{
39+
logger.Log("----------------------------------------");
40+
logger.Log($"Sending box '{len}x{width}x{height} cms' to {city}.");
41+
base.Process(city);
42+
}
43+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Core.Console.Interfaces;
2+
using GofPatterns.Structural.CompositePattern;
3+
4+
namespace GofConsoleApp.Examples.Structural.CompositePattern;
5+
6+
internal interface IResource : IComponent { }
7+
8+
internal class Employee : ILeaf, IResource
9+
{
10+
private readonly string name;
11+
private readonly IConsoleLogger logger;
12+
13+
public Employee(string name, IConsoleLogger logger)
14+
{
15+
this.name = name;
16+
this.logger = logger;
17+
}
18+
19+
public void Process()
20+
{
21+
logger.Log($" - Employee working: {name}.");
22+
}
23+
}
24+
25+
internal class Team : Composite, IResource
26+
{
27+
private readonly string name;
28+
private readonly IConsoleLogger logger;
29+
30+
public Team(string name, IConsoleLogger logger)
31+
{
32+
this.name = name;
33+
this.logger = logger;
34+
}
35+
36+
public override void Process()
37+
{
38+
logger.Log("----------------------------------------");
39+
logger.Log($"Team: {name}.");
40+
base.Process();
41+
}
42+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace GofPatterns.Core.Extensions;
2+
3+
internal static class CollectionExtensions
4+
{
5+
internal static List<T> Build<T>(this List<T> list, T item, params T[] items)
6+
{
7+
list.Add(item);
8+
list.AddRange(items);
9+
return list;
10+
}
11+
}

GofPatterns/GofPatterns.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1111
<PackageId>GofPatterns</PackageId>
1212
<Title>Gof Patterns</Title>
13-
<Version>1.3.3</Version>
13+
<Version>1.3.4</Version>
1414
<Authors>viveksacademia</Authors>
1515
<Company>vivopensource</Company>
1616
<Description>Desgin Patterns for C# (Gang of Four)</Description>
1717
<PackageTags>
1818
patterns; design-patterns; gang-of-four; Gof;
1919
behavioral-patterns; structural-patterns; creational-patterns;
2020
chain-of-responsibility-pattern; cor; command-pattern; state-pattern; strategy-pattern; mediator-pattern; observer-pattern;
21-
decorator-pattern; proxy-pattern; adapter-pattern; flyweight-pattern; bridge-pattern;
21+
decorator-pattern; proxy-pattern; adapter-pattern; flyweight-pattern; bridge-pattern; composite-pattern;
2222
factory-pattern; abstract-factory-pattern; builder-pattern
2323
</PackageTags>
2424
<PackageLicenseFile>LICENSE</PackageLicenseFile>

GofPatterns/Structural/BridgePattern/Implementations/BridgeAbstractionsImpl.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace GofPatterns.Structural.BridgePattern.Implementations;
1+
using GofPatterns.Core.Extensions;
2+
3+
namespace GofPatterns.Structural.BridgePattern.Implementations;
24

35
/// <summary>
46
/// Bridge abstraction interface with multiple implementations.
@@ -11,8 +13,7 @@ public class BridgeAbstractionsImpl<TImplementation> : IBridgeAbstractionsImpl<T
1113

1214
public void Add(TImplementation implementation, params TImplementation[] implementations)
1315
{
14-
impls.Add(implementation);
15-
impls.AddRange(implementations);
16+
impls.Build(implementation, implementations);
1617
}
1718

1819
public void Execute()
@@ -35,8 +36,7 @@ public class BridgeAbstractionsImpl<TImplementation, TInput> : IBridgeAbstractio
3536

3637
public void Add(TImplementation implementation, params TImplementation[] implementations)
3738
{
38-
impls.Add(implementation);
39-
impls.AddRange(implementations);
39+
impls.Build(implementation, implementations);
4040
}
4141

4242
public void Execute(TInput input)

0 commit comments

Comments
 (0)