View useCORpattern.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ClaimApprover junior = new Manager(); | |
ClaimApprover sukhpinder = new Manager(); | |
ClaimApprover singh = new SeniorManager(); | |
junior.SetHierarchy(sukhpinder); | |
sukhpinder.SetHierarchy(singh); | |
Claim c1 = new Claim() { amount = 999, Id = 1001 }; | |
Claim c2 = new Claim() { amount = 10001, Id = 1002 }; | |
junior.ApproveRequest(c1); |
View seniormanager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SeniorManager : ClaimApprover | |
{ | |
public override void ApproveRequest(Claim claim) | |
{ | |
if (claim.amount > 1000 && claim.amount <= 10000) | |
{ | |
System.Console.WriteLine($"Claim reference {claim.Id} with amount {claim.amount} is approved by Senior Manager"); | |
} | |
else | |
{ |
View manager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Manager : ClaimApprover | |
{ | |
public override void ApproveRequest(Claim claim) | |
{ | |
if (claim.amount >= 100 && claim.amount <= 1000) | |
{ | |
System.Console.WriteLine($"Claim reference {claim.Id} with amount {claim.amount} is approved by Manager"); | |
} | |
else if (claimApprover != null) | |
{ |
View junior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Junior : ClaimApprover | |
{ | |
public override void ApproveRequest(Claim claim) | |
{ | |
System.Console.WriteLine("Cannot approve"); | |
} | |
} |
View corabstract.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class ClaimApprover | |
{ | |
protected ClaimApprover claimApprover; | |
public void SetHierarchy(ClaimApprover claimApprover) | |
{ | |
this.claimApprover = claimApprover; | |
} | |
public abstract void ApproveRequest(Claim claim); | |
} |
View mediator-main.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
Chatroom chatroom = new Chatroom(); | |
User Jennifer = new UserPersona(Username.Jennifer.ToString()); | |
User Ashley = new UserPersona(Username.Ashley.ToString()); | |
User David = new UserPersona(Username.David.ToString()); | |
User Scott = new UserPersona(Username.Scott.ToString()); | |
chatroom.Register(Jennifer); | |
chatroom.Register(Ashley); |
View user-persona.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserPersona : User | |
{ | |
public UserPersona(string name) : base(name) { } | |
public override void DM(string from, string message) => base.DM(from, message); | |
} |
View user-mediator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User | |
{ | |
private Chatroom _chatroom; | |
private string _name; | |
public User(string name) => this._name = name; | |
public string Name => _name; | |
public Chatroom Chatroom | |
{ |
View abstract-clatroom.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Chatroom : AChatroom | |
{ | |
private Dictionary<string, User> _users = new Dictionary<string, User>(); | |
public override void Post(string fromUser, string toUser, string msg) | |
{ | |
User participant = _users[toUser]; | |
if (participant != null) | |
{ | |
participant.DM(fromUser, msg); |
View chatroom.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class AChatroom | |
{ | |
public abstract void Register(User user); | |
public abstract void Post(string fromUser, string toUser, string msg); | |
} |
NewerOlder