Upload
stanley-mccoy
View
222
Download
3
Embed Size (px)
Citation preview
BCS 2143
Object Oriented Design Using UML
Objectives
Objects Interactions Finding Classes Relationship Between Classes Attribute and Operation Class Diagram
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
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.
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
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
Example of Use Case Diagram for ATM Machine
Customer
Bank Clerk
Make transaction
Manage bank transaction
ATM Maintainer
Bank
Maintain ATM Machine
Produce report
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
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.
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
Sequence Diagram
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
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.
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
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.
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
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.
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( );
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.
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.
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.
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.
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.
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
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
Class/Attribute/Method/Object
Student
nameage
coursefees
registerSubject withdrawSubject
borrowBook
Std1
Class
Attribute(variable)
Method(operation)
ObjectStdDiplomaObject
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}…
}
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) ; }
}
Association Aggregation Composition Inheritance
Relationships among Classes
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.
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.
Example of Aggregation
Student Club
Advisor Member
1 ... * 1 ... *
1 1 ... *
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
Example of Composition
Chair
Back Seat
1 1
Frame
1
Arm Rest
2
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
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.
A Sample of Inheritance
Here are the superclass Vehicle and its subclasses Car, Boat and Truck.
Vehicle
Car Boat Truck
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 */}
…
Inheritance Hierarchy
An example of inheritance hierarchy among different types of students.
Law Masters Doctoral Commuting Resident
Student
Graduate Undergrad
Example of class diagram with multiplicities, attributes and operations
Key Concepts
OOP
Class
Object
Message
Class and instance
methods
Instance and class data
values
Variable
Constant
Inheritance
Superclass
Subclass
Q & A