public void Print(Client client, IFormatter formatter) { var result = formatter.Format(client); Console.WriteLine(result); // class Print does nto suit format strings, so to keep OOP principles // we create StringBasicFormat - a class only to format string when we need it }
static void Main(string[] args) { var client = new Client(); client.Name = "Pesho"; client.Age = 22; var printer = new Printer(); printer.Print(client,new StringBasicFormat()); }
public string Format(Client client) { return string.Format("\"Name\" {0} ------ \"Age\" {1}", client.Name, client.Age); }