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 | |
{ |
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); |
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); | |
} |
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 Program | |
{ | |
static void Main(string[] args) | |
{ | |
ITransactions adapter = new TransAdapter(); | |
foreach (var item in adapter.GetTransactions()) | |
{ | |
Console.WriteLine(item); | |
} | |
} |
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 TransAdapter : OrgYTransactions, ITransactions | |
{ | |
public List<string> GetTransactions() | |
{ | |
return GetTransactionsList(); | |
} | |
} |
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 OrgYTransactions | |
{ | |
public List<string> GetTransactionsList() | |
{ | |
List<string> transactions = new List<string>(); | |
transactions.Add("Debit 1"); | |
transactions.Add("Debit 2"); | |
transactions.Add("Debit 3"); | |
return transactions; | |
} |
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) | |
{ | |
var sedan = new ModelSedan(); | |
var suv = new ModelSuv(); | |
var factory = new CarFactory(); | |
var builders = new List<CarBuilder> { suv, sedan }; | |
foreach (var b in builders) | |
{ |
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 ModelSedan : CarBuilder | |
{ | |
public override void SetIsSUV() | |
{ | |
_car.IsSUV = false; | |
} | |
public override void SetName() | |
{ | |
_car.Name = "Maruti Sedan"; |
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 ModelSuv : CarBuilder | |
{ | |
public override void SetIsSUV() | |
{ | |
_car.IsSUV = true; | |
} | |
public override void SetName() | |
{ | |
_car.Name = "Maruti SUV"; |
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 CarFactory | |
{ | |
public Car Build(CarBuilder builder) | |
{ | |
builder.SetName(); | |
builder.SetSpeed(); | |
builder.SetIsSUV(); | |
return builder.GetCar(); | |
} | |
} |