Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 2 additions & 40 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ name: Pull Request

on:
pull_request:
branches:
- 'dev'

jobs:

test-linux:
test-pr:

runs-on: ubuntu-latest

Expand Down Expand Up @@ -56,40 +54,4 @@ jobs:
path: code-coverage-results.md

- name: Write to Job Summary
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY

test-windows:

runs-on: windows-latest

env:
Solution_Name: GofPatterns.sln
Test_Project_Path: GofPatternsTests\GofPatternsTests.csproj

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x

- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.0.2

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build

- name: Test
run: dotnet test

- name: Restore the application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
env:
Configuration: Debug
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ jobs:
run: dotnet pack GofPatterns/GofPatterns.csproj -c Release --no-restore --no-build --include-symbols -p:SymbolPackageFormat=snupkg -o .

# Push to NuGet
- name: Deploy
- name: Publish
run: dotnet nuget push *.nupkg --skip-duplicate -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}}
53 changes: 32 additions & 21 deletions GofConsoleApp/Examples/ExecutionHelpers/PatternOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using GofConsoleApp.Examples.Creational.FactoryPattern;
using GofConsoleApp.Examples.Structural.AdapterPattern;
using GofConsoleApp.Examples.Structural.BridgePattern;
using GofConsoleApp.Examples.Structural.CompositePattern;
using GofConsoleApp.Examples.Structural.DecoratorPattern;
using GofConsoleApp.Examples.Structural.FlyweightPattern;
using GofConsoleApp.Examples.Structural.ProxyPattern;
Expand All @@ -25,9 +26,11 @@ internal static class PatternOptions
internal const string ProxyPatternOptionBoundedInputOutput = "12.3";
internal const string AdapterPatternOption = "13";
internal const string FlyweightPatternOption = "14";
internal const string MediatorPatternOption = "15";
internal const string ObserverPatternOption = "16.1";
internal const string ObserverPatternOptionWithType = "16.2";
internal const string BridgePatterOptionSingleImplementations = "15";
internal const string BridgePatterOptionMultipleImplementations = "15.2";
internal const string BridgePatterOptionMarker = "15.3";
internal const string CompositePatternOptionWithInput = "16.1";
internal const string CompositePatternOptionWithoutInput = "16.2";

internal const string ChainOfResponsibilityPatternOption = "21";
internal const string ChainOfResponsibilityPatternOption2 = "21.2";
Expand All @@ -38,9 +41,9 @@ internal static class PatternOptions
internal const string StatePatternOptionDriveExample = "23.2";
internal const string StrategyPatternOptionSender = "24";
internal const string StrategyPatternOptionPayment = "24.2";
internal const string BridgePatterOptionSingleImplementations = "25";
internal const string BridgePatterOptionMultipleImplementations = "25.2";
internal const string BridgePatterOptionMarker = "25.3";
internal const string MediatorPatternOption = "25";
internal const string ObserverPatternOption = "26.1";
internal const string ObserverPatternOptionWithType = "26.2";

internal const string FactoryOption = "31";
internal const string AbstractFactoryOption = "32";
Expand Down Expand Up @@ -79,17 +82,26 @@ internal static class PatternOptions
new PatternExampleMap("Flyweight Pattern >> Drawing shapes", new FlyweightPatternExample())
},
{
MediatorPatternOption,
new PatternExampleMap("Flyweight Pattern >> Drawing shapes", new MediatorPatternExample())
BridgePatterOptionSingleImplementations,
new PatternExampleMap("Bridge Pattern >> With Single Implementation",
new BridgePatternExampleSingleImplementations())
},
{
ObserverPatternOption,
new PatternExampleMap("Observer Pattern >> News Publisher", new ObserverPatternExample())
BridgePatterOptionMultipleImplementations,
new PatternExampleMap("Bridge Pattern >> With Multiple Implementations",
new BridgePatternExampleMultipleImplementations())
},
{
ObserverPatternOptionWithType,
new PatternExampleMap("Observer Pattern >> News Publisher with type",
new ObserverPatternExampleWithCategory())
BridgePatterOptionMarker,
new PatternExampleMap("Bridge Pattern >> With Marker", new BridgePatternExampleWithMarker())
},
{
CompositePatternOptionWithInput,
new PatternExampleMap("CompositePattern >> With Input", new CompositePatternExampleWithInput())
},
{
CompositePatternOptionWithoutInput,
new PatternExampleMap("CompositePattern >> Without Input", new CompositePatternExampleWithoutInput())
},

// Behavioral Patterns
Expand Down Expand Up @@ -133,18 +145,17 @@ internal static class PatternOptions
new PatternExampleMap("Strategy Pattern >> Payment Example", new StrategyPatternPaymentExample())
},
{
BridgePatterOptionSingleImplementations,
new PatternExampleMap("Bridge Pattern >> With Single Implementation",
new BridgePatternExampleSingleImplementations())
MediatorPatternOption,
new PatternExampleMap("Flyweight Pattern >> Drawing shapes", new MediatorPatternExample())
},
{
BridgePatterOptionMultipleImplementations,
new PatternExampleMap("Bridge Pattern >> With Multiple Implementations",
new BridgePatternExampleMultipleImplementations())
ObserverPatternOption,
new PatternExampleMap("Observer Pattern >> News Publisher", new ObserverPatternExample())
},
{
BridgePatterOptionMarker,
new PatternExampleMap("Bridge Pattern >> With Marker", new BridgePatternExampleWithMarker())
ObserverPatternOptionWithType,
new PatternExampleMap("Observer Pattern >> News Publisher with type",
new ObserverPatternExampleWithCategory())
},

// Creational Patterns
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace GofConsoleApp.Examples.Structural.CompositePattern;

internal class CompositePatternExampleWithInput : BaseExample
{
protected override bool Execute()
{
// Accessories
IDeliveryItem bag = new DeliveryProduct("Bag", Logger);
IDeliveryItem shoes = new DeliveryProduct("Shoes", Logger);
var accessories = new DeliveryBox(50, 40, 40, Logger);
accessories.Add(bag, shoes);

// Clothes
IDeliveryItem shirt = new DeliveryProduct("Shirt", Logger);
IDeliveryItem pants = new DeliveryProduct("Pants", Logger);
var clothes = new DeliveryBox(40, 30, 20, Logger);
clothes.Add(shirt, pants);

// Delivery
var delivery = new DeliveryBox(100, 80, 60, Logger);
delivery.Add(accessories, clothes);
delivery.Process("Berlin");

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace GofConsoleApp.Examples.Structural.CompositePattern;

internal class CompositePatternExampleWithoutInput : BaseExample
{
protected override bool Execute()
{
// Installation team
IResource employeeJack = new Employee("Jack", Logger);
IResource employeeJill = new Employee("Jill", Logger);
var installers = new Team("Product Installation", Logger);
installers.Add(employeeJack, employeeJill);

// Specialist team
IResource employeeJohn = new Employee("John", Logger);
IResource employeeJane = new Employee("Jane", Logger);
var specialists = new Team("Product Specialist", Logger);
specialists.Add(employeeJohn, employeeJane);

// Support team
var support = new Team("Product Support", Logger);
support.Add(specialists, installers);
support.Process();

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Core.Console.Interfaces;
using GofPatterns.Structural.CompositePattern;

namespace GofConsoleApp.Examples.Structural.CompositePattern;

internal interface IDeliveryItem : IComponent<string> { }

internal class DeliveryProduct : ILeaf<string>, IDeliveryItem
{
private readonly string name;

public DeliveryProduct(string name, IConsoleLogger logger)
{
this.name = name;
logger.Log($"Packaging: {name}.");
}

public void Process(string city) => Console.WriteLine($"Sending '{name}' to {city}.");
}

internal class DeliveryBox : Composite<string>, IDeliveryItem
{
private readonly int len;
private readonly int width;
private readonly int height;
private readonly IConsoleLogger logger;

public DeliveryBox(int len, int width, int height, IConsoleLogger logger)
{
this.len = len;
this.width = width;
this.height = height;
this.logger = logger;
Console.WriteLine($"Packaging Box: {len}x{width}x{height} cms.");
}

public override void Process(string city)
{
logger.Log("----------------------------------------");
logger.Log($"Sending box '{len}x{width}x{height} cms' to {city}.");
base.Process(city);
}
}
42 changes: 42 additions & 0 deletions GofConsoleApp/Examples/Structural/CompositePattern/IResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Core.Console.Interfaces;
using GofPatterns.Structural.CompositePattern;

namespace GofConsoleApp.Examples.Structural.CompositePattern;

internal interface IResource : IComponent { }

internal class Employee : ILeaf, IResource
{
private readonly string name;
private readonly IConsoleLogger logger;

public Employee(string name, IConsoleLogger logger)
{
this.name = name;
this.logger = logger;
}

public void Process()
{
logger.Log($" - Employee working: {name}.");
}
}

internal class Team : Composite, IResource
{
private readonly string name;
private readonly IConsoleLogger logger;

public Team(string name, IConsoleLogger logger)
{
this.name = name;
this.logger = logger;
}

public override void Process()
{
logger.Log("----------------------------------------");
logger.Log($"Team: {name}.");
base.Process();
}
}
11 changes: 11 additions & 0 deletions GofPatterns/Core/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GofPatterns.Core.Extensions;

internal static class CollectionExtensions
{
internal static List<T> Build<T>(this List<T> list, T item, params T[] items)
{
list.Add(item);
list.AddRange(items);
return list;
}
}
4 changes: 2 additions & 2 deletions GofPatterns/GofPatterns.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>GofPatterns</PackageId>
<Title>Gof Patterns</Title>
<Version>1.3.3</Version>
<Version>1.3.4</Version>
<Authors>viveksacademia</Authors>
<Company>vivopensource</Company>
<Description>Desgin Patterns for C# (Gang of Four)</Description>
<PackageTags>
patterns; design-patterns; gang-of-four; Gof;
behavioral-patterns; structural-patterns; creational-patterns;
chain-of-responsibility-pattern; cor; command-pattern; state-pattern; strategy-pattern; mediator-pattern; observer-pattern;
decorator-pattern; proxy-pattern; adapter-pattern; flyweight-pattern; bridge-pattern;
decorator-pattern; proxy-pattern; adapter-pattern; flyweight-pattern; bridge-pattern; composite-pattern;
factory-pattern; abstract-factory-pattern; builder-pattern
</PackageTags>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GofPatterns.Structural.BridgePattern.Implementations;
using GofPatterns.Core.Extensions;

namespace GofPatterns.Structural.BridgePattern.Implementations;

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

public void Add(TImplementation implementation, params TImplementation[] implementations)
{
impls.Add(implementation);
impls.AddRange(implementations);
impls.Build(implementation, implementations);
}

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

public void Add(TImplementation implementation, params TImplementation[] implementations)
{
impls.Add(implementation);
impls.AddRange(implementations);
impls.Build(implementation, implementations);
}

public void Execute(TInput input)
Expand Down
Loading