POC on Restaurant ordering system using factory pattern
POC on Restaurant ordering system using factory pattern
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ManualResetEvent_
{
//---------------------------------------------Factory Design Pattern for createing Food Items---------------------------------------------------//
abstract class IFood
{
public string name { get; set; }
public int quantity { get; set; }
public int price { get; set; }
public abstract void GetValues();
}
class Rice : IFood
{
public string name { get; set; }
public int quantity { get; set; }
public int price { get; set; }
public Rice()
{
}
public override void GetValues()
{
this.name = "Rice";
this.price = 20;
this.quantity = 1;
}
}
class Tea : IFood
{
string name;
int quantity;
int price;
public Tea()
{
}
public override void GetValues()
{
this.name = "Tea";
this.price = 10;
this.quantity = 1;
}
}
class MilkShake : IFood
{
string name;
int quantity;
int price;
public MilkShake()
{
}
public override void GetValues()
{
this.name = "MilkShake";
this.price = 20;
this.quantity = 1;
}
}
class Paneer : IFood
{
string name;
int quantity;
int price;
public Paneer()
{
}
public override void GetValues()
{
name = "Paneer";
price = 100;
quantity = 1;
}
}
abstract class creator
{
public abstract IFood factoryMethod(string type);
}
class concretecreator : creator
{
public override IFood factoryMethod(string type)
{
switch (type)
{
case "Rice": return new Rice();
case "Milk": return new MilkShake();
case "Paneer": return new Paneer();
default: throw new ArgumentException("No Object of Mentioned type", "type");
}
}
}
//------------------------------------ Factory Design Pattern -For Creating Food Items--------------------------------------//
//------------------------------------Adapter Design Pattern -- For getting the food Items ---------------------------------//
//------------------------------------Adapter Design Pattern -- For getting the food Items ---------------------------------//
class People
{
public string name {get;set;}
public int mobile{get;set;}
public List<string> food;
public People(string name_, int mobile_)
{
name = name_;
mobile = mobile_;
}
public List<string> orderFood(List<IFood> fd)
{
food=new List<string>();
foreach (IFood name_ in fd)
{
food.Add(name_.name);
}
return food;
}
}
class Restaurant
{
public List<IFood> fdItems {get;set;}
creator p = new concretecreator();
List<string> fd;
public void createFood(List<string> fditems)
{
fd = new List<string>();
fdItems = new List<IFood>();
foreach (string food in fditems)
{
if (food == "Rice")
{
IFood rice = p.factoryMethod("Rice");
//rice.GetValues();
rice.name = "Rice";
rice.price = 20;
rice.quantity = 2;
fdItems.Add(rice);
}
else if (food == "Milk")
{
IFood milk = p.factoryMethod("Milk");
milk.GetValues();
milk.price = 10;
milk.quantity = 1;
fdItems.Add(((ManualResetEvent_.MilkShake)(milk)));
}
else if (food == "Paneer")
{
IFood paneer = p.factoryMethod("Paneer");
paneer.GetValues();
paneer.price = 100;
paneer.quantity = 1;
fdItems.Add(((ManualResetEvent_.Paneer)(paneer)));
}
}
}
}
class calculation_bill
{
People p;
List<IFood> fd;
int totalbill_;
public calculation_bill(People p1, List<IFood> fd_)
{
p = p1;
fd = fd_;
totalbill_ = 0;
}
public int totalbill()
{
foreach(IFood fd_ in fd)
{
totalbill_ = totalbill_ + fd_.price;
}
return totalbill_;
}
}
class Program_Main
{
public static void Main()
{
People Amit = new People("Amit", 8904);
People Ajit = new People("Ajit", 7678);
List<string> amit_order = new List<string>();
amit_order.Add("Rice");
amit_order.Add("Paneer");
Console.WriteLine("Customer name :" + Amit.name + " Mobile Number :" + Amit.mobile);
Restaurant food_today = new Restaurant();
food_today.createFood(amit_order);
Console.WriteLine("Amits Food Items");
foreach (IFood fd in food_today.fdItems)
{
Console.WriteLine(fd.name + " , " + fd.price);
}
calculation_bill amit_bill = new calculation_bill(Amit,food_today.fdItems);
Console.WriteLine("Amits bill" + amit_bill.totalbill());
List<string> Ajit_order = new List<String>();
Ajit_order.Add("Rice");
Ajit_order.Add("Paneer");
Ajit_order.Add("Milk");
Console.WriteLine("Customer name :" + Ajit.name + " Mobile Number :" + Ajit.mobile);
food_today.createFood(Ajit_order);
Console.WriteLine("Ajit Food Items");
foreach (IFood fd in food_today.fdItems)
{
Console.WriteLine(fd.name + " , " + fd.price);
}
calculation_bill Ajit_bill = new calculation_bill(Ajit, food_today.fdItems);
Console.WriteLine("Ajit bill " + Ajit_bill.totalbill());
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ManualResetEvent_
{
//---------------------------------------------Factory Design Pattern for createing Food Items---------------------------------------------------//
abstract class IFood
{
public string name { get; set; }
public int quantity { get; set; }
public int price { get; set; }
public abstract void GetValues();
}
class Rice : IFood
{
public string name { get; set; }
public int quantity { get; set; }
public int price { get; set; }
public Rice()
{
}
public override void GetValues()
{
this.name = "Rice";
this.price = 20;
this.quantity = 1;
}
}
class Tea : IFood
{
string name;
int quantity;
int price;
public Tea()
{
}
public override void GetValues()
{
this.name = "Tea";
this.price = 10;
this.quantity = 1;
}
}
class MilkShake : IFood
{
string name;
int quantity;
int price;
public MilkShake()
{
}
public override void GetValues()
{
this.name = "MilkShake";
this.price = 20;
this.quantity = 1;
}
}
class Paneer : IFood
{
string name;
int quantity;
int price;
public Paneer()
{
}
public override void GetValues()
{
name = "Paneer";
price = 100;
quantity = 1;
}
}
abstract class creator
{
public abstract IFood factoryMethod(string type);
}
class concretecreator : creator
{
public override IFood factoryMethod(string type)
{
switch (type)
{
case "Rice": return new Rice();
case "Milk": return new MilkShake();
case "Paneer": return new Paneer();
default: throw new ArgumentException("No Object of Mentioned type", "type");
}
}
}
//------------------------------------ Factory Design Pattern -For Creating Food Items--------------------------------------//
//------------------------------------Adapter Design Pattern -- For getting the food Items ---------------------------------//
//------------------------------------Adapter Design Pattern -- For getting the food Items ---------------------------------//
class People
{
public string name {get;set;}
public int mobile{get;set;}
public List<string> food;
public People(string name_, int mobile_)
{
name = name_;
mobile = mobile_;
}
public List<string> orderFood(List<IFood> fd)
{
food=new List<string>();
foreach (IFood name_ in fd)
{
food.Add(name_.name);
}
return food;
}
}
class Restaurant
{
public List<IFood> fdItems {get;set;}
creator p = new concretecreator();
List<string> fd;
public void createFood(List<string> fditems)
{
fd = new List<string>();
fdItems = new List<IFood>();
foreach (string food in fditems)
{
if (food == "Rice")
{
IFood rice = p.factoryMethod("Rice");
//rice.GetValues();
rice.name = "Rice";
rice.price = 20;
rice.quantity = 2;
fdItems.Add(rice);
}
else if (food == "Milk")
{
IFood milk = p.factoryMethod("Milk");
milk.GetValues();
milk.price = 10;
milk.quantity = 1;
fdItems.Add(((ManualResetEvent_.MilkShake)(milk)));
}
else if (food == "Paneer")
{
IFood paneer = p.factoryMethod("Paneer");
paneer.GetValues();
paneer.price = 100;
paneer.quantity = 1;
fdItems.Add(((ManualResetEvent_.Paneer)(paneer)));
}
}
}
}
class calculation_bill
{
People p;
List<IFood> fd;
int totalbill_;
public calculation_bill(People p1, List<IFood> fd_)
{
p = p1;
fd = fd_;
totalbill_ = 0;
}
public int totalbill()
{
foreach(IFood fd_ in fd)
{
totalbill_ = totalbill_ + fd_.price;
}
return totalbill_;
}
}
class Program_Main
{
public static void Main()
{
People Amit = new People("Amit", 8904);
People Ajit = new People("Ajit", 7678);
List<string> amit_order = new List<string>();
amit_order.Add("Rice");
amit_order.Add("Paneer");
Console.WriteLine("Customer name :" + Amit.name + " Mobile Number :" + Amit.mobile);
Restaurant food_today = new Restaurant();
food_today.createFood(amit_order);
Console.WriteLine("Amits Food Items");
foreach (IFood fd in food_today.fdItems)
{
Console.WriteLine(fd.name + " , " + fd.price);
}
calculation_bill amit_bill = new calculation_bill(Amit,food_today.fdItems);
Console.WriteLine("Amits bill" + amit_bill.totalbill());
List<string> Ajit_order = new List<String>();
Ajit_order.Add("Rice");
Ajit_order.Add("Paneer");
Ajit_order.Add("Milk");
Console.WriteLine("Customer name :" + Ajit.name + " Mobile Number :" + Ajit.mobile);
food_today.createFood(Ajit_order);
Console.WriteLine("Ajit Food Items");
foreach (IFood fd in food_today.fdItems)
{
Console.WriteLine(fd.name + " , " + fd.price);
}
calculation_bill Ajit_bill = new calculation_bill(Ajit, food_today.fdItems);
Console.WriteLine("Ajit bill " + Ajit_bill.totalbill());
Console.ReadLine();
}
}
}
Comments
Post a Comment