Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

LAB 07 SOFTWARE DESIGN AND

ARCHITECTURE

Bahria University,
Karachi Campus

LAB EXPERIMENT NO.09


LIST OF TASKS
TASK NO OBJECTIVE
01 Implement Chain of Responsibility Design pattern on Processing
Scenario. Consider that there are multiple processors having multiple
responsibilities to handle (ex: media player file is played by media player
handler, calculation is carried out by calculation handler, etc…) initiate
handling for opening internet browser and notepad by creating multiple
handlers with different responsibilities.
02 Implement COR on call center scenario.

Submitted On:
26-03-2020
(Date: DD/MM/YY)

M SOHAIL ZAKIR 02-131172-028


Task 01: Implement Chain of Responsibility Design pattern on Processing
Scenario. Consider that there are multiple processors having multiple
responsibilities to handle (ex: media player file is played by media player
handler, calculation is carried out by calculation handler, etc…) initiate
handling for opening internet browser and notepad by creating multiple handlers
with different responsibilities.

Code:

Handler Class:
namespace Lab_7
{
abstract class Handler
{
protected Handler Successor;
public void SetSuccessor(Handler Successor)
{
this.Successor = Successor;
}
public abstract void ProcessRequest(File file);
}
}

Chrome Class:
namespace Lab_7
{
class Chrome : Handler
{
public override void ProcessRequest(File file)
{
if (file.extension == "html" || file.extension == "pdf" || file.extension ==
"json")
Console.WriteLine("vour file extension is {0} and is run by Google
Chrome", file.extension);
else if (Successor != null)
Successor.ProcessRequest(file);
}
}
}
Media Player Class:
namespace Lab_7
{
class Media_Player : Handler
{
public override void ProcessRequest(File file)
{
if (file.extension == "mp3" || file.extension == "mp4" || file.extension ==
"mov")
Console.WriteLine("Your file extension is {0} and is run by Media
Player", file.extension);
else if (Successor != null)
Successor.ProcessRequest(file);
}

}
}

Image Class:
namespace Lab_7
{
class Image : Handler
{
public override void ProcessRequest(File file)
{
if (file.extension == "jpg" || file.extension == "png" || file.extension ==
"img")
Console.WriteLine("Your file extension is {0} and is run by Image
Viewer", file.extension);
else
Console.WriteLine("This file Format is not Supported. . .");
}
}
}
Main Function:
namespace Lab_7
{
class Program
{
static void Main(string[] args)
{
Handler Media = new Media_Player();
Handler Chrome = new Chrome();
Handler Image = new Image();
Chrome.SetSuccessor(Media);
Media.SetSuccessor(Image);
while (true)
{
Console.Write("Enter File Name or -1 to exit");
string name = Console.ReadLine();
if (name == "-1")
break;
Chrome.ProcessRequest(new File(name));
}
Console.WriteLine("Good Bye");
}
}
}

Output:
Task 02: Implement COR on call center scenario.

Code:

Call Centre:
namespace Lab_7
{
abstract class Call_Centre
{
protected Call_Centre Successor;
public void setSuccessor(Call_Centre successor)
{
this.Successor = successor;
}
public abstract void Call_Request(Call call);
}
}

Customer Care:

namespace Lab_7
{
class Customer_Care : Call_Centre
{
public override void Call_Request(Call call)
{
if (call.issue == "Customer Care")
Console.WriteLine("Your Call is being transfered to Customer Care,
Please Wait..");
else
Console.WriteLine("Please Explain your Issue Clearly");
}
}
}
Billing:
namespace Lab_7
{
class Billing_Issue : Call_Centre
{
public override void Call_Request(Call call)
{
if (call.issue == "Billing")
Console.WriteLine("Your Call is Being Transfered to Billing Section:
Please Wait ");
else if (Successor != null)
Successor.Call_Request(call);
}
}
}

Main Function:
namespace Lab_7
{
class Program
{
static void Main(string[] args)
{
Call_Centre centre = new Billing_Issue();
Call_Centre customer = new Customer_Care();
centre.setSuccessor(customer);
while (true)
{
Console.Write("Enter your issue: or -1 to cancel the call: ");
string issue = Console.ReadLine();
if (issue == "-1")
break;
Call call = new Call(issue);
centre.Call_Request(call);
}
Console.WriteLine("Good Bye");
}
}
}
Output:

You might also like