42
BCS 2143 Object Oriented Design Using UML

BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Embed Size (px)

Citation preview

Page 1: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

BCS 2143

Object Oriented Design Using UML

Page 2: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Objectives

Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class Diagram

Page 3: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Outline Name the basic components of object-oriented

design using UML

Experience with significant diagram in UML

Experience with main part of class that consists of attributes and operation

Class Diagram; association, aggregation and inheritance

Basic concepts in Sequence Diagram

Utilize all modeling concepts in solving problem

Page 4: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Unified Modeling Language UML - standardized general-purpose

modeling language in the field of software engineering using graphical notations

UML Diagrams: Use Case Diagram Class Diagram Interaction Diagram Component Diagram Etc.

Page 5: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

UML 2.0

UML 2.0 has 13 types of diagrams divided into three categories. Six diagram types represent the structure application, seven represent general types of behavior, including four that represent different aspects of interactions.

Emphasizes the static structure of the system using objects, attributes, operations and relationships

Emphasizes the dynamic behavior of the system by showing collaborations among objects and changes to the internal states of objects

Page 6: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Use Case Diagram

System behavior – how the system act and react towards their environment.

Consists of: Actor – represent environment of system

Use case – represent function of system

Page 7: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Example of Use Case Diagram for ATM Machine

Customer

Bank Clerk

Make transaction

Manage bank transaction

ATM Maintainer

Bank

Maintain ATM Machine

Produce report

Page 8: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Class Diagram

Diagram that consists of several classes or objects.

Object : represent specific entity in term of physical and

conceptual have the behaviors, characteristics and identity

Class : Represent a group of object that have the similar

attribute, behavior and relationship among the others

Page 9: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Example of Class Diagram

Class diagram: describes the structure of a system by showing the system's classes, their attributes, and the relationships among the classes.

Page 10: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Interaction Diagram

Represent string of messages that have been submit and receive and its relation

Example of 2 types: Sequence diagram – based on

sequence of time frame Collaboration diagram – represent

the data flow

Page 11: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Sequence Diagram

Page 12: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Collaboration Diagram

Registration Windows

Timetable Windows

Course Offered

1: Enter ID2: Enter current semester

3: Create new timetable

4: Display

5: Get the course

: Johan:Student

Page 13: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Classes and Objects

Object-oriented programs use objects. An object is a thing, both tangible and

intangible. Account, Vehicle, Employee, etc. To create an object inside the computer

program, we must provide a definition for objects—how they behave and what kinds of information they maintain —called a class.

An object is called an instance of a class.

Page 14: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Graphical Representation of a Class

<Class Name>We use a rectangle to represent a class with its name appearing inside the rectangle.

We use a rectangle to represent a class with its name appearing inside the rectangle.

Example: Account Motorcycle

Page 15: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Graphical Representation of an Object

<Object Name>

We use a rectangle to represent an object and place the underlined name of the object inside the rectangle.

We use a rectangle to represent an object and place the underlined name of the object inside the rectangle.

Example:

PersonA This is an object named PersonA.

This is an object named PersonA.

Page 16: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

An Object with the Class Name

<Object Name> : <Class Name>

This notation indicates the class which the object is an instance.

This notation indicates the class which the object is an instance.

This tells an object PersonA is an instance of the BankAccount class.

This tells an object PersonA is an instance of the BankAccount class.

Example:

PersonA : BankAccount

Page 17: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Messages and Methods To instruct a class or an object to perform a

task, we send a message to it. A class or an object must possess a matching

method to be able to handle the received message.

A method defined for a class is called a class method, and a method defined for an object is called an instance method.

A value we pass to an object when sending a message is called an argument of the message.

Page 18: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Sending a Message

deposit(250.00)

Message deposit with the argument 250.00 is sent to a BankAccount object PersonA.

Message deposit with the argument 250.00 is sent to a BankAccount object PersonA.

PersonA : BankAccount

ExamplesmyWindow.setVisible(true);personA.deposit( 250.0 );student.setName(“john”);car1.startEngine( );

Page 19: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Sending a Message and Getting an Answer

current balance

getCurrentBalance()

Ask for the current balance of this particular account.

Ask for the current balance of this particular account.

PersonA : BankAccount

The current balance of PersonA is returned.

The current balance of PersonA is returned.

Page 20: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Calling a Class Method

maximum speed

MobileRobot

getMaximumSpeed()

Ask for the maximum possible speed for all MobileRobot objects is returned.

Ask for the maximum possible speed for all MobileRobot objects is returned.

Page 21: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Class and Instance Data Values An object is comprised of data values and

methods. An instance data value is used to maintain

information specific to individual instances. For example, each BankAccount object maintains its balance.

A class data value is used to maintain information shared by all instances or aggregate information about the instances.

For example, minimum balance is the information shared by all Account objects, whereas the average balance of all BankAccount objects is an aggregate information.

Page 22: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Sample Instance Data Value

Ani : BankAccount Siti : BankAccountAli : BankAccount

current balance current balance current balance908.55 1304.98 354.00

All three BankAccount objects possess the same instance data value current balance.

All three BankAccount objects possess the same instance data value current balance.

The actual dollar amounts are, of course, different.

The actual dollar amounts are, of course, different.

Page 23: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Sample Class Data Value

Ani : BankAccount Siti : BankAccountAli : BankAccount

current balance current balance current balance908.55 1304.98 354.00

BankAccount

minimum balance

100.00

There is one copy of minimum balance for the whole class and shared by all instances.

There is one copy of minimum balance for the whole class and shared by all instances.

This line is an instance-of relationship.

This line is an instance-of relationship.

Page 24: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Object Icon with Class Data Value

When the class icon is not shown, we include the class data value in the object icon itself.

When the class icon is not shown, we include the class data value in the object icon itself.

Ali : BankAccount

current balance908.55

minimum balance

100.00

Page 25: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Class

Class name Start with capital letter for each new word Example : Student, StudentAdvisory

Attributes Represent the characteristics of the object Variables,

Operation Represent the behavior of the class Methods, behaviors

Page 26: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Class/Attribute/Method/Object

Student

nameage

coursefees

registerSubject withdrawSubject

borrowBook

Std1

Class

Attribute(variable)

Method(operation)

ObjectStdDiplomaObject

Page 27: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Java Code : Class, Attribute, Method Declaration

public class Student { // class nameString name; // attribute @ variable

declarationint age =10;

String course = “DCS” ;double fees = 1067.60;

public void registerSubject (){ // code for register subject}…

}

Page 28: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Java Code : Object Declaration / Manipulation

public Class Student{…

public static void main (String data[]){ Student stdDiploma ; // declaring/creating an object stdDiploma = new Student() ; // object initialize Student Std1 = new Student() ; // declaration and

initialize Std1.name = " Amad“ ; // assigning value to object Std1.age = 24 ; // assigning value to object System.out.println(" student name : " + Std1.name) ; System.out.println(" student age registration : " +

Std1.age) ; }

}

Page 29: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Association Aggregation Composition Inheritance

Relationships among Classes

Page 30: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

AssociationAssociation represents a general binary relationship that describes an activity between two classes.

Student * 5..60 Take Teach

0..3 1 Teacher

Faculty Course

public class Student {

/** Data fields */ private Course[]

courseList;

/** Constructors */

/** Methods */

}

public class Course {

/** Data fields */ private Student[]

classList;

private Faculty faculty;

/** Constructors */

/** Methods */

}

public class Faculty {

/** Data fields */

private Course[]

courseList;

/** Constructors */

/** Methods */

}

An association is usually represented as a data field in the class.

Page 31: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Aggregation

Whole-to-part associations The concept representing the

whole is called the aggregate; each concept representing a part is called constituent.

The aggregate and the constituent may existed independently of each other.

Page 32: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Example of Aggregation

Student Club

Advisor Member

1 ... * 1 ... *

1 1 ... *

Page 33: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Composition Whole-to-part associations The concept representing the whole is

called the composite; each concept representing a part is called component

The composite does not exist independently from its component

The component may exist without the composite

Page 34: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Example of Composition

Chair

Back Seat

1 1

Frame

1

Arm Rest

2

Page 35: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Aggregation vs Composition

AGGREGATION COMPOSITION

Name of whole Aggregate Composite

Name of part Constituent Component

Parts May be different types

Usually the same type

Existence May exist without its parts

Does not exist without its parts

Number of wholes to which a part may belong

Part may belong to more than one aggregate at a time

Part may belong to only one composite at a time

Page 36: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Inheritance

Inheritance is a mechanism in OOP to design two or more entities that are different but share many common features. Features common to all classes are defined in

the superclass. The classes that inherit common features from

the superclass are called subclasses. We also call the superclass an ancestor and the

subclass a descendant.

Page 37: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

A Sample of Inheritance

Here are the superclass Vehicle and its subclasses Car, Boat and Truck.

Vehicle

Car Boat Truck

Page 38: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Inheritance

Inheritance models the is-an-extension-of relationship between two classes.

public class Car extends Vehicle { /** Data fields */ /** Constructors */ /** Methods */}

public class Boat extends Vehicle { /** Data fields */ /** Constructors */ /** Methods */}

Page 39: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Inheritance Hierarchy

An example of inheritance hierarchy among different types of students.

Law Masters Doctoral Commuting Resident

Student

Graduate Undergrad

Page 40: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Example of class diagram with multiplicities, attributes and operations

Page 41: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Key Concepts

OOP

Class

Object

Message

Class and instance

methods

Instance and class data

values

Variable

Constant

Inheritance

Superclass

Subclass

Page 42: BCS 2143 Object Oriented Design Using UML. Objectives Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class

Q & A