Nothing Special   »   [go: up one dir, main page]

Oose Lab - Manual (Final)

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

35List of Experiments

PAGEN MARK SIG


NAME
S.NO DATE O S N

1 19-12-2017 EXERCISES ON CLASS DIAGRAMS   11-13  

2 19-12-2017 EXERCISES ON USE CASE DIAGRAMS  14-15  

3 26-12-2017 EXERCISES ON SEQUENCE DIAGRAMS  16-18  

4 26-12-2017 EXERCISES ON STATE MACHINE DIAGRAMS  19-21  

5 02-01-2018 EXERCISES ON ACTIVITY DIAGRAMS  22-25  

6 02-01-2018 EXERCISES ON COMPOSITE DIAGRAMS  26-27  

7 09-01-2018 EXERCISES ON DEPLOYMENT DIAGRAMS  28  

8 09-01-2018 MODEL VIEW CONTROL MODEL (MVC)  29  

9 23-01-2018 FACTORY DESIGN PATTERN  30  

10 23-01-2018 ABSTRACT FACTORY DESIGN PATTERN  31-32  

11 30-01-2018 ADAPTER DESIGN PATTERN  33-34  

12 30-01-2018 BRIDGE DESIGN PATTERN  35  

13 06-02-2018 FACADE DESIGN PATTERN  36  

14 20-02-2018 COMPOSITE DESIGN PATTERN  37  

15 27-02-2018 PROXY DESIGN PATTERN  38  

16 06-03-2018 OBJECT CONTRAINED LANGUAGE (OCL)  39  

17 13-03-2018 ARENA CASE STUDY  40  

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 1


I Exercises on class diagrams

1 A) Draw a class diagram representing a book defined by the following statement:


“A book is composed of a number of parts, which in turn are composed of a
number of chapters. Chapters are composed of sections.”Focus only on classes and
relationships. Add multiplicity to the class diagram .

B) Extend the class diagram of Exercise 1A to include the following attributes:


• a book includes a publisher, publication date, and an ISBN
• a part includes a title and a number
• a chapter includes a title, a number, and an abstract
• a section includes a title and a number

C) Consider the class diagram of Exercise 1B. Note that the Part, Chapter, and
Section classes all include a title and a number attribute. Add an abstract class and
a generalization relationship to factor out these two attributes into the abstract
class.

2) Draw a UML class diagram for Library Management System (LMS).

Hint: Each physical library item - book, tape cassette, CD, DVD, etc. could have
its own item number. To support it, the items may be bar-coded. The purpose of
bar-coding is to provide a unique and scan able identifier that links the bar-coded
physical item to the electronic record in the catalog. Barcode must be physically
attached to the item, and barcode number is entered into the corresponding field in
the electronic item record. Barcodes on library items could be replaced by RFID
tags. The RFID tag can contain item's identifier, title, material type, etc. It is read
by an RFID reader, without the need to open a book cover or CD/DVD case to
scan it with barcode reader. Library has some rules on what could be borrowed
and what is for reference only. Rules are also defined on how many books could
be borrowed by patrons and how many could be reserved

3) Draw a UML class diagram showing an inheritance hierarchy containing


classes that represent different types of cars, organized first by manufacturer. Show
some appropriate variables and method names for at least two of these classes

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 2


4) Draw a class diagram for online shopping. Each customer could have some
web user identity. Web user could be in several states and could be linked to one
shopping cart. Each customer has exactly one account. Account owns shopping
cart and orders. Orders are sorted and unique. Each order is linked to none to
several payments. Each order has current order status. Both order and shopping
cart have line items linked to specific product

II Exercises on Use case diagrams

1) Draw a use case diagram for a ticket distributor for a train system. The system
includes two actors: a traveler, who purchases different types of tickets, and a
central computer system, which maintains a reference database for the tariff.
Use cases should include: BuyOneWayTicket, BuyWeeklyCard,
BuyMonthlyCard, UpdateTariff. Also include the following exceptional
cases: Time-Out (i.e., traveler took too long to insert the right amount),
TransactionAborted (i.e., traveler selected the cancel button without
completing the transaction), DistributorOutOfChange, and
DistributorOutOfPaper

2) Draw a use case diagram to represent the following system. Over the summer
holiday, university students can book collegehall accommodation online. They
must specify their name, student number, course, year, and identify three college
residences as their preferences. The system makes an allocation of students to
rooms before the start of the term, trying, where possible, to allocate students to a
room in one of their preferred halls.

3) Draw a usecase diagram for on-line shopping Web Customer actor uses some
web site to make purchases online. Top level use cases are View Items, Make
Purchase and Client Register. View Items use case could be used by customer as
top level use case if customer only wants to find and see some products. This use
case could also be used as a part of Make Purchase use case. Client Register use
case allows customer to register on the web site, for example to get some coupons
or be invited to private sales. Note that Checkout use case is includedusecase not
available by itself - checkout is part of making purchase. Except for the Web
Customer actor there are several other actors .View Items use case is extended by
several optional use cases - customer may search for items, browse catalog, view
items recommended for him/her, add items to shopping cart or wish list. All these
use cases are extending use cases because they provide some optional functions
allowing customer to find item. Customer Authentication use case is included in
View Recommended Items and Add to Wish List because both require customer

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 3


to be authenticated. At the same time, item could be added to the shopping cart
without user authentication.

4) Draw Use case diagram for the course registration system

III Exercises on Sequence diagrams

1. Draw a sequence diagram representing the process of making a phone call from
a cell phone.
Hint: The objects involved include the caller, the phone network, the
receiver of the phone call, and the cell phone accounting department.

2. Draw a sequence diagram for ATM Transactions.

3. Draw a sequence diagram for a user to recharge his account online through third
party site.

4. Draw a sequence diagram for Elevator button.

IV Exercises on State machine diagrams

1. Draw a UML state machine Diagram for a seminar during enrollment of student
in university.
Hint: Create a state machine when behavior differs based on state.  A seminar
object is fairly complex, reacting to events such a enrolling a student differently
depending on its current state.

2. Draw a state chart to describe one's marital status.

3. Draw a state chart diagram for Bank ATM.

Hint: ATM is initially turned off. After the power is turned on, ATM performs
startup action and enters Self Test state. If the test fails, ATM goes into Out of
Service state, otherwise there is triggerless transition to the Idle state. In this state
ATM waits for customer interaction. The ATM state changes from Idle to Serving
Customer when the customer inserts banking or credit card in the ATM's card
reader. On entering the Serving Customer state, the entry action readCard is
performed. Note, that transition from Serving Customer state back to the Idle state

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 4


could be triggered by cancel event as the customer could cancel transaction at any
time.

4.Draw state chart diagram for water phases

V Exercises on Activity diagrams

1. Draw an activity diagram for "Withdraw money from a bank account through an
ATM”.

2. Draw an activity diagram for 'Make lemon juice' and 'Make Ginger Juice'
activities are executed in parallel.

3. Draw an activity diagram for the activity to the respective objects like Customer,
Stock, Order processing, Payment and Invoice using swimlanes.

4. Draw an activity diagram showing the passenger checking in for a flight.

VI Exercises on Component diagrams

1. Draw a component diagram for a user to recharge his account online through
third party site.
Hint: Following components should be involved.
Third Party Home Page (visitor / registered user / admin / service
provider)
Third Party Register Page (visitor)
Third Party Login Page (registered user)
Third Party User History Page (registered user)
Request Recharge Page (registered user)
Third Party Logout Page (registered user)
Online Payment Transaction Gateway Page (direct user / registered user)
Service Provider Home Page (visitor / registered user / admin / service
provider)
Tariff Plans Page (visitor / registered user / admin / service provider)

2. Draw a component diagram Library Management System.


Hint: Following components should be involved.
Register Page (visitor / vendor)

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 5


Login Page (user / librarian / vendor)
Search Page (user / librarian / vendor)
Request Vendor Page (librarian)
Request Book Issue Page (user / vendor)
Issue Status Page (librarian)
Make Payment Page (librarian / vendor)
Provide Books Page (librarian)
Logout Page (user / librarian / vendor)

VII Exercises on Deployment diagrams

1. Draw a deployment diagram for a user to recharge his account online


through third party site.
Hint:
Consoles / Computers for registration, login purposes by third party users
and for quick recharge by direct users.
Third Party Server to receive and respond to all the requests from various
users.
Internet to provide access to users to recharge their accounts through
payment gateways by placing requests through Third Party Sites and
Service Providers sites.
Payment Gateway Server like Bank's server to provide online payment
through their personal accounts to meet the requirements of the users.
Service Provider Server to maintain the records of the requests made by
the users.

2. Draw a deployment diagram which shows the relationships among software


and hardware components involved in real estate transactions.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 6


Project: Passport Tracking system
Description
The passport tracking system is developed to manage the passport application and issue of
passports. The system has login. if the username and password are correct, it will open the next form. If
the entered details are not correct, it will show the error message. The members will register for new
passport through the application and it will provide the application id and password. The member will use
the application id and password to login to the system. The status can be viewed by the member. The
members can make complaint to the administrator through complaint form. The administrator can view all
complaints and reply to all complaints sent by the members. The members can send renewal application
to the administrator through the renew application portal. The renewal request will be sent to the
administrator. The administrator can renew or reject the renewal request. The status of the renewal can
be viewed by the members.

Modules
1.Logon & Application Status
2.Submit an Enquiry for Information
3.Passport Renewal
4.passport approval

1 week for study and identify requirements of their projects this step is same for
all modules

Logon & Application Status module works on

5 weeks on analysis and design diagrams of each module


Out of 5 weeks 2weeks for development of analysis diagrams of each module
And remaining 2weeks for design diagrams of each module
Remaining 1 week the student should submit project report

1st Week Study and identify requirements

2nd and 3rd Week Development of analysis diagrams

4th and 5th Week Development of design diagrams.

6th week Project report

Submit an Enquiry for Information module works on


5 weeks on analysis and design diagrams of each module
Out of 5 weeks 2weeks for development of analysis diagrams of each module
And remaining 2weeks for design diagrams of each module
Remaining 1 week the student should submit project report

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 7


1st Week Study and identify requirements

2nd and 3rd Week Development of analysis diagrams

4th and 5th Week Development of design diagrams.

6th week Project report

Passport Renewal module works on

5 weeks on analysis and design diagrams of each module


Out of 5 weeks 2weeks for development of analysis diagrams of each module
And remaining 2weeks for design diagrams of each module
Remaining 1 week the student should submit project report

1st Week Study and identify requirements

2nd and 3rd Week Development of analysis diagrams

4th and 5th Week Development of design diagrams.

6th week Project report

Passport Approval module works on

5 weeks on analysis and design diagrams of each module


Out of 5 weeks 2weeks for development of analysis diagrams of each module
And remaining 2weeks for design diagrams of each module
Remaining 1 week the student should submit project report

1st Week Study and identify requirements

2nd and 3rd Week Development of analysis diagrams

4th and 5th Week Development of design diagrams.

6th week Project report

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 8


Project: Bus Reservation System
Bus Reservation system for a Road Transport corporation contains four modules. The first
module of the project deals with reserving tickets for passengers. The second module deals with
cancelling the reservations made earlier and paying refund. The third module deals with enquiry
regarding reservations, cancellations, waiting list, Bus routes and timings, etc. The fourth module
deals with Accounting. The developers (a batch of 4 students) have to elicit the requirements
from the hypothetical client and prepare and finalize the Software Requirements specification
(SRS) document. As per the principles of Object Oriented Analysis and Design, the developers
have to analyze the system keeping in view of the SRS document and design the system and
produce analysis and design models by drawing the necessary UML diagrams

Modules
1. Reservation
2. Cancelation
3. Enquiry
4. Accounting

1 week for study and identify requirements of their projects this step is same for
all modules

Reservation module works on

5 weeks on analysis and design diagrams of each module


Out of 5 weeks 2weeks for development of analysis diagrams of each module
And remaining 2weeks for design diagrams of each module
Remaining 1 week the student should submit project report

1st Week Study and identify requirements

2nd and 3rd Week Development of analysis diagrams

4th and 5th Week Development of design diagrams.

6th week Project report

Cancelation module works on

5 weeks on analysis and design diagrams of each module


Out of 5 weeks 2weeks for development of analysis diagrams of each module
K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 9
And remaining 2weeks for design diagrams of each module
Remaining 1 week the student should submit project report

1st Week Study and identify requirements

2nd and 3rd Week Development of analysis diagrams

4th and 5th Week Development of design diagrams.

6th week Project report

Enquiry module works on

5 weeks on analysis and design diagrams of each module


Out of 5 weeks 2weeks for development of analysis diagrams of each module
And remaining 2weeks for design diagrams of each module
Remaining 1 week the student should submit project report

1st Week Study and identify requirements

2nd and 3rd Week Development of analysis diagrams

4th and 5th Week Development of design diagrams.

6th week Project report

Accounting module works on

5 weeks on analysis and design diagrams of each module


Out of 5 weeks 2weeks for development of analysis diagrams of each module
And remaining 2weeks for design diagrams of each module
Remaining 1 week the student should submit project report

1st Week Study and identify requirements

2nd and 3rd Week Development of analysis diagrams

4th and 5th Week Development of design diagrams.

6th week Project report

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 10


Solutions of the above experiments
Exercise-1 Class diagrams

1A) Draw a class diagram representing a book defined by the following statement:
“A book is composed of a number of parts, which in turn are composed of a
number of chapters. Chapters are composed of sections.”Focus only on classes and
relationships. Add multiplicity to the class diagram.

B) Extend the class diagram of Exercise 1A to include the following attributes:


• a book includes a publisher, publication date, and an ISBN
• a part includes a title and a number
• a chapter includes a title, a number, and an abstract
• a section includes a title and a number

C) Consider the class diagram of Exercise 2B. Note that the Part, Chapter, and
Section classes all include a title and a number attribute. Add an abstract class and
a generalization relationship to factor out these two attributes into the abstract
class.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 11


2) Draw a UML class diagram for Library Management System (LMS).

Hint: Each physical library item - book, tape cassette, CD, DVD, etc. could have
its own item number. To support it, the items may be bar-coded. The purpose of
bar-coding is to provide a unique and scan able identifier that links the bar-coded
physical item to the electronic record in the catalog. Barcode must be physically
attached to the item, and barcode number is entered into the corresponding field in
the electronic item record. Barcodes on library items could be replaced by RFID
tags. The RFID tag can contain item's identifier, title, material type, etc. It is read
by an RFID reader, without the need to open a book cover or CD/DVD case to
scan it with barcode reader. Library has some rules on what could be borrowed
and what is for reference only. Rules are also defined on how many books could
be borrowed by patrons and how many could be reserved.

3) Draw a UML class diagram showing an inheritance hierarchy containing


classes that represent different types of cars, organized first by manufacturer. Show
some appropriate variables and method names for at least two of these classes

4) Draw a class diagram for online shopping. Each customer could have some
web user identity. Web user could be in several states and could be linked to one
shopping cart. Each customer has exactly one account. Account owns shopping
cart and orders. Orders are sorted and unique. Each order is linked to none to
several payments. Each order has current order status. Both order and shopping
cart have line items linked to specific product.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 12


K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 13
Exercise-2 Use Case Diagrams
1. Draw a use case diagram for a ticket distributor for a train system. The system
includes two actors: a traveler, who purchases different types of tickets, and a
central computer system, which maintains a reference database for the tariff. Use
cases should include: BuyOneWayTicket, BuyWeeklyCard, BuyMonthlyCard,
UpdateTariff. Also include the following exceptional cases: Time-Out(i.e.,
traveler took too long to insert the right amount),TransactionAborted (i.e.,
traveler selected the cancel button without completing the
transaction),DistributorOutOfChange, and DistributorOutOfPaper

2) Draw a use case diagram to represent the following system. Over the summer
holiday, university students can book collegehall accommodation online. They
must specify their name, student number, course, year, and identify three college
residences as their preferences. The system makes an allocation of students to
rooms before the start of the term, trying, where possible, to allocate students to a
room in one of their preferred halls.

3) Draw a usecase diagram for on-line shopping Web Customeractoruses some


web site to make purchases online. Top level use cases are View Items, Make
Purchase and Client Register. View Items use case could be used by customer as
top level use case if customer only wants to find and see some products. This use
case could also be used as a part of Make Purchase use case. Client Register use
case allows customer to register on the web site, for example to get some coupons
or be invited to private sales. Note that Checkout use case is includedusecase not
available by itself - checkout is part of making purchase. Except for the Web
Customer actor there are several other actors .View Items use case is extended by
several optional use cases - customer may search for items, browse catalog, view
items recommended for him/her, add items to shopping cart or wish list. All these
use cases are extending use cases because they provide some optional functions
allowing customer to find item. Customer Authentication use case is included in
View Recommended Items and Add to Wish List because both require customer
to be authenticated. At the same time, item could be added to the shopping cart –––
without user authentication.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 14


K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 15
Exercise-3 Sequence Diagram & Collaboration Diagram
1. Draw a sequence diagram representing the process of making a phone call from
a cell phone.
Hint: The objects involved include the caller, the phone network,the
receiver of the phone call, and the cell phone accounting department.

2. Draw a sequence diagram for ATM Transactions.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 16


3. Draw a sequence diagram for a user to recharge his account online through
third party site.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 17


4. Draw a sequence diagram for Elevator button.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 18


Exercise-4 State Machine Diagram

1.Draw a UML state machine Diagram for a seminar during enrollment of student
in university.

Hint: Create a state machine when behavior differs based on state.  A seminar
object is fairly complex, reacting to events such a enrolling a student differently
depending on its current state.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 19


2. Draw a state chart diagram for Bank ATM.

Hint: ATM is initially turned off. After the power is turned on, ATM performs
startup action and enters Self Test state. If the test fails, ATM goes into Out of
Service state, otherwise there is triggerless transition to the Idle state. In this state
ATM waits for customer interaction. The ATM state changes from Idle to Serving
Customer when the customer inserts banking or credit card in the ATM's card
reader. On entering the Serving Customer state, the entry action readCard is
performed. Note, that transition from Serving Customer state back to the Idle state
could be triggered by cancel event as the customer could cancel transaction at any
time.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 20


3. Draw state chart diagram for water phases

Hint: Water can exist in several states - liquid, vapor, solid, and plasma.
Several transitions are possible from one state to another. For example,
freezing is phase change from liquid state to ice. Condensation is phase
change from vapor state to liquid. Water vapor could turn directly into frost
through deposition.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 21


Exercise-5 Activity diagram

1) Draw an activity diagram for "Withdraw money from a bank account


through an ATM”.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 22


2) Draw an activity diagram for 'Make lemon juice' and 'Make Ginger Juice'
activities are executed in parallel.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 23


3) Draw an activity diagram for the activity to the respective objects like
Customer, Stock, Order processing, Payment and Invoice using swimlanes.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 24


4) Draw an activity diagram showing the passenger checking in for a flight.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 25


Exercise- 6 & 7 Component & Deployment Diagrams

1. Draw a component diagram for a user to recharge his account online


through third party site.
Hint: Following components should be involved.
Third Party Home Page (visitor / registered user / admin / service
provider)
Third Party Register Page (visitor)
Third Party Login Page (registered user)
Third Party User History Page (registered user)
Request Recharge Page (registered user)
Third Party Logout Page (registered user)
Online Payment Transaction Gateway Page (direct user / registered user)
Service Provider Home Page (visitor / registered user / admin / service
provider)
Tariff Plans Page (visitor / registered user / admin / service provider)

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 26


2. Draw a component diagram for Library Management System.
Hint: Following components should be involved.
Register Page (visitor / vendor)
Login Page (user / librarian / vendor)
Search Page (user / librarian / vendor)
Request Vendor Page (librarian)
Request Book Issue Page (user / vendor)
Issue Status Page (librarian)
Make Payment Page (librarian / vendor)
Provide Books Page (librarian)
Logout Page (user / librarian / vendor)

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 27


3. Draw a deployment diagram for a user to recharge his account online
through third party site.
Hint: Consoles / Computers for registration, login purposes by third
party users and for quick recharge by direct users.
Third Party Server to receive and respond to all the requests from various
users.
Internet to provide access to users to recharge their accounts through
payment gateways by placing requests through Third Party Sites and
Service Providers sites.
Payment Gateway Server like Bank's server to provide online payment
through their personal accounts to meet the requirements of the users.
Service Provider Server to maintain the records of the requests made by
the users.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 28


EXERCISE-8 MVC MODEL

MVC Pattern stands for Model-View-Controller Pattern. This pattern is used to


separate application's concerns.
 Model - Model represents an object or JAVA POJO carrying data. It can also
have logic to update controller if its data changes.
 View - View represents the visualization of the data that model contains.
 Controller - Controller acts on both model and view. It controls the data flow
into model object and updates the view whenever data changes. It keeps view
and model separate.

IMPLEMENTATION
We are going to create a Student object acting as a model.StudentView will
be a view class which can print student details on console
and StudentControlleris the controller class responsible to store data
in Student object and update view StudentView accordingly.

MVCPatternDemo, our demo class, will use StudentController to


demonstrate use of MVC pattern.

EXERCISE-9 FACTORY DESIGN PATTERN


K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 29
Factory pattern is one of the most used design patterns in Java. This type of
design pattern comes under creational pattern as this pattern provides one
of the best ways to create an object.

In Factory pattern, we create object without exposing the creation logic to


the client and refer to newly created object using a common interface.

Implementation
We're going to create a Shape interface and concrete classes implementing
the Shape interface. A factory class ShapeFactory is defined as a next step.

FactoryPatternDemo, our demo class will use ShapeFactory to get


a Shapeobject. It will pass information (CIRCLE / RECTANGLE / SQUARE)
to ShapeFactory to get the type of object it needs.

EXERCISE-10 ABSTRACT FACTORY DESIGN PATTERN

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 30


Abstract Factory patterns work around a super-factory which creates other
factories. This factory is also called as factory of factories. This type of
design pattern comes under creational pattern as this pattern provides one
of the best ways to create an object.

In Abstract Factory pattern an interface is responsible for creating a factory


of related objects without explicitly specifying their classes. Each generated
factory can give the objects as per the Factory pattern.

Implementation
We are going to create a Shape and Color interfaces and concrete classes
implementing these interfaces. We create an abstract factory
class AbstractFactory as next step. Factory
classes ShapeFactory and ColorFactoryare defined where each factory
extends AbstractFactory. A factory creator/generator class FactoryProducer is
created.
AbstractFactoryPatternDemo, our demo class uses FactoryProducer to get
a AbstractFactory object. It will pass information (CIRCLE / RECTANGLE /
SQUARE for Shape) to AbstractFactory to get the type of object it needs. It also
passes information (RED / GREEN / BLUE for Color) to AbstractFactory to get
the type of object it needs.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 31


ABSTRACT FACTORY DESIGN PATTERN

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 32


EXERCISE-11 ADAPTER DESIGN PATTERN

Adapter pattern works as a bridge between two incompatible interfaces.


This type of design pattern comes under structural pattern as this pattern
combines the capability of two independent interfaces.

This pattern involves a single class which is responsible to join


functionalities of independent or incompatible interfaces. A real life example
could be a case of card reader which acts as an adapter between memory
card and a laptop. You plugin the memory card into card reader and card
reader into the laptop so that memory card can be read via laptop.

We are demonstrating use of Adapter pattern via following example in


which an audio player device can play mp3 files only and wants to use an
advanced audio player capable of playing vlc and mp4 files.

Implementation
We have a MediaPlayer interface and a concrete
class AudioPlayerimplementing the MediaPlayer interface. AudioPlayer can
play mp3 format audio files by default.

We are having another interface AdvancedMediaPlayer and concrete classes


implementing the AdvancedMediaPlayer interface. These classes can play
vlc and mp4 format files.

We want to make AudioPlayer to play other formats as well. To attain this,


we have created an adapter class MediaAdapter which implements
the MediaPlayer interface and uses AdvancedMediaPlayer objects to play the
required format.

AudioPlayer uses the adapter class MediaAdapter passing it the desired


audio type without knowing the actual class which can play the desired
format. AdapterPatternDemo, our demo class will use AudioPlayer class to
play various formats.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 33


ADAPTER DESIGN PATTERN

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 34


EXERCISE-12 BRIDGE DESIGN PATTERN

Bridge is used when we need to decouple an abstraction from its


implementation so that the two can vary independently. This type of design
pattern comes under structural pattern as this pattern decouples
implementation class and abstract class by providing a bridge structure
between them.

This pattern involves an interface which acts as a bridge which makes the
functionality of concrete classes independent from interface implementer
classes. Both types of classes can be altered structurally without affecting
each other.

We are demonstrating use of Bridge pattern via following example in which


a circle can be drawn in different colors using same abstract class method
but different bridge implementer classes.

Implementation
We have a DrawAPI interface which is acting as a bridge implementer and
concrete classes RedCircle, GreenCircle implementing
the DrawAPI interface. Shape is an abstract class and will use object
of DrawAPI. BridgePatternDemo, our demo class will use Shape class to
draw different colored circle.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 35


EXERCISE-13 FACADE DESIGN PATTERN

Facade pattern hides the complexities of the system and provides an


interface to the client using which the client can access the system. This
type of design pattern comes under structural pattern as this pattern adds
an interface to existing system to hide its complexities.

This pattern involves a single class which provides simplified methods


required by client and delegates calls to methods of existing system classes.

Implementation
We are going to create a Shape interface and concrete classes
implementing the Shape interface. A facade class ShapeMaker is defined as
a next step.

ShapeMaker class uses the concrete classes to delegate user calls to these


classes. FacadePatternDemo, our demo class, will use ShapeMaker class to
show the results.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 36


EXERCISE-14 COMPOSITE DESIGN PATTERN

Composite pattern is used where we need to treat a group of objects in


similar way as a single object. Composite pattern composes objects in term
of a tree structure to represent part as well as whole hierarchy. This type of
design pattern comes under structural pattern as this pattern creates a tree
structure of group of objects.

This pattern creates a class that contains group of its own objects. This
class provides ways to modify its group of same objects.

We are demonstrating use of composite pattern via following example in


which we will show employees hierarchy of an organization.

Implementation
We have a class Employee which acts as composite pattern actor
class. CompositePatternDemo, our demo class will use Employee class to
add department level hierarchy and print all employees.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 37


EXERCISE-15 PROXY DESIGN PATTERN

In proxy pattern, a class represents functionality of another class. This type


of design pattern comes under structural pattern.

In proxy pattern, we create object having original object to interface its


functionality to outer world.

Implementation

We are going to create an Image interface and concrete classes


implementing the Image interface. ProxyImage is a a proxy class to reduce
memory footprint of RealImage object loading.

ProxyPatternDemo, our demo class, will use ProxyImage to get


an Imageobject to load and display as it needs.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 38


EXERCISE-16 OBJECT CONTRAINED LANGUAGE

Object Constraint Language (OCL) is a language that allows constraints


to be formally specified on single model elements (e.g., attributes,
operations, classes) or groups of model elements (e.g., associations and
participating classes).

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 39


EXERCISE-17 ARENA CASE STUDY

• Provide a generic infrastructure to


• Support virtual game communities.
• Register new games
• Register new players
• Organize tournaments
• Keeping track of the player’s scores.
• Provide a framework for tournament organizers
• To customize the number and sequence of matchers and the
accumulation of expert rating points.
• Provide a framework for game developers
• For developing new games, or for adapting existing games into the
ARENA framework.
• Provide an infrastructure for advertisers.
• Provide a framework for tournament organizers
• to customize the number and sequence of matchers and the
accumulation of expert rating points
• Provide a framework for game developers
• for developing new games, or for adapting existing games into the
ARENA framework
• Provide an infrastructure for advertisers.

K L UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE Page 40

You might also like