Update description on ChainOfResponssibility and Command pattern
This commit is contained in:
@@ -19,9 +19,11 @@ namespace BehavioralPatterns
|
|||||||
//This is usefull when you have a request and you don't know who should process it
|
//This is usefull when you have a request and you don't know who should process it
|
||||||
ChainOfResponsibillityExamples.Run();
|
ChainOfResponsibillityExamples.Run();
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
CommandPatternExamples.Run();
|
CommandPatternExamples.Run();
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
IteratorPatternExamples.Run();
|
IteratorPatternExamples.Run();
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|||||||
@@ -80,9 +80,10 @@ namespace ChainOfResponssibility.PurchaseExample
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string GetDescriptionOfClass()
|
public string GetDescriptionOfExample()
|
||||||
{
|
{
|
||||||
return @"CheckAuthority allows an employee to spend money
|
return @"Description of example:
|
||||||
|
CheckAuthority allows an employee to spend money
|
||||||
if(manager can approve it) manager will process the request
|
if(manager can approve it) manager will process the request
|
||||||
if (director can approve it) director will process the request
|
if (director can approve it) director will process the request
|
||||||
if (vice president can approve it) vice president will process the request
|
if (vice president can approve it) vice president will process the request
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace ChainOfResponssibility
|
|||||||
|
|
||||||
CheckAuthority moneySpender = new CheckAuthority();
|
CheckAuthority moneySpender = new CheckAuthority();
|
||||||
|
|
||||||
Console.WriteLine(moneySpender.GetDescriptionOfClass());
|
Console.WriteLine(moneySpender.GetDescriptionOfExample());
|
||||||
GoToNextStep();
|
GoToNextStep();
|
||||||
|
|
||||||
moneySpender.PrintHowMuchEachCanSpend();
|
moneySpender.PrintHowMuchEachCanSpend();
|
||||||
@@ -26,7 +26,7 @@ namespace ChainOfResponssibility
|
|||||||
|
|
||||||
TransferFilesManager transferFilesManager = new TransferFilesManager();
|
TransferFilesManager transferFilesManager = new TransferFilesManager();
|
||||||
|
|
||||||
Console.WriteLine(transferFilesManager.GetDescriptionOfClass());
|
Console.WriteLine(transferFilesManager.GetDescriptionOfExample());
|
||||||
GoToNextStep();
|
GoToNextStep();
|
||||||
transferFilesManager.TransferFiles();
|
transferFilesManager.TransferFiles();
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ namespace ChainOfResponssibility
|
|||||||
|
|
||||||
public static string GetPatternDescription()
|
public static string GetPatternDescription()
|
||||||
{
|
{
|
||||||
return @"
|
return @"Pattern description:
|
||||||
Decouples sender and receiver (as a sender you don't know who will handle the request/ as a receiver you don't know who the sender is necessary)
|
Decouples sender and receiver (as a sender you don't know who will handle the request/ as a receiver you don't know who the sender is necessary)
|
||||||
Hierarchical in nature
|
Hierarchical in nature
|
||||||
When using the Chain of Responsibility is more effective:
|
When using the Chain of Responsibility is more effective:
|
||||||
@@ -67,7 +67,7 @@ Examples in real life:
|
|||||||
|
|
||||||
public static string GetPitfalls()
|
public static string GetPitfalls()
|
||||||
{
|
{
|
||||||
return @"
|
return @"Pitfalls:
|
||||||
Handling/Handler guarantee - you won't be sure that someone can process the request
|
Handling/Handler guarantee - you won't be sure that someone can process the request
|
||||||
Runtime configuration risk - the order matters/and it might be that the chain is not configured correctly
|
Runtime configuration risk - the order matters/and it might be that the chain is not configured correctly
|
||||||
Chain length/performance issues - in theory you could see a chain that is too big, and it would be a bottleneck in performance";
|
Chain length/performance issues - in theory you could see a chain that is too big, and it would be a bottleneck in performance";
|
||||||
|
|||||||
@@ -42,9 +42,10 @@ namespace ChainOfResponssibility.TransferFileExample
|
|||||||
return "exit".Equals(input, StringComparison.OrdinalIgnoreCase);
|
return "exit".Equals(input, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetDescriptionOfClass()
|
public string GetDescriptionOfExample()
|
||||||
{
|
{
|
||||||
return @"TransferFilesManager will try to transfer the file to the destination by trying FTP, SFTP, Http, and simple file copy";
|
return @"Description of example:
|
||||||
|
TransferFilesManager will try to transfer the file to the destination by trying FTP, SFTP, Http, and simple file copy";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
using ChainOfResponssibility.Validators.UserEntities.UserMenu;
|
using ChainOfResponssibility.Validators.UserEntities.UserMenu;
|
||||||
using ChainOfResponssibility.Validators.UserEntities.Validators;
|
using ChainOfResponssibility.Validators.UserEntities.Validators;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ChainOfResponssibility.Validators.UserEntities
|
namespace ChainOfResponssibility.Validators.UserEntities
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace CommandPattern
|
|||||||
public static void Run()
|
public static void Run()
|
||||||
{
|
{
|
||||||
Console.WriteLine(GetPatternDescription());
|
Console.WriteLine(GetPatternDescription());
|
||||||
|
Console.WriteLine(GetActors());
|
||||||
GoToNextStep();
|
GoToNextStep();
|
||||||
|
|
||||||
StockExampleRunner stockExampleRunner = new StockExampleRunner();
|
StockExampleRunner stockExampleRunner = new StockExampleRunner();
|
||||||
@@ -21,6 +22,13 @@ namespace CommandPattern
|
|||||||
stockExampleRunner.RunWithMarketClosed();
|
stockExampleRunner.RunWithMarketClosed();
|
||||||
stockExampleRunner.RunWithMarketOpened();
|
stockExampleRunner.RunWithMarketOpened();
|
||||||
stockExampleRunner.RunWithMarketOpeningInTwoSeconds();
|
stockExampleRunner.RunWithMarketOpeningInTwoSeconds();
|
||||||
|
|
||||||
|
GoToNextStep();
|
||||||
|
Console.WriteLine(GetPitfalls());
|
||||||
|
Console.WriteLine(CommandWithUndoDescription());
|
||||||
|
|
||||||
|
GoToNextStep();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void GoToNextStep()
|
private static void GoToNextStep()
|
||||||
@@ -31,7 +39,7 @@ namespace CommandPattern
|
|||||||
|
|
||||||
public static string GetPatternDescription()
|
public static string GetPatternDescription()
|
||||||
{
|
{
|
||||||
return @"
|
return @"Patttern description:
|
||||||
command pattern is a behavioral design pattern in which an object is used to encapsulate
|
command pattern is a behavioral design pattern in which an object is used to encapsulate
|
||||||
all information needed to perform an action or trigger an event at a later time
|
all information needed to perform an action or trigger an event at a later time
|
||||||
Uses:
|
Uses:
|
||||||
@@ -42,5 +50,31 @@ sequence of actions simply by keeping a list of the command objects as they are
|
|||||||
4. Parallel processing
|
4. Parallel processing
|
||||||
5. Transactional behavior ";
|
5. Transactional behavior ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetActors()
|
||||||
|
{
|
||||||
|
return @"Actors:
|
||||||
|
Client: class that is making use of the command pattern, the one that uses the invoker, makes instance of commands, and passes the commands to the invoker
|
||||||
|
Invoker: Invokes the command (calls execute on the command)
|
||||||
|
Receiver: the class that the command is using as an implementation
|
||||||
|
Command interface: the interface for the commmands
|
||||||
|
Concrete Command: Concrete implementations of the command interface";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetPitfalls()
|
||||||
|
{
|
||||||
|
return @"Pitfalls:
|
||||||
|
Dependence on other patterns
|
||||||
|
Multiple commands having the same implementation";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string CommandWithUndoDescription()
|
||||||
|
{
|
||||||
|
return @"Undo functionality:
|
||||||
|
While it is true that it would be easy using Command pattern to implement at the invoker
|
||||||
|
level undo/redo functionality, in practice this only works for simple examples,
|
||||||
|
where all entities are at the same level. More details about undo can be seen at:
|
||||||
|
http://gernotklingler.com/blog/implementing-undoredo-with-the-command-pattern/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace CommandPattern.StocksExample
|
|||||||
|
|
||||||
public string GetDescriptionOfExample()
|
public string GetDescriptionOfExample()
|
||||||
{
|
{
|
||||||
return @"
|
return @"Example description:
|
||||||
Buy or sell a stock on the market.
|
Buy or sell a stock on the market.
|
||||||
If the market is closed save the orders for when the market opens again.
|
If the market is closed save the orders for when the market opens again.
|
||||||
When the market opens place all the orders.";
|
When the market opens place all the orders.";
|
||||||
|
|||||||
Reference in New Issue
Block a user