The following information is from "beginning visual c#2012" book. I am trying to implement the classes and interface from these information. I tried to do it but failed. Is there a way to declare instant, milk, sugar and description in interface and declare beantype or leaftype in class coffee and class tea respectively.
<<Interface>> CupOfCoffee - IHotDrink(Interface)
IHotDrink + BeanType:string
--------------
+Instant: bool CupOfTea - IHotDrink (Interface)
+Milk : bool + LeafType:string
+Sugar : byte
+Description : String
namespace Interfaces
{
interface IHotDrink
class Coffee: IHotDrink
{
public string BeanType;
public string Description;
public string Sugar;
public string Milk;
}
class Tea: IHotDrink
{
public string LeafType;
public string Description;
public string Sugar;
public string Milk;
}
class Program
{
static void PrintInfo(IHotDrink item)
{
Console.WriteLine("BeanType: {0}, Description: {1}, Sugar: {2}, Milk: {3}",item.BeanType, item.Description, item.Sugar,
item.Milk);
}
static void PrintInfo(Tea item)
{
Console.WriteLine("LeafType: {0}, Description: {1}, Sugar: {2}, Milk: {3}", item.LeafType, item.Description, item.Sugar,
item.Milk);
}
static void Main()
{
Coffee c = new Coffee() { BeanType = "Medium Roast", Description = "Large", Sugar ="No", Milk = "Yes" };
Tea t = new Tea() { LeafType = "Green", Description = "Small", Sugar = "No", Milk = "Yes" };
PrintInfo(c);
PrintInfo(t);
}
}
}