0% found this document useful (0 votes)
19 views

Lecture 4 - Some Advanced Design Techniques by UML

The document discusses advanced object-oriented design techniques using the Unified Modeling Language (UML). It covers popular abstract data types like lists, stacks, and queues. It then discusses modeling these concepts using UML diagrams, including use case diagrams, class diagrams, state diagrams, activity diagrams, communication diagrams, and sequence diagrams. Finally, it walks through a case study of modeling an automated teller machine (ATM) system using various UML diagrams and design techniques like inheritance and polymorphism.
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)
19 views

Lecture 4 - Some Advanced Design Techniques by UML

The document discusses advanced object-oriented design techniques using the Unified Modeling Language (UML). It covers popular abstract data types like lists, stacks, and queues. It then discusses modeling these concepts using UML diagrams, including use case diagrams, class diagrams, state diagrams, activity diagrams, communication diagrams, and sequence diagrams. Finally, it walks through a case study of modeling an automated teller machine (ATM) system using various UML diagrams and design techniques like inheritance and polymorphism.
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/ 54

Lecture 4

Some Advanced Design


Techniques by UML
MAIN CONTENT

Some popular abstract data types


Techniques for object-oriented design
in UML
ABSTRACT
DATA TYPES
Concept of Abstract Data Type (ADT)

 ADTs are entities that are definitions


of data and operations but do not have
implementation details
 Store data
 Allows various operations on the data to
access or change it
Why abstract ?

 Specify the operations of the data


structure and leave implementation
details for later
 High-level languages often provide built-
in data structures
The core operation

 Every collection ADT should provide a


way to:
o Add an item
o Remove an item
o Find, retrieve or access an item
Additional operations

 More possibilities:
o Is the collection empty ?
o Make the collection empty
o Give a subset of the collection
Program logic formulation
ADT in Data Structures
ADT in Data Structure
Java Abstract Data Type

 Java ADT in a data structure is a type of data type


whose behaviour is defined by a set of operations and
values

 In Java ADT, we can only know what operations are to


be performed and not how to perform them

 This type is thus called abstract as it does not give


the view of implementation
Java Abstract Data Type
List ADT
A list ADT is the type of o get() – Return an element from the list.
list which contains similar
o insert() – Insert an element at any position.
elements in sequential order
o remove() – Remove the first occurrence of any
element from a non-empty list.

o removeAt() – Remove the element at a


predefined area from a non-empty list.

o Replace() – Replace an element by another


element.

o size() – Returns number of elements of the list.

o isEmpty() – Return true if the list is empty, else


return false.

o isFull() – Return true only if the list is full, else


return false.
List ADT
typedef struct node
{
void *DataPtr;
struct node *link;
} Node;
typedef struct
{
int count;
Node *pos;
Node *head;
Node *rear;
int (*compare) (void *argument1,
void *argument2)
} LIST;
Stack ADT
A stack ADT contains similar
elements which are in an o push() – Insert an element at the top of
ordered sequence. All the stack.
operations in stack takes
place at the top of the o pop() – Remove an element from the top of
stack. the stack, If it is not empty.

o peep() – Returns the top element of stack


without removing it.

o size() – Returns the size of the stack.

o isEmpty() – Return true if the stack is


empty, else it returns false.

o isFull() – Return true if the stack is full,


else it returns false.
Stack ADT
typedef struct node
{
void *DataPtr;
struct node *link;
} StackNode;
typedef struct
{
int count;
StackNode *top;
} STACK;
Queue ADT
The elements of the queue ADT o enqueue() – Inserting an element at the
are of the same type which are
end of queue.
arranged sequentially. The
operations can be performed at o dequeue() – Removing an element of the
both ends, insertion is done at
rear end, deletion is done at queue.
the front end.
o peek() – Returns the element of the queue
without removing it.

o size() – Returns the number of elements in


the queue.

o isEmpty() – Return true if the queue is


empty, else it returns false.

o isFull() – Return true if the queue is full,


else it returns false.
Queue ADT

typedef struct node


{
void *DataPtr;
struct node *next;
} QueueNode;
typedef struct
{
QueueNode *front;
QueueNode *rear;
int count;
} QUEUE;
UML DIAGRAMS
REVISION
Use Case Diagram Revision
Use Case Diagram Revision
Use Case Diagram Revision
Use Case Diagram Revision
Class Diagram Revision
Class Diagram Revision
Class Diagram Revision
Class Diagram Revision
Class Diagram Revision
Class Diagram Revision
Sequence Diagram Revision
OBJECT ORIENTED
DESIGN WITH UML
(A CASE STUDY)
Step 1- Examine the ATM requirements

Hardware requirements:
o A screen
o A keypad
o A cash dispenser
o A deposit slot

Automated Teller Machine (ATM) user interface


Step 1- Examine the ATM requirements

Sequence of events:
1. Screen displays welcome
and prompts the user to
enter account number
2. User input account number
3. Screen prompts user to
enter PIN
4. User enters PIN
5. System validates PIN. If
correct, displays main
menu. If incorrect, restarts
the step 1
ATM withdrawal menu
Step 1- Examine the ATM requirements
Withdrawal sequences:
1. Screen displays menu
2. User enters menu selection
3. System validates the
chosen amount. If invalid,
return to step 1, else move
to step 4
4. If enough cash, moves to
step 5. Otherwise, shows a
message then return to
step 1
5. ATM subtracts the
withdrawal amount in
user’s account balance ATM withdrawal menu
6. ATM dispenses desired
amount to user
7. Screens show reminders to
user to take the money
Step 1- Examine the ATM requirements

Use case diagram for the ATM system from the User’s view
Step 2 - Identify the Classes

Representing a class in the UML using a class diagram

Class diagram showing an association among classes


Step 2 - Identify the Classes

Class diagram showing composition relationships


Step 2 - Identify the Classes

Class diagram for the ATM system model


Step 3 - Identify the Class Attributes

Classes with attributes


Step 4 - Identify the Object’s States & Activities

State diagram for the ATM object

Activity diagram for a BalanceInquiry transaction


Step 4 - Identify the Object’s States & Activities

Activity diagram
for a Withdrawal
transaction
Step 5 - Identify the Class Operations

Classes in the
ATM system
with attributes
and operations
Step 5 - Identify the Class Operations

Class BankDatabase

Class Screen Class CashDispenser

Class Account
Step 6 - Indicate collaboration among objects

Collaborations in the
ATM system
Step 6 - Indicate collaboration among objects

Communication diagram of the ATM


executing a balance inquiry

Communication diagram for


executing a balance inquiry
Step 6 - Indicate collaboration among objects

Sequence diagram that


models a Withdrawal
executing
Implement the ATM system from its UML design

Initial code for class Withdrawal

Incorporate private variables for class Withdrawal


Implement the ATM system from its UML design

Incorporate private reference handles for the


associations of the class Withdrawal
Implement the ATM system from its UML design

Incorporate method Execute in class Withdrawal


Incorporate inheritance and polymorphism into ATM system

Attributes and operations of classes BalanceInquiry,


Withdrawal and Deposit

Class diagram modelling the generalization (ex: inheritance) relationship


between the base class Transaction and its derived classes BalanceInquiry,
Withdrawal and Deposit
Incorporate inheritance and polymorphism into ATM system

Class diagram of the ATM system (incorporating inheritance)


Abstract class name Transaction appears in italics
Incorporate inheritance and polymorphism into ATM system

Code for shell


of class
Withdrawal

Code for class


Withdrawal
ATM Case Study Implementation

Task: Complete working implementation of the ATM system


Refer the file ATM Case Study Code for detail Java code

Sample code for class ATM


THANK YOU
FOR LISTENING !

You might also like