Title: BCS 2143
1BCS 2143
- Object Oriented Design Using UML
2Objectives
- Objects Interactions
- Finding Classes
- Relationship Between Classes
- Attribute and Operation
- Class Diagram
3Outline
- 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
4Unified 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.
5UML 2.0
Emphasizes the dynamic behavior of the system by
showing collaborations among objects and changes
to the internal states of objects
Emphasizes the static structure of the system
using objects, attributes, operations and
relationships
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.
6Use 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
7Example of Use Case Diagram for ATM Machine
Customer
Make transaction
Manage bank transaction
Bank Clerk
Bank
Produce report
ATM Maintainer
Maintain ATM Machine
8Class 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
9Example 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.
10Interaction 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
11Sequence Diagram
12Collaboration Diagram
13Classes 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 objectshow they
behave and what kinds of information they
maintain called a class. - An object is called an instance of a class.
14Graphical Representation of a Class
15Graphical Representation of an Object
16An Object with the Class Name
17Messages 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.
18Sending a Message
myWindow.setVisible(true) personA.deposit( 250.0
) student.setName(john) car1.startEngine( )
Examples
19Sending a Message and Getting an Answer
20Calling a Class Method
21Class 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.
22Sample Instance Data Value
All three BankAccount objects possess the same
instance data value current balance.
The actual dollar amounts are, of course,
different.
23Sample Class Data Value
24Object Icon with Class Data Value
25Class
- 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
26Class/Attribute/Method/Object
Student
Class
name age course fees
Attribute (variable)
registerSubject withdrawSubject borrowBook
Method (operation)
Object
Object
StdDiploma
Std1
27Java Code Class, Attribute, Method Declaration
public class Student // class name String
name // attribute _at_ variable
declaration int age 10 String course
DCS double fees 1067.60 public void
registerSubject () // code for
register subject
28Java 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)
29Relationships among Classes
- Association
- Aggregation
- Composition
- Inheritance
30Association
- Association represents a general binary
relationship that describes an activity between
two classes.
An association is usually represented as a data
field in the class.
31Aggregation
- 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.
32Example of Aggregation
33Composition
- 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
34Example of Composition
35Aggregation 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
36Inheritance
- 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.
37A Sample of Inheritance
- Here are the superclass Vehicle and its
subclasses Car, Boat and Truck.
Truck
38Inheritance
- 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 /
39Inheritance Hierarchy
- An example of inheritance hierarchy among
different types of students.
40Example of class diagram with multiplicities,
attributes and operations
41Key Concepts
- Variable
- Constant
- Inheritance
- Superclass
- Subclass
- OOP
- Class
- Object
- Message
- Class and instance methods
- Instance and class data values
42Q A