SDA Lab 11
SDA Lab 11
College of Engineering
(Software Engineering)
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.
Adapter Pattern
1. Target
2. Adaptee
3. Adapter
4. Client
1. Target
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.
1.Click on
file then new
1.Select
Visual C#
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.Select Visual C#
2. Add Interface
Step#04: Now add Adaptee class. This is the class; user wants to access. But the interface of class is
incompatible for user.
1.Select Visual C#
4.Click Add
2. Add Class
1.Select Visual C#
4.Click Add
Handle Incompatibility by Object
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).