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
10 changes: 7 additions & 3 deletions .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ jobs:

strategy:
matrix:
configuration: [Release]
configuration: [Debug]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Solution_Name: GofPatterns.sln # Replace with your solution name, i.e. MyWpfApp.sln.
Test_Project_Path: GofPatternsTests\GofPatternsTests.csproj # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
Solution_Name: GofPatterns.sln
Test_Project_Path: GofPatternsTests\GofPatternsTests.csproj


steps:
Expand All @@ -75,6 +75,10 @@ jobs:
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.0.2

# Execute build
- name: Execute build
run: dotnet build

# Execute all unit tests in the solution
- name: Execute unit tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
using Core.Console.Interfaces;
using GofPatterns.Behavioral.CommandPattern;
using GofPatterns.Behavioral.CommandPattern.Interfaces.Invokers;

namespace GofConsoleApp.Examples.Behavioral.CommandPattern.OnlineShopComponents;

internal class OnlineShopAsInvoker
{
private readonly IConsoleLogger logger;
private readonly ICommandUndoInvoker<TransactionCommand, ProductRequest> commandUndoInvoker;
private readonly ICommandInvokerUndo<TransactionCommand, ProductRequest> commandInvokerUndo;

public OnlineShopAsInvoker(IConsoleLogger logger)
{
this.logger = logger;
commandUndoInvoker = new CommandUndoInvoker<TransactionCommand, ProductRequest>();
commandInvokerUndo = new CommandInvokerUndo<TransactionCommand, ProductRequest>();
}

public void PurchaseProduct(string productName)
{
var productRequest = new ProductRequest(logger, productName); // Request
var transactionCommand = new TransactionCommand(productRequest); // Command
commandUndoInvoker.AddCommand(transactionCommand, false);
commandInvokerUndo.AddCommand(transactionCommand, false);
}

public void ReturnProduct(string productName)
{
var productRequest = new ProductRequest(logger, productName); // Request
var transactionCommand = new TransactionCommand(productRequest); // Command
commandUndoInvoker.AddCommand(transactionCommand, true);
commandInvokerUndo.AddCommand(transactionCommand, true);
}

public int CheckOut() => commandUndoInvoker.ExecuteCommands();
public int CheckOut() => commandInvokerUndo.ExecuteCommands();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Core.Console.Interfaces;
using GofPatterns.Behavioral.CommandPattern.Interfaces;
using GofPatterns.Behavioral.CommandPattern;

namespace GofConsoleApp.Examples.Behavioral.CommandPattern.OnlineShopComponents;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GofConsoleApp.Examples.Behavioral.CommandPattern.OnlineShopComponents;

internal class TransactionCommand : AbstractCommandUndo<ProductRequest>
internal class TransactionCommand : CommandUndo<ProductRequest>
{
public TransactionCommand(ProductRequest productRequest)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace GofConsoleApp.Examples.Behavioral.CommandPattern.RestaurantComponents.Commands;

internal class DeliverFoodCommand : AbstractCommand<IFoodRequest>, IFoodCommand
internal class DeliverFoodCommand : Command<IFoodRequest>, IFoodCommand
{
public override void Execute()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GofConsoleApp.Examples.Behavioral.CommandPattern.RestaurantComponents.Requests;
using GofPatterns.Behavioral.CommandPattern.Interfaces.Commands;
using GofPatterns.Behavioral.CommandPattern;

namespace GofConsoleApp.Examples.Behavioral.CommandPattern.RestaurantComponents.Commands;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace GofConsoleApp.Examples.Behavioral.CommandPattern.RestaurantComponents.Commands;

internal class ServeFoodCommand : AbstractCommand<IFoodRequest>, IFoodCommand
internal class ServeFoodCommand : Command<IFoodRequest>, IFoodCommand
{
public override void Execute()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Behavioral.CommandPattern.Interfaces;
using GofPatterns.Behavioral.CommandPattern;

namespace GofConsoleApp.Examples.Behavioral.CommandPattern.RestaurantComponents.Requests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Core.Console.Interfaces;
using GofPatterns.Behavioral.ObserverPattern.Interfaces;
using GofPatterns.Behavioral.ObserverPattern;

namespace GofConsoleApp.Examples.Behavioral.ObserverPattern.Components;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Core.Console.Interfaces;
using GofPatterns.Behavioral.ObserverPattern.Interfaces;
using GofPatterns.Behavioral.ObserverPattern;

namespace GofConsoleApp.Examples.Behavioral.ObserverPattern.Components;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Core.Extensions;
using GofConsoleApp.Examples.Behavioral.ObserverPattern.Components;
using GofPatterns.Behavioral.ObserverPattern;
using GofPatterns.Behavioral.ObserverPattern.Interfaces;

namespace GofConsoleApp.Examples.Behavioral.ObserverPattern;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Core.Extensions;
using GofConsoleApp.Examples.Behavioral.ObserverPattern.Components;
using GofPatterns.Behavioral.ObserverPattern;
using GofPatterns.Behavioral.ObserverPattern.Interfaces;

namespace GofConsoleApp.Examples.Behavioral.ObserverPattern;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Core.Console.Interfaces;
using GofPatterns.Behavioral.StatePattern;
using GofPatterns.Behavioral.StatePattern.Interfaces;

namespace GofConsoleApp.Examples.Behavioral.StatePattern.BulbComponents;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Behavioral.StatePattern.Interfaces;
using GofPatterns.Behavioral.StatePattern;
using static GofConsoleApp.Examples.Behavioral.StatePattern.BulbComponents.EnumStatePatternBulbExample;

namespace GofConsoleApp.Examples.Behavioral.StatePattern.BulbComponents.States;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Behavioral.StatePattern.Interfaces;
using GofPatterns.Behavioral.StatePattern;
using static GofConsoleApp.Examples.Behavioral.StatePattern.BulbComponents.EnumStatePatternBulbExample;

namespace GofConsoleApp.Examples.Behavioral.StatePattern.BulbComponents.States;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GofPatterns.Behavioral.StatePattern;
using GofPatterns.Behavioral.StatePattern.Interfaces;

namespace GofConsoleApp.Examples.Behavioral.StatePattern.DriveComponents;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Behavioral.StatePattern.Interfaces;
using GofPatterns.Behavioral.StatePattern;

namespace GofConsoleApp.Examples.Behavioral.StatePattern.DriveComponents.States;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GofConsoleApp.Examples.Behavioral.StatePattern.BulbComponents;
using GofConsoleApp.Examples.Behavioral.StatePattern.BulbComponents.States;
using GofPatterns.Behavioral.StatePattern.Interfaces;
using GofPatterns.Behavioral.StatePattern;
using static GofConsoleApp.Examples.Behavioral.StatePattern.BulbComponents.EnumStatePatternBulbExample;

namespace GofConsoleApp.Examples.Behavioral.StatePattern;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GofConsoleApp.Examples.Behavioral.StatePattern.DriveComponents;
using GofConsoleApp.Examples.Behavioral.StatePattern.DriveComponents.States;
using GofPatterns.Behavioral.StatePattern.Interfaces;
using GofPatterns.Behavioral.StatePattern;
using static GofConsoleApp.Examples.Behavioral.StatePattern.DriveComponents.EnumStatePatternDriveExample;

namespace GofConsoleApp.Examples.Behavioral.StatePattern;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Behavioral.StrategyPattern.Interfaces;
using GofPatterns.Behavioral.StrategyPattern;

namespace GofConsoleApp.Examples.Behavioral.StrategyPattern.PaymentComponents.Strategies;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Behavioral.StrategyPattern.Interfaces;
using GofPatterns.Behavioral.StrategyPattern;

namespace GofConsoleApp.Examples.Behavioral.StrategyPattern.SenderComponents.Strategies;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GofConsoleApp.Examples.Behavioral.StrategyPattern.PaymentComponents;
using GofConsoleApp.Examples.Behavioral.StrategyPattern.PaymentComponents.Strategies;
using GofPatterns.Behavioral.StrategyPattern.Interfaces;
using GofPatterns.Behavioral.StrategyPattern;
using static GofConsoleApp.Examples.Behavioral.StrategyPattern.PaymentComponents.EnumPaymentOptions;

namespace GofConsoleApp.Examples.Behavioral.StrategyPattern;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GofConsoleApp.Examples.Behavioral.StrategyPattern.SenderComponents;
using GofConsoleApp.Examples.Behavioral.StrategyPattern.SenderComponents.Strategies;
using GofPatterns.Behavioral.StrategyPattern.Interfaces;
using GofPatterns.Behavioral.StrategyPattern;
using static GofConsoleApp.Examples.Behavioral.StrategyPattern.SenderComponents.EnumSendingOptions;

namespace GofConsoleApp.Examples.Behavioral.StrategyPattern;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Core.Console.Interfaces;
using Core.Extensions;
using GofPatterns.Structural.FlyweightPattern.Interfaces;
using GofPatterns.Structural.FlyweightPattern;

namespace GofConsoleApp.Examples.Structural.FlyweightPattern.Components;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using GofConsoleApp.Examples.Structural.FlyweightPattern.Components;
using GofPatterns.Structural.FlyweightPattern;
using GofPatterns.Structural.FlyweightPattern.Interfaces;

namespace GofConsoleApp.Examples.Structural.FlyweightPattern;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Core.Console.Interfaces;
using GofPatterns.Structural.ProxyPattern.Interfaces;
using GofPatterns.Structural.ProxyPattern;

namespace GofConsoleApp.Examples.Structural.ProxyPattern.ConfigProviderComponents;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Structural.ProxyPattern.Interfaces;
using GofPatterns.Structural.ProxyPattern;

namespace GofConsoleApp.Examples.Structural.ProxyPattern.NewsChannelComponents;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Structural.ProxyPattern.Interfaces;
using GofPatterns.Structural.ProxyPattern;

namespace GofConsoleApp.Examples.Structural.ProxyPattern.NewsChannelComponents;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GofConsoleApp.Examples.Structural.ProxyPattern.UserInterfaceComponents;
using GofPatterns.Structural.ProxyPattern.Interfaces;
using GofPatterns.Structural.ProxyPattern;

namespace GofConsoleApp.Examples.Structural.ProxyPattern.UserInterfaceComponents;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GofPatterns.Structural.ProxyPattern.Interfaces;
using GofPatterns.Structural.ProxyPattern;

namespace GofConsoleApp.Examples.Structural.ProxyPattern.UserInterfaceComponents;

Expand Down
18 changes: 0 additions & 18 deletions GofPatterns/Behavioral/CommandPattern/AbstractCommandUndo.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using GofPatterns.Behavioral.CommandPattern.Interfaces;
using GofPatterns.Behavioral.CommandPattern.Interfaces.Commands;

namespace GofPatterns.Behavioral.CommandPattern;
namespace GofPatterns.Behavioral.CommandPattern;

/// <summary>
///
/// They can be directly used as a command, or inherited by other classes to make them command
/// </summary>
/// <typeparam name="TRequest"></typeparam>
public abstract class AbstractCommand<TRequest> : ICommand<TRequest> where TRequest : ICommandRequest
public abstract class Command<TRequest> : ICommand<TRequest> where TRequest : ICommandRequest
{
protected TRequest? Request;

Expand Down
6 changes: 1 addition & 5 deletions GofPatterns/Behavioral/CommandPattern/CommandInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using GofPatterns.Behavioral.CommandPattern.Interfaces;
using GofPatterns.Behavioral.CommandPattern.Interfaces.Commands;
using GofPatterns.Behavioral.CommandPattern.Interfaces.Invokers;

namespace GofPatterns.Behavioral.CommandPattern;
namespace GofPatterns.Behavioral.CommandPattern;

/// <summary>
/// Command invoker class for command pattern.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using GofPatterns.Behavioral.CommandPattern.Interfaces;
using GofPatterns.Behavioral.CommandPattern.Interfaces.Commands;
using GofPatterns.Behavioral.CommandPattern.Interfaces.Invokers;

namespace GofPatterns.Behavioral.CommandPattern;
namespace GofPatterns.Behavioral.CommandPattern;

// ReSharper disable once MemberCanBeProtected.Global

public class CommandUndoInvoker<TCommandUndo, TCommandRequest> : ICommandUndoInvoker<TCommandUndo, TCommandRequest>
public class CommandInvokerUndo<TCommandUndo, TCommandRequest> : ICommandInvokerUndo<TCommandUndo, TCommandRequest>
where TCommandUndo : ICommandUndo<TCommandRequest> where TCommandRequest : ICommandRequest
{
private IList<CommandWrapper> commandWrappers = new List<CommandWrapper>();
Expand Down
15 changes: 15 additions & 0 deletions GofPatterns/Behavioral/CommandPattern/CommandUndo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace GofPatterns.Behavioral.CommandPattern;

public abstract class CommandUndo<TRequest> : ICommandUndo<TRequest> where TRequest : ICommandRequest
{
protected TRequest? Request;

public void AddRequest(TRequest commandRequest)
{
Request = commandRequest;
}

public abstract void Execute();

public abstract void UnExecute();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GofPatterns.Behavioral.CommandPattern.Interfaces.Commands;
namespace GofPatterns.Behavioral.CommandPattern;

/// <summary>
/// Base Command interface for command pattern.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using GofPatterns.Behavioral.CommandPattern.Interfaces.Commands;

namespace GofPatterns.Behavioral.CommandPattern.Interfaces.Invokers;
namespace GofPatterns.Behavioral.CommandPattern;

/// <summary>
/// Base Command Invoker interface for command pattern.
Expand Down
8 changes: 8 additions & 0 deletions GofPatterns/Behavioral/CommandPattern/ICommandInvokerUndo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace GofPatterns.Behavioral.CommandPattern;

public interface ICommandInvokerUndo<in TCommand, TCommandRequest> : ICommandInvoker
where TCommand : ICommand<TCommandRequest>
where TCommandRequest : ICommandRequest
{
void AddCommand(TCommand command, bool undoFlag);
}
3 changes: 3 additions & 0 deletions GofPatterns/Behavioral/CommandPattern/ICommandRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace GofPatterns.Behavioral.CommandPattern;

public interface ICommandRequest { }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GofPatterns.Behavioral.CommandPattern.Interfaces.Commands;
namespace GofPatterns.Behavioral.CommandPattern;

public interface ICommandUndo<in TRequest> : ICommand<TRequest> where TRequest : ICommandRequest
{
Expand Down

This file was deleted.

This file was deleted.

Loading