BS (Software Engineering) 2023
Preface
This lab manual has been prepared to facilitate the students of software engineering in studying
and implementing software design and architecture. The students will also analyze the best and
most efficient software design and architecture to solve problems. The students can learn and
implement several UML diagrams, architectural patterns, and styles. After the completion of
this course students will be able to practically implement the concepts of software design &
architecture on real life applications.
Tools/ Technologies
MS Visio
Visual Paradigm for UML
2
BS (Software Engineering) 2023
TABLE OF CONTENTS
Preface ....................................................................................................................................... 2
Tools/ Technologies .................................................................................................................. 2
LAB 1: Introduction to MS Visio ........................................................................................... 4
LAB 2: Use Case Diagram ....................................................................................................... 9
LAB 3: Use Case Description ................................................................................................ 10
LAB 4: Domain Model ........................................................................................................... 11
LAB 5: Class Diagram ........................................................................................................... 13
LAB 6: Interaction Diagrams: Sequence Diagram ............................................................. 16
LAB 7: Activity Diagram....................................................................................................... 20
Lab 8: Mid Lab Assessment .................................................................................................. 22
Lab 9: State Machine Diagram ............................................................................................. 23
LAB 10: Component Diagram .............................................................................................. 25
Lab 12: Deployment Diagram ............................................................................................... 27
LAB 13: Model View Controller (MVC) ............................................................................. 28
LAB 14: GoF PATTERNS (FACTORY PATTERN, SINGLETON PATTERN) ........... 30
LAB 15: DESIGN PATTERNS (FACADE, DECORATOR) ............................................ 33
LAB 16: GoF PATTERNS (OBSERVER PATTERN)....................................................... 37
3
BS (Software Engineering) 2023
LAB 1: Introduction to MS Visio
Objectives
The purpose of this lab is to give a basic overview of MS Visio. The manual discusses how to
install and use MS Visio. The lab will also cover basic introduction to UML.
Theoretical Description
Installation of MS Visio:
Software is available at:
\\csdept\data\Resources\Software\Applications\Document Explorers\Office\MS Office 2007
(DVD)
Step 1: Run the setup.exe file.
Step 2: Select Microsoft Office Visio Professional 2007 and click Continue Button.
Step 3: On next screen, enter Product Key and click Continue Button. The Product key is given
in text file named as Serial_No.
Step 4: Check the checkbox “I accept the terms of this agreement” and click Continue Button.
Step 5: Click Install Now Button.
4
BS (Software Engineering) 2023
Step 6: Click Close Button when installation is complete.
USING MS VISIO
In today’s lab, we will practice how to make flow charts in MS Visio. The purpose of a flow
chart diagram is to depict the nature and flow of steps in a process. The basic symbols used for
drawing a flow chart are:
Step 1: Now Open Microsoft Office Visio 2007.
Step 2: Click Flow Chart Button from right pane, select basic flow chart and then click Create
Button. Alternate way: On the File menu, point to Shapes, point to the category that you want,
and then click the name of the stencil that you want to use.
5
BS (Software Engineering) 2023
The stencils that open with the Basic Flowchart template are called Arrow Shapes,
Backgrounds, and Basic Flowchart Shapes.
Step 3 (Drag and connect shapes): To create your drawing, all you need to do is drag shapes
from stencils onto the blank drawing page and connect them to one another. There are many
ways to connect shapes, but for now let's use the fastest — drag the shapes on top of each other
to connect them automatically by using AutoConnect. For more information, see Add and glue
connectors with AutoConnect.
Drag your first shape from the Basic Flowchart Shapes stencil onto the drawing page, and then release
the mouse button.
Drag your second shape on top of the first so that the blue arrows show, but don't release the
mouse button yet.
6
BS (Software Engineering) 2023
While holding the mouse button, move your pointer on top of the blue arrow that points
toward where you want to place the second shape.
Now release the mouse button. Your shapes are connected, and the first shape points to the
second shape.
Continue to build your drawing by repeating the steps mentioned above.
Step 4 (Add text to shapes): Although some drawings make a point all by themselves, it's often
helpful and sometimes necessary to add text to the shapes. There are many ways to add text to
shapes, but for now let's use the simplest way. If you want to learn more ways to add text to shapes,
see Add data to shapes and Add imported data to shapes.
Add text directly to a shape
1. Double-click the shape.
2. Start typing.
3. When you finish typing, click on a blank area of the drawing page.
The example flow chart for finding the largest among three numbers is given below:
7
BS (Software Engineering) 2023
Note: The files are saved with extension: .vsd
Lab Task
Draw and submit flowchart for a cashier program.
-
First it asks user to enter the code of the item purchased by a customer.
-
If item code is valid, the description and price for that code is displayed on the screen.
-
If item code is invalid, message is displayed “Item Code doesn’t exists”.
-
Then it asks for the quantity of the particular item code entered. If quantity is less than
zero, it prompts user to enter quantity greater than zero.
-
It displays the subtotal thereafter.
-
Moreover, it keeps on accepting item codes until ‘0’ is pressed.
-
Consequently, it displays the total amount due.
-
Then, it asks the user to tender the amount of cash of the customer. It should not accept
amount of cash less than the amount due.
-
Finally, it displays the change.
8
BS (Software Engineering) 2023
LAB 2: Use Case Diagram
Objective
In today’s lab, students will learn how to draw use case diagrams. First an introduction will be given;
next students will practice an exercise related to use case diagrams.
Theoretical Description
Use Case Diagram defines how our system will interact with the outside world. Use case model is a
representation of sequence of transactions initiated by the user (actor) from outside the system. The
main concepts in use cases are Actors, Use Cases and Associations
Case Study
Hurry's require a new point of sale and stock control system for their many stores throughout
the UK to replace their ageing mini based systems.
A sales assistant will be able to process an order by entering product numbers and required
quantities into the system. The system will display a description, price and available stock. Instock products will normally be collected immediately by the customer from the store but may
be selected for delivery to the customer's home address for which there will be a charge. If
stock is not available the sales assistant will be able to create a backorder for the product from
a regional warehouse. The products will then either be delivered direct from the regional
warehouse to the customer's home address or to the store for collection by the customer. The
system will allow products to be paid for by cash or credit card. Credit card transactions will
be validated via an online card transaction system. The system will produce a receipt. Order
details for in-stock products will be printed in the warehouse including the bin reference,
quantity, product number and description. These will be collected by the sales assistant and
given to the customer. The sales assistant will be able to make refunds, provided a valid receipt
is produced. The sales assistant will also be able to check stock and pricing without creating an
order and progress orders that have been created for delivery.
The store manager will be able at any time to print a summary report of sales in the store for a
given period, including assignment of sales to sales assistants in order to calculate weekly sales
bonuses.
The stock manager will be able to monitor stock levels and weekly run-rates in order to set
minimum stock levels and requisition products which fall below the minimum stock levels or
for which demand is anticipated. When the stock arrives it will be booked in by the warehouse
person. Stock that has been backordered for collection from the store is held in a separate area
and the store manager advised of its arrival.
The catalogue of available products will be maintained remotely by marketing from head
office. Marketing will also be able to access sales information from each store system.
Lab Task
1. Enlist all the possible Actors in the above scenario.
2. Enlist all the possible Use Cases in the above scenario.
3. Draw the detailed use-case diagram of the above requirement specifications.
9
BS (Software Engineering) 2023
LAB 3: Use Case Description
Objective
In today’s lab, students will learn how to write use case description. The students will
practice an exercise related to use case description.
Theoretical Description
Use Case Description is a narrative document that describes the sequence of system events and
the system responses originating from the initiating actors of the system. The description
showed both the basic flow and the alternate flow of events, which will be used as a guidance
for dynamic modelling of the system.
Case Study:
Hurry's require a new point of sale and stock control system for their many stores throughout
the UK to replace their ageing mini based systems.
A sales assistant will be able to process an order by entering product numbers and required
quantities into the system. The system will display a description, price and available stock. Instock products will normally be collected immediately by the customer from the store but may
be selected for delivery to the customer's home address for which there will be a charge. If
stock is not available the sales assistant will be able to create a backorder for the product from
a regional warehouse. The products will then either be delivered direct from the regional
warehouse to the customer's home address, or to the store for collection by the customer. The
system will allow products to be paid for by cash or credit card. Credit card transactions will
be validated via an online card transaction system. The system will produce a receipt. Order
details for in-stock products will be printed in the warehouse including the bin reference,
quantity, product number and description. These will be collected by the sales assistant and
given to the customer. The sales assistant will be able to make refunds, provided a valid receipt
is produced. The sales assistant will also be able to check stock and pricing without creating an
order and progress orders that have been created for delivery.
The store manager will be able at any time to print a summary report of sales in the store for a
given period, including assignment of sales to sales assistants in order to calculate weekly sales
bonuses.
The stock manager will be able to monitor stock levels and weekly run-rates in order to set
minimum stock levels and requisition products which fall below the minimum stock levels or
for which demand is anticipated. When the stock arrives it will be booked in by the warehouse
person. Stock that has been backordered for collection from the store is held in a separate area
and the store manager advised of its arrival.
The catalogue of available products will be maintained remotely by marketing from head
office. Marketing will also be able to access sales information from each store system.
Lab Task
Draw the detailed use-case description keeping in mind the use case diagram created previously
of the requirement specifications described above.
10
BS (Software Engineering) 2023
LAB 4: Domain Model
Objective
In this lab, students will learn how to identify real-world objects, their attributes, associations and how
to model all this using Domain Model.
Theoretical Description
A Domain Model is used to represent entities and it illustrates meaningful concepts in a
problem domain. It may show concepts, associations between concepts and attributes of
concepts.
A UML domain model will relate objects in the system domain to each other. It will define concepts
and terms. Objects in the domain model can be:
* Physical objects
* Abstract concepts
List Objects (Concepts)
To help the development of a domain model, it is important to identify nouns and noun phrases.
Concepts that may not ultimately become objects may be listed for completeness and for discussion.
The following types of concepts should be listed:
* Actor roles
* Events
* Transactions
o Transaction line items
* Objects (physical)
o Containers
+ Items (in container)
o Other systems
o Organizations
Nouns can be taken from the requirements definitions and use case drawings. This means at this point
all your use case drawings should be done. Actors should not be emphasized in the domain model.
Domain Model Syntax
After the list of concepts is complete a domain model should be made. Consider which simple items
should be attributes of objects. The domain model is a static model. Time flow, with sequence of events
or information flow is not shown in the domain model. The objects in the domain model are candidates
for programming objects.
NOTE: Domain Models are created using Class Diagram notations.
1. Start MS Visio. Select Softwares and Databases category. Select UML Model
Diagrams.
2. Select Static Structure.
Class Structure:
11
BS (Software Engineering) 2023
Note: To modify this structure to suit needs of a domain model, right click it, select shape
display Options, Uncheck Operation Parameters from General group and Check Operations in
Suppress group.
Case Study: BATS System
The Bank Accounts and Transactions System (BATS) is to be built for the Prime Bank
Corporation. It must handle clients' bank accounts and the services on these accounts, i.e.,
deposit, withdraw, transfer, get balance, etc.
The transactions are recorded, because at the end of each month, the system sends out account
statements to all clients showing all transactions performed for their accounts during the last
period. The system sends the statements to the printer from where a junior clerk posts them.
The system is accessed by the bank's clients only indirectly, i.e., either via a teller, or an ATM,
or the Internet. All transactions and queries are possible via a teller; all transactions and queries
are possible except deposits via an ATM; and all except deposits and withdrawals via the
Internet. Opening an account can be performed only via a teller and the Internet; however, if a
client opens an account via the Internet they must identify themselves with a teller to have their
account activated (this is government policy to avoid money laundering, e.g.). Closing an
account can only be performed by a teller, and it requires a final statement to be sent out to the
client. The Bank offers various account types, which fall into two categories: savings and
checking. Savings accounts cannot be overdrawn. There can be a credit limit, subject to
agreement by the bank, on checking accounts; a checking account cannot be overdrawn beyond
this limit.
Lab Task
Develop a partial Domain model for the given BATS system. Identify the concepts, attributes,
and associations explicitly. This lab task submission must include:
1. List of possible conceptual classes
2. Attributes for each class
3. A partial domain model showing the conceptual classes and association between them.
12
BS (Software Engineering) 2023
LAB 5: Class Diagram
Objective
The aim of this lab is to introduce students to the concept of UML class diagrams. Scenario shall be
given to the user for which they shall have to create a class diagram.
Theoretical Description
The class diagram is used both for general conceptual modelling of the systematic of the
application, and for detailed modelling translating the models into programming code. It
describes the structure of a system by showing the system's classes, their attributes, operations
(or) methods and the relationships between the classes.
Class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that
describes the structure of a system by showing the system's classes, their attributes, operations (or)
methods and the relationships between the classes.
The class diagram is used both for general conceptual modeling of the systematic of the application,
and for detailed modeling translating the models into programming code. The classes in a class diagram
represent both the main objects and or interactions in the application and the objects to be programmed.
In the class diagram these classes are represented with boxes which contain three parts:
A class with three sections:
* The upper part holds the name of the class
* The middle part contains the attributes of the class
* The bottom part gives the methods or operations the class can take or undertake
For Example:
Composition Relationships
Each instance of type Circle seems to contain an instance of type Point. This is a relationship known as
composition. It can be depicted in UML using a class relationship.
The black diamond represents composition. It is placed on the Circle class because it is the Circle that
is composed of a Point. The arrowhead on the other end of the relationship denotes that the relationship
is navigable in only one direction. That is, Point does not know about Circle. In UML relationships are
presumed to be bidirectional unless the arrowhead is present to restrict them. If the arrowhead is
omitted, it would have meant that Point knew about Circle. At the code level, this would imply a
#include “circle.h” within point.h.
13
BS (Software Engineering) 2023
Composition relationships are a strong form of containment or aggregation. Aggregation is a whole/part
relationship. In this case, Circle is the whole, and Point is part of Circle. Composition also indicates that
the lifetime of Point is dependent upon Circle. This means that if Circle is destroyed, Point will be
destroyed with it.
Inheritance
The inheritance relationship in UML is depicted by a peculiar triangular arrowhead. This arrowhead
that looks rather like a slice of pizza, points to the base class. One or more lines proceed from the base
of the arrowhead connecting it to the derived classes.
Figure shows the form of the inheritance relationship. In this diagram we see that Circle and Square
both derive from Shape. Note that the name of class Shape is shown in italics. This indicates that Shape
is an abstract class. Note also that the operations, Draw () and Erase () are also shown in italics. This
indicates that they are pure virtual.
Aggregation / Association
The weak form of aggregation is denoted with an open diamond. This relationship denotes that the
aggregate class (the class with the white diamond touching it) is in some way the “whole”, and the other
class in the relationship is somehow “part” of that whole.
Interfaces
There are classes that have nothing but pure virtual functions. In Java such entities are not classes at all;
they are a special language element called an interface. UML has followed the Java example and has
created some special syntactic elements for such entities.
14
BS (Software Engineering) 2023
The primary icon for an interface is just like a class except that it has a special denotation called a
stereotype.
Alternate representation is the lollipop representation:
Lab Task
Create a class diagram for Next Generation Point of Sale Application.
The Domain Model is given below:
Reference: Applying UML and Patterns by Craig Larmen (Ch#12, Ch#16)
15
BS (Software Engineering) 2023
LAB 6: Interaction Diagrams: Sequence Diagram
Objective
The objective of this lab is to practice sequence diagrams.
Theoretical Description
UML sequence diagrams model the flow of logic within your system in a visual manner,
enabling you both to document and validate your logic, and are commonly used for both
analysis and design purposes.
Sequence diagrams are typically used to model:
1.
Usage scenarios. A usage scenario is a description of a potential way your system
is used. The logic of a usage scenario may be part of a use case, perhaps an alternate
course. It may also be one entire pass through a use case, such as the logic described
by the basic course of action or a portion of the basic course of action, plus one or
more alternate scenarios. The logic of a usage scenario may also be a pass through
the logic contained in several use cases. For example, a student enrolls in the
university, and then immediately enrolls in three seminars.
2.
The logic of methods. Sequence diagrams can be used to explore the logic of a
complex operation, function, or procedure. One way to think of sequence diagrams,
particularly highly detailed diagrams, is as visual object code.
3.
The logic of services. A service is effectively a high-level method, often one that
can be invoked by a wide variety of clients. This includes web-services as well as
business transactions implemented by a variety of technologies such as
CICS/COBOL or CORBA-compliant object request brokers (ORBs).
Case Study: ATM Cash Withdrawal
1. Brief Description
This use case describes how the Bank Customer uses the ATM to withdraw money to his/her
bank account.
2. Actors
Bank Customer
Bank
3. Preconditions
There is an active network connection to the Bank.
The ATM has cash available.
4. Basic Flow of Events
a) The use case begins when Bank Customer inserts their Bank Card.
b) Use Case: Validate User is performed.
16
BS (Software Engineering) 2023
c) The ATM displays the different alternatives that are available on this unit. In this
case the Bank Customer always selects “Withdraw Cash”.
d) The ATM prompts for an account.
e) The Bank Customer selects an account.
f) The ATM prompts for an amount.
g) The Bank Customer enters an amount.
h) Card ID, PIN, amount and account is sent to Bank as a transaction. The Bank
Consortium replies with a go/no go reply telling if the transaction is ok.
i) Then money is dispensed.
j) The Bank Card is returned.
k) The receipt is printed.
l) The use case ends successfully.
5. Alternative Flows
5.1 Invalid User
If in step 2 of the basic flow Bank Customer the use case: Validate User does not complete
successfully, then the use case ends with a failure condition
5.2 Wrong account
If in step 8 of the basic flow the account selected by the Bank Customer is not associated with
this bank card, then
1. The ATM shall display the message “Invalid Account – please try again”.
2. The use case resumes at step 4.
5.3 Wrong amount
If in step 7 in the basic flow, the Bank Customer enters an amount that can't be 'created' with
the kind of in the ATM, then
1. The ATM shall display the message indicating that the amount must be a multiple of the
bills on hand, and ask the Bank Customer to reenter the amount.
2. The use case resumes at step 7.
5.4 Amount Exceeds Withdrawal Limit
If in step 7 in the basic flow, the Bank Customer enters an amount that exceeds the
withdrawal limit (See Special Requirement WC-2 for maximum amount), then
1. The ATM shall display a warning message, and ask the Bank Customer to reenter the
amount
2. The use case resumes at step 7
5.5 Amount Exceeds Daily Withdrawal Limit
If in step 8 in the basic flow, the Bank response indicates the daily withdrawal limit has been
exceeded (this is determined by the Bank and depends upon the specific account), then
1. The ATM shall display a warning message, and ask the Bank Customer to reenter the
amount.
2. The use case resumes at step 7.
17
BS (Software Engineering) 2023
5.6 Insufficient Cash
If in step 7 in the basic flow, the Bank Customer enters an amount that exceeds the amount of
cash available in the ATM, then
1. The ATM will display a warning message, and ask the Bank Customer to reenter the
amount.
2. The use case resumes at step 7.
5.7 No Response from Bank
If in step 8 of the basic there is no response from the Bank within 3 seconds, then
1. The ATM will re-try, up to three times.
2. If there is still no response from the Bank, the ATM shall display the message “Network
unavailable – try again later”.
3. The ATM shall return the card.
4. The ATM shall indicate that it is “Closed”.
5. The use case ends with a failure condition.
5.8 Money Not Removed
If in step 9 of the basic flow the money is not removed from the machine within 15 seconds,
then
1. The ATM shall issue a warning sound and display the message “Please remove cash”.
2. If there is still no response from the Bank Customer within 15 seconds the ATM will retract the money and note the failure in the log.
3. The use case end with a failure condition.
5.9 Quit
If at point prior to step 8 in the basic flow the Bank Customer selects Quit, then
1. The ATM shall print a receipt indicating the transaction was cancelled.
2. The ATM shall return the card.
3. The use case ends.
6. Key Scenarios
6.1 No Response from Bank
7. Post-conditions
7.1 Successful Completion
The user has received their cash and the internal logs have been updated.
7.2 Failure Condition
The logs have been updated accordingly.
8. Special Requirements
The ATM shall dispense cash in multiples of $20.
The maximum individual withdrawal is $500.
[SpReq:WC-1] The ATM shall keep a log, including date and time, of all complete
and incomplete transactions with the Bank.
NOTE
18
BS (Software Engineering) 2023
1. Start MS Visio. Select Softwares and Databases category. Select UML Model
Diagrams.
2. Select Sequence Diagrams.
3. An actor notation can be added from the use-case diagram section and ‘Life Line’ object
can be used with it instead of an ‘Object Life Line’.
Lab Task
Draw the sequence diagram for the above mention case study
19
BS (Software Engineering) 2023
LAB 7: Activity Diagram
Objective
The aim of this lab is to introduce students to the concept of activity diagrams. The same shall
be drawn using MS Visio.
Theoretical Description
The purpose of the activity diagram is to model the procedural flow of actions that are part of
a larger activity.
In projects in which use cases are present, activity diagrams can model a specific use case at a
more detailed level. However, activity diagrams can be used independently of use cases for
modeling a business-level function, such as buying a concert ticket or registering for a college
class. Activity diagrams can also be used to model system-level functions, such as how a ticket
reservation data mart populates a corporate sales system's data warehouse.
How to Create Activity Diagram:
1. Go to FileNewSoftware & DatabaseUML Model Diagram.
2. Select UML Activity stencil from Shapes Menu.
3. If you want to indicate responsibility in the activity diagram, drag a Swimlane shape onto the
page for each class, person, or organizational unit you want to represent.
Create swimlanes in an activity diagram:
a. In an activity diagram, drag a Swimlane shape onto the drawing page.
b. Double-click the shape to add a name and other property values.
c. Repeat steps a, b until you've added all the partitions or organizational units you need.
d. Drag the side selection handles on the Swimlane shapes to make the lanes the size you
want.
e. Drag State, Action State, Object In State and Signal Receipt or Signal Send shapes
into the areas defined by the swimlanes and connect them using Control Flow and
Object Flow shapes.
4. Drag an Action State or State shape onto the drawing page for each action or activity state
you want to represent. Use the Initial State and Final State shapes to represent initial and final
pseudo states.
5. Connect Control Flow shapes to State shapes to indicate the change from one state to another.
Indicate the flow of control in an activity diagram:
a. In an activity diagram, drag a Control Flow shape onto the drawing page.
b. Glue the Control Flow shape endpoint (without the arrowhead) to a connection point
on the source Action State or State shape.
c. Glue the Control Flow shape endpoint (with an arrowhead) to a connection point on the
destination Action State or State shape.
20
BS (Software Engineering) 2023
d. Double-click the Control Flow shape to add a transition string, including an
event (event: An occurrence in Visio, such as a change to a shape formula or the deletion
of a page.), guard condition, action expression, and more.
6. Use the complex transition shapes, Transition (Fork) or Transition (Join), to represent the
forking of one action state into multiple parallel states, or the synchronization of multiple action
states into one state.
7. Double-click any shape to open its UML Properties dialog box where you can add a name,
transition string etc.
8. Save the diagram.
Lab Task
Create an activity diagram of the ATM Cash Withdrawal system explained in Lab 6.
21
BS (Software Engineering) 2023
Lab 8: Mid Lab Assessment
Objective
To evaluate the tasks taught up till now.
22
BS (Software Engineering) 2023
Lab 9: State Machine Diagram
Objective
Students will learn how to make a state machine diagram
Theoretical Description
State machine diagram typically are used to describe state-dependent behavior for an object.
An object responds differently to the same event depending on what state it is in. State
machine diagrams are usually applied to objects but can be applied to any element that has
behavior to other entities such as: actors, use cases, methods, subsystems systems and etc.
and they are typically used in conjunction with interaction diagrams (usually sequence
diagrams).
Example:
Consider you have $100,000 in a bank account. The behavior of the withdraw function would
be: balance := balance - withdrawAmount; provided that the balance after the withdrawal is
not less than $0; this is true regardless of how many times you have withdrawn money from
the bank. In such situations, the withdrawals do not affect the abstraction of the attribute
values, and hence the gross behavior of the object remains unchanged.
However, if the account balance would become negative after a withdrawal, the behavior of
the withdraw function would be quite different. This is because the state of the bank account
is changed from positive to negative; in technical jargon, a transition from the positive state
to the negative state is fired.
The abstraction of the attribute value is a property of the system, rather than a globally
applicable rule. For example, if the bank changes the business rule to allow the bank balance
to be overdrawn by 2000 dollars, the state of the bank account will be redefined with
condition that the balance after withdrawal must not be less than $2000 in deficit.
Note That: A state machine diagram describes all events (and states and transitions for a
single object) A sequence diagram describes the events for a single interaction across all
objects involved.
23
BS (Software Engineering) 2023
Example:
Lab Task
Make a State Machine for “ATM” system.
24
BS (Software Engineering) 2023
LAB 10: Component Diagram
Objective
In this lab students will learn how to construct a package diagram in MS Visio.
Theoretical Description
A package is used to group together classes that have some commonality. In UML, a package is
displayed with this symbol:
There are a few common approaches when packaging classes, but you can group the classes together
however you'd like. One approach is to group the classes together by functionality. For example, you
might have a package called Security, which holds all of the classes that deal with application security.
You might have some other packages called Employee Maintenance, Reporting, or Error Handling. The
advantage of this approach is in reuse. If you carefully group your classes together, you end up with
packages that are fairly independent of one another. In this example, you can just pick up the Security
package and reuse it in other applications. Packages can be nested inside each other to further organize
your classes.
How to Create a UML Component Diagram
1. On the File menu, point to New, point to Software, and then click UML Model Diagram.
2. In the tree view (tree view: Displayed in a window in the UML Navigator, a hierarchy in which
each UML element or view (diagram) is represented by an icon. The UML template
automatically creates a tree view of your model.), right-click the package (package: A
grouping of model elements represented in the UML by a symbol that resembles a manila file
folder. Each element in a system can be owned by only one package, and one package can be
nested in another.) You want to use as a container for other packages, point to New, and then
click Static Structure Diagram.
A blank page appears, and the UML Static Structure stencil becomes the top-most stencil.
The workspace displays 'Static Structure' as a watermark. An icon representing the diagram is
added to the tree view.
NOTE If the tree view is not visible, point to View on the UML menu, and then click Model
Explorer
3. In the tree view, click the name of the static structure diagram (static structure diagram: A
diagram that shows the static structure of a model; that is, the elements that exist (such as
classes and types), the internal structure of the elements, and their relationships to one another.)
icon, and then click the name again. Type a new name for the diagram.
4. Drag a Package shape from the UML Static Structure stencil onto the package diagram
drawing page to indicate one of the packages the top package contains. A package is added to
the tree view.
25
BS (Software Engineering) 2023
5. Double-click the new package shape to open the UML Package Properties dialog box. Type
a name for the package, such as SubPackage1, type and choose other property values, and then
click OK.
6. Right-click the SubPackage1 icon in the tree view, point to New, and then choose the type of
diagram you want to represent in the sub package.
7. In the tree view, click the name of the static structure diagram icon, and then click the name
again. Type a new name for the diagram, such as SubPackage1 Diagram.
An icon representing the diagram is added to the tree view and the appropriate stencil and a
blank drawing page appear.
8. Drag shapes onto the drawing page to represent the elements the sub package contains.
9. In the tree view, double-click the diagram icon for Package Diagram, and then repeat steps 3
through 7 until you have created all the sub packages you want.
Lab Task
Consider an online shopping portal which allows a customer to browse and purchase different products.
The products are arranged under different categories like Books, Computers, and Electronics etc.
Only a registered customer can order a product from this portal. Each registered customer will have his
own shopping cart. He can view, add or remove products in his shopping cart and view his total bill.
Final cart is submitted for payment and details like shipment address are confirmed by the customer.
Customer is confirmed with a shipment id and delivery of goods within 15 days.
Once customer finishes selecting the product/s, he can view the cart and then place the order by
providing details like postal address, number of items etc.
The website is managed by an Administrator. Administrator can add, remove and update categories,
products under each category, their price and quantity. He can also remove or verify customer.
Perform the following tasks:
Draw Use Case Diagrams
Group together related use cases into components.
Identify all possible classes.
Then group related classes into components.
26
BS (Software Engineering) 2023
Lab 12: Deployment Diagram
Objective
Students will be able to make deployment diagram.
Theoretical Description
A UML deployment diagram is a diagram that shows the configuration of run time processing
nodes and the components that live on them. Deployment diagrams is a kind of structure
diagram used in modeling the physical aspects of an object-oriented system. They are often be
used to model the static deployment view of a system (topology of the hardware).
When to Use Deployment Diagram
What existing systems will the newly added system need to interact or integrate with?
How robust does system need to be (e.g., redundant hardware in case of a system
failure)?
What and who will connect to or interact with system, and how will they do it
What middleware, including the operating system and communications approaches and
protocols, will system use?
What hardware and software will users directly interact with (PCs, network computers,
browsers, etc.)?
How will you monitor the system once deployed?
How secure does the system needs to be (needs a firewall, physically secure hardware,
etc.)?
Lab Task
Make deployment diagram for the known systems
27
BS (Software Engineering) 2023
LAB 13: Model View Controller (MVC)
Objective
The aim of this lab is to introduce students to the concept of Model View Controller Pattern.
A small application shall be designed using this pattern.
Theoretical Description
Model–view–controller (MVC) is a software architecture, currently considered an architectural pattern
used in software engineering. The pattern isolates "domain logic" (the application logic for the user)
from the user interface (input and presentation), permitting independent development, testing and
maintenance of each (separation of concerns).
A model is an object representing data, e.g. a database table.
A view is some form of visualization of the state of the model.
A controller offers facilities to change the state of the model.
Overview:
Though MVC comes in different flavours, control flow is generally as follows:
1. The user interacts with the user interface in some way (for example, by pressing a mouse
button).
2. The controller handles the input event from the user interface, often via a registered handler or
callback, and converts the event into an appropriate user action, understandable for the model.
3. The controller notifies the model of the user action, possibly resulting in a change in the model's
state. (For example, the controller updates the user's shopping cart.)
4. A view queries the model in order to generate an appropriate user interface (for example the
view lists the shopping cart's contents). The view gets its own data from the model. In some
implementations, the controller may issue a general instruction to the view to render itself. In
others, the view is automatically notified by the model of changes in state (Observer) that
require a screen update.
5. The user interface waits for further user interactions, which restarts the control flow cycle.
Lab Task
Create a Model-View Controller Design for the following scenario:
At the beginning of each semester students are given a course catalogue containing a list of course
offerings for the semester. Information about each course, such as professor, department, and
prerequisites will be included to help students make informed decisions.
The new on-line registration system will allow students to select courses for the coming semester. The
students will have to fill an online form in which they shall provide their personal information, their
academic information and their choice of courses. The information provided shall be stored in a
database which can include:
1.
Personal information
a.
Name
b.
Registration Number
c.
Contact Number
28
BS (Software Engineering) 2023
2.
Previous Academic History
a.
Previous Semester’s GPA
b.
Previous Semester’s courses.
3.
Financial Record
a.
Scholarship information (if held)
4.
Degree Program registered to.
5.
List of available electives from which the student can select the desired course.
6.
Information for courses
a.
Course/Subject Title
b.
Instructor
c.
Venue
d.
Date and Time
What you need to design:
Model: Database Design
View: Interface Design
Controller: Logic of the application (Class Diagrams)
29
BS (Software Engineering) 2023
LAB 14: GoF PATTERNS (FACTORY PATTERN,
SINGLETON PATTERN)
Objective
The objective of this lab is to demonstrate the application of Factory Pattern.
Theoretical Description
Factory Pattern
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory
Method lets a class defer instantiation to subclasses.
STRUCTURE:
Singleton Pattern
Ensure a class has only one instance and provide a global point of access to it.
STRUCTURE:
According to the Gang of Four, the Singleton's intent is to
“Ensure a class only has one instance, and provide a global point of access to it”.
The Singleton pattern works by having a special method that is used to instantiate the desired
object. Here is what is most interesting about this special method:
When this method is called, it checks to see whether the object has already been
instantiated. If it has, the method just returns a reference to the object. If not, the method
instantiates it and returns a reference to the new instance.
To ensure that this is the only way to instantiate an object of this type, define the
constructor of this class to be protected or private.
30
BS (Software Engineering) 2023
Lab Task
Task # 1
The classes and/or objects participating in this pattern are as given below. Create a class
diagram to represent the classes as given. You can use any other application/example that you
see fit for this design pattern.
Product (Page)
o defines the interface of objects the factory method creates
ConcreteProduct (SkillsPage, EducationPage, ExperiencePage)
o implements the Product interface
Creator (Document)
o declares the factory method, which returns an object of type Product. Creator
may also define a default implementation of the factory method that returns a
default ConcreteProduct object.
o may call the factory method to create a Product object.
ConcreteCreator (Report, Resume)
o overrides the factory method to return an instance of a ConcreteProduct.
Every program needs a way to report errors. Consider the following interface:
Listing 1
public interface Trace {
// turn on and off debugging
public void setDebug( boolean debug );
// write out a debug message
public void debug( String message );
// write out an error message
public void error( String message );
}
Suppose that you've written two implementations. One implementation (Listing 2) writes the
messages out to the command line, while another (Listing 3) writes them to a file.
Listing 2
public class FileTrace implements Trace {
private java.io.PrintWriter pw;
private boolean debug;
public FileTrace() throws java.io.IOException {
// a real FileTrace would need to obtain the filename somewhere
pw = new java.io.PrintWriter( new java.io.FileWriter( "c:\trace.log" ) );
}
public void setDebug( boolean debug ) {
this.debug = debug;
}
public void debug( String message ) {
if( debug ) { // only print if debug is true
pw.println( "DEBUG: " + message );
pw.flush();
}
31
BS (Software Engineering) 2023
}
public void error( String message ) {
// always print out errors
pw.println( "ERROR: " + message );
pw.flush();
}
}
Listing 3
public class SystemTrace implements Trace {
private boolean debug;
public void setDebug( boolean debug ) {
this.debug = debug;
}
public void debug( String message ) {
if( debug ) { // only print if debug is true
System.out.println( "DEBUG: " + message );
}
}
public void error( String message ) {
// always print out errors
System.out.println( "ERROR: " + message );
}
}
To use either of these classes, you would need to do the following:
Listing 4
//... some code ...
SystemTrace log = new SystemTrace();
//... code ...
log.debug( "entering loog" );
// ... etc ...
Problem: Now if you want to change the Trace implementation that your program uses, you'll
need to edit each class that instantiates a Trace implementation. Depending upon the number
of classes that use Trace, it might take a lot of work for you to make the change. Plus, you want
to avoid altering your classes as much as possible.
Demonstrate how Factory Method Design Pattern can solve the above mentioned issue.
TASK # 2
The classes and/or objects participating in this pattern are as given below. Create a class
diagram to represent the classes as given. You can use any other application/example that you
see fit for this design pattern.
Singleton (LoadBalancer)
o defines an Instance operation that lets clients access its unique instance.
Instance is a class operation.
o responsible for creating and maintaining its own unique instance.
32
BS (Software Engineering) 2023
LAB 15: DESIGN PATTERNS (FACADE, DECORATOR)
Objective
The aim of this lab is to introduce students to the concept design patterns.
Theoretical Description
Background
In software engineering, a design pattern is a general repeatable solution to a commonly occurring
problem in software design. A design pattern isn't a finished design that can be transformed directly
into code. It is a description or template for how to solve a problem that can be used in many different
situations.
Uses of Design Patterns:
Design patterns can speed up the development process by providing tested, proven development
paradigms. Effective software design requires considering issues that may not become visible until later
in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major
problems and improves code readability for coders and architects familiar with the patterns.
Creational design patterns
This design patterns is all about class instantiation. This pattern can be further divided into classcreation patterns and object-creational patterns. While class-creation patterns use inheritance effectively
in the instantiation process, object-creation patterns use delegation effectively to get the job done.
Abstract Factory
Creates an instance of several families of classes
Builder
Separates object construction from its representation
Factory Method
Creates an instance of several derived classes
Object Pool
Avoid expensive acquisition and release of resources by recycling objects that are no longer
in use
Prototype
A fully initialized instance to be copied or cloned
Singleton
A class of which only a single instance can exist
Structural design patterns
This design patterns is all about Class and Object composition. Structural class-creation patterns use
inheritance to compose interfaces. Structural object-patterns define ways to compose objects to obtain
new functionality.
Adapter
Match interfaces of different classes
Bridge
Separates an object’s interface from its implementation
33
BS (Software Engineering) 2023
Composite
A tree structure of simple and composite objects
Decorator
Add responsibilities to objects dynamically
Facade
A single class that represents an entire subsystem
Flyweight
A fine-grained instance used for efficient sharing
Private Class Data
Restricts accessor/mutator access
Proxy
An object representing another object
Behavioral design patterns
This design patterns is all about Class's objects communication. Behavioral patterns are those patterns
that are most specifically concerned with communication between objects.
Chain of responsibility
A way of passing a request between a chain of objects
Command
Encapsulate a command request as an object
Interpreter
A way to include language elements in a program
Iterator
Sequentially access the elements of a collection
Mediator
Defines simplified communication between classes
Memento
Capture and restore an object's internal state
Null Object
Designed to act as a default value of an object
Observer
A way of notifying change to a number of classes
State
Alter an object's behavior when its state changes
Strategy
Encapsulates an algorithm inside a class
Template method
Defer the exact steps of an algorithm to a subclass
Visitor
Defines a new operation to a class without change
Facade Pattern
Make a complex system simpler by providing a unified or general interface, which is a higher layer to
these subsystems.
Benefits of Facade Pattern
To reduce complexities of a system.
Decouple subsystems, reduce its dependency, and improve portability.
Make an entry point to your subsystems.
34
BS (Software Engineering) 2023
Minimize the communication and dependency between subsystems.
Security and performance consideration.
Shield clients from subsystem components.
Simplify generosity to specification.
Structure:
DECORATOR PATTERN
Attach additional responsibilities to an object dynamically. Decorators provide a flexible
alternative to subclassing for extending functionality.
Structure:
Lab Task
Task # 1
The classes and/or objects participating in this pattern are as given below. Create a class
diagram to represent the classes as given. You can use any other application/example that you
see fit for this design pattern.
35
BS (Software Engineering) 2023
Facade (Mortgage Application)
o
o
knows which subsystem classes are responsible for a request.
delegates client requests to appropriate subsystem objects.
Subsystem classes (Bank, Credit, Loan)
o
o
o
implement subsystem functionality.
handle work assigned by the Facade object.
have no knowledge of the facade and keep no reference to it.
Task # 2
The classes and/or objects participating in this pattern are as given below. Create a class
diagram to represent the classes as given. You can use any other application/example that you
see fit for this design pattern.
Component (LibraryItem)
defines the interface for objects that can have responsibilities added to them
dynamically.
ConcreteComponent (Book, Video)
o defines an object to which additional responsibilities can be attached.
o
Decorator (Decorator)
o
maintains a reference to a Component object and defines an interface that
conforms to Component's interface.
ConcreteDecorator (Borrowable)
o
adds responsibilities to the component.
36
BS (Software Engineering) 2023
LAB 16: GoF PATTERNS (OBSERVER PATTERN)
Objective
The objective of this lab is to demonstrate the application of Observer and Publish Subscriber
Pattern.
Theoretical Description
Observer Pattern
The Observer Pattern is a software design pattern in which an object, called the subject, maintains a
list of its dependents, called observers, and notifies them automatically of any state changes, usually by
calling one of their methods. It is mainly used to implement distributed event handling systems.
Publish/Subscribe Pattern
Publish–subscribe is a messaging pattern where senders of messages, called publishers, do not
program the messages to be sent directly to specific receivers, called subscribers. Instead, published
messages are characterized into classes, without knowledge of what, if any, subscribers there may be.
Similarly, subscribers express interest in one or more classes, and only receive messages that are of
interest, without knowledge of what, if any, publishers there are.
Lab Task
Consider the example where a head hunter is responsible of notifying all the registered
developers of any job opening that comes his way. All the developers in the list will be notified
of the job opening. Whenever there is some update from the head hunter, the notification is
sent to all the contacts in the list. The head hunter sends notification to all the developers
without knowing who they are. Any number of developers can subscribe to the head hunter’s
list.
By using the observer pattern, what will be structure and implementation for above
mentioned example?
37
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )