0% found this document useful (0 votes)
8 views12 pages

SDA Lab 11

The document outlines a lab experiment for Software Design and Architecture focusing on the Adapter Design Pattern. It includes objectives, tools, and a detailed explanation of the Adapter Pattern, including its components and implementation steps. Additionally, it provides assessment criteria for students' understanding and practical application of the concepts learned.

Uploaded by

Muhammad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

SDA Lab 11

The document outlines a lab experiment for Software Design and Architecture focusing on the Adapter Design Pattern. It includes objectives, tools, and a detailed explanation of the Adapter Pattern, including its components and implementation steps. Additionally, it provides assessment criteria for students' understanding and practical application of the concepts learned.

Uploaded by

Muhammad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

KARACHI INSTITUTE OF ECONOMICS & TECHNOLOGY

College of Engineering

(Software Engineering)

SE3301 – Software Design And Architecture

Semester: Date of Experiment:


Student name: Faculty Signature:
Student ID: Remarks/Comments:

Lab11 Structural Design Pattern-2: Adapter Pattern

PLO1 – Engineering Knowledge C1 – Recall


PLOs PLO3 – Design and Development Bloom’s Taxonomy C3 - Apply
PLO8 – Ethics P2 – Set
LAB TASK PERFORMANCE
Excellent Average Poor
CLO’s Aspects of Assessments Marks
(75-100%) (50-75%) (<50%)
Complete understanding of the Complete understanding of the Student lacks clear understanding
Recall Recall the concepts of
concepts of C# Programming concepts of C# Programming of concepts of C# Programming
CLO1 C# Programming Language,
10% Language,OOP and Structural Language, OOP and Structural Language, OOP and Structural
OOP and Structural Design
Design Patterns / actively Design Patterns / less actively Design Patterns / Unable to read
Patterns from theory.
participates during lecture. participate during lecture. and interpret it.
Experimental Validation
Select an appropriate and
Correctly select the technique Correctly select the technique to
suitable concept of OOP to Doesn’t be able to write a logic
CLO6 to perform Particular task perform Particular task related
solve and implement real world and code as per requirement of the
80% related to Adapter Design to Adapter Design Pattern. But
example to validate the task.
Pattern. code have some minor errors.
working of Adapter Design
Pattern.
Lab Safety Properly handle
CLO7 Properly handle lab equipment Moderate level lab handling Minor or no safety measurements
10%
lab infrastructure/safety
precautions & obey safety measures. and safety measurements has been considered.

Total Marks: 10
Objective:
1) Make attendee understand the basic concept of Structural Design Pattern
2) Make attendee understand the concept of Adapter Design Pattern
3) Make attendee implement example of .net to create Structural design pattern (Adapter Pattern)
Tools to be used:
Visual Studio is used to implement .net to create structural design pattern (Adapter Pattern).
What is Structural Design Pattern?

Structural Design Patterns are design patterns that ease the design by identifying a simple way to realize
the relationship among entities. This design pattern is all about class and object composition. Structural
class creation patterns use inheritance to compose interfaces. The structural object patterns define ways to
compose objects to obtain new functionality. The structural patterns describe how objects and classes can
be combined to form larger structures. Following are the types of structural design patterns:

1. Proxy
2. Adapter
3. Composite
4. Facade
5. Flyweight
6. Decorator
7. Bridge

Adapter Pattern

Adapter design pattern is used between incompatible interfaces. It converts the incompatible interface
into a compatible interface which can be used by client. So, we can say that adapter design pattern is
used to allow two incompatible interfaces to communicate. The adapter plays the role of converter or
translator. Adapter is most commonly known as Wrappers because it wraps the adapter by a new
interface which can be used by the client.

To handle the incompatibility, we use different approaches and based on that we can classify Adapter
Pattern in 2 parts.

1. Object Adapter Pattern


2. Class Adapter Pattern

1. Object Adapter Design Pattern

In Object Adapter Pattern Incompatibility is handled by creating the object.

2. Class Adapter Design Pattern

In Class Adapter Design Pattern Incompatibility is handled by inheritance.


The UML class diagram for the implementation of the Adapter design pattern is given below:

Adapter Pattern

There are four components participating in the above pattern diagram

1. Target
2. Adaptee
3. Adapter
4. Client

1. Target

This is an interface which is used by the client to achieve its functionality/request.


2. Adaptee

This is a class which has the functionality, required by the client. However, its interface is not
compatible with the client.
3. Adapter

This is a class which implements the ITarget interface and inherits the Adaptee class. It is responsible
for communication between Client and Adaptee.
4. Client

This is a class which interacts with a type that implements the ITarget interface. However, the
communication class called adaptee, is not compatible with the client
To implement Adapter pattern in real world example, lets follow the following steps
Step#01: Create new project of console application.

Create new Project

1.Click on
file then new

2. Select Console Application

1.Select
Visual C#

3. Change name accordingly

4.Click OK
Step#02: After creation of new class. Add new Interface inside the solution. Inside Interface we will
define a list which will show the list of products by methods.

1. Right click on Application

2.Click on Add option

3.Click on Add New Item

1.Select Visual C#
2. Add Interface

3.Change name accordingly


4.Click Add
Step#03: As we are going to display the list of products. We have to declare the methods using list
which will hold the product list in string format. The interface can be inherited.

Declare a method which will hold list


items

Step#04: Now add Adaptee class. This is the class; user wants to access. But the interface of class is
incompatible for user.

1. Right click on Application

2.Click on Add option

3.Click on Add New Item


2. Add Class

1.Select Visual C#

3.Change name accordingly

4.Click Add

1.Declare another method which will hold the string values

2.Create a string variable

3.Add products in list one by one

3.return list items


Step#05: Now it’s time to add Adapter class. As the name suggests, it acts as an adapter for client class
so that he or she will access the product list. Adapter class handles incompatibility. It can be done by
two methods. Either by objects or by inheritance.

1. Right click on Application

2.Click on Add option

3.Click on Add New Item

2. Add Class

1.Select Visual C#

3.Change name accordingly

4.Click Add
Handle Incompatibility by Object

1. Inherit Target interface

2. Define Target Interface Method

3.Create an object of Adaptee class

4.Return Adaptee class method

Handle Incompatibility by Inheritance

1.Inherit Adaptee class and Target interface

1.Inside method return the method of adaptee class


Step#06: Now at client side, create an object of interface using Adapter class. After creating that object
display the products using for each loop.

1.Create an Interface object

2.Display list items

Example: 2
Output:

Lab Task:
1) Implement Adapter Design Pattern (Object+Inheritance) to display list of products. (Marks: 2)
2) Implement Adapter Design Pattern for following: (Marks: 2)
1. Display the list of random numbers
2. Find out which number is even and which number is odd from the list.

Home Task:
1) Implement Adapter Design Pattern in Organization Scenario. (Marks: 4)
An organization has total 5 Departments. Each department have three types of employee having different
salary scales. You have to display the list of departments. User will choose the department to check the
salary scales of that particular department.
Create a program to solve above problem. You can use adapter (using object) or adapter (using
inheritance).

You might also like