SlideShare a Scribd company logo
1
Chapter 5
Implementing UML
Specification
(Part I)
Object-Oriented Technology
From Diagram to Code with Visual Paradigm for UML
Curtis H.K. Tsang, Clarence S.W. Lau and Y.K.
Leung
McGraw-Hill Education (Asia), 2005
2
Objectives
 After you have read this chapter, you
should be able to
 implement a class diagram;
 implement a state diagram;
 implement an activity diagram; and
 implement sequence and
collaboration diagrams.
3
Class
class SampleClass {
private int privateAttribute;
protected double protectedAttribute;
long packageAttribute;
public boolean publicAttribute;
public boolean publicMethod(int parameter1) {
…
}
private float privateMethod(byte parameter1,float parameter2) {
…
}
protected double protectedMethod() {
…
}
void packageMethod(short parameter1) {
…
}
}
A Single Class
4
Inheritance
 Single inheritance can be easily implemented by
super class and subclass in most OO programming
languages.
 Multiple inheritances may not be supported in some
OO programming languages.
 Replace some of the inheritances by interfaces.
5
Inheritance
class SubClass:BaseClass {
…
}
Inheritance

6
Inheritance (cont’d)
interface BaseInterface {
// declaration of methods
….
}
class ConcreteClass : BaseInterface
{
// implementation of
// methods of the
// interface BaseInterface
…
}
Inheritance

7
Inheritance (cont’d)
8
class Class2: Class1, Interface3 {
…
define attributes from class2
define operations from interface3
}
Inheritance (cont’d)
9
One-to-one Association
(cont’d)
class ClassA {
ClassB _b;
// declare attributes
// for the
// association class
…
}
class ClassB {
ClassA _a;
…
}
One-to-one
Association

10
One-to-many Association
(cont’d)
class ClassA {
Vector _b; // or
hashtable
…
}
class ClassB {
ClassA _a;
// declare attributes
// for association
// class
}
One-to-many
Association

11
One-to-many Association
(cont’d)
class ClassA {
Vector _Bs;
public ClassA() {
_Bs = new Vector();
…
}
public Enumeration getBs() {
return(_Bs.elements());
}
12
One-to-many Association
(cont’d)
// remove the link between ClassB object to this
// object
public void removeB(ClassB b) {
_Bs.remove(b);
}
public void addB(ClassB b) {
_Bs.add(b);
}
// other functions for searching objects in the
// vector
…
}
13
Qualified Association (cont’d)
class ClassA {
Hashtable _b;
…
}
class ClassB {
ClassA _a;
// declare attributes
// for association
// class
…
}
One-to-many
Association

14
Qualified Association (cont’d)
class ClassA {
private Hashtable _Bs;
public ClassA() {
_Bs = new Hashtable();
}
public Enumeration getBs() {
return(_Bs.elements());
}
public void addB(ClassB b, int key) {
_ClassBs.put(new Key(key), b);
}
15
Qualified Association (cont’d)
public void removeClassB(ClassB b) {
_ClassBs.remove(b);
}
public ClassB getClassB(int key) {
return((ClassB) _Bs.get(new Key(key)));
}
} // ClassA
16
Qualified Association (cont’d)
class Key {
int _key;
public ClassB(int key) {
_key = key;
}
public boolean equals(Object obj) {
if (obj instanceof Key)
return(((Key) obj)._key == _key);
else
return(false);
}
public int hashCode() {
return(_key);
}
}// Key
17
Many-to-many Association
(cont’d)
 Many-to-many Association
 If the association does not have additional
attributes, we can use a vector or a
hashtable on each side.
 If the association has attribute(s), a distinct
association class is needed for holding the
links between the objects and storing the
additional attributes of the association.
18
Implementation of Association Class
 One-to-one association. Assign the
attributes of the association class to
one of the classes of the association.
 One-to-many association. Assign the
attributes of the association class to the
class on the many side.
 Many-to-many association. Implement
the association class as a distinct class.
19
Example – One-to-many Association
20
Example – One-to-many Association
(cont’d)
class Car {
private int EngineNo;
private int ChasisNo;
private int OwnershipYear;
private int OwnershipMonth;
private int OwnershipDay;
…
}
21
Example - Many-to-many
Association
Registration
9080
9807
6782
9878
1111
1234
1242
9080
9807
6782
9878
1111
1234
1242Peter Chan
Alan Tong
John Lee
Venice Tsui
Mary Lui
TWGS
KCTS
LKP
CMT
KKY
Example of
objects and links
Many-to-many
Association
22
Example – Many-to-many
Association (cont’d)
class School {
private String _name;
private Vector _registrations;
public School(String name) {
_name = name;
_registrations = new Vector();
}
public void setName(String name) {
_name = name;
}
public String getName() {
return(_name);
}
23
Example – Many-to-many
Association (cont’d)
// school class continues
public void addRegistration(Registration reg) {
_registrations.add(reg);
}
public void removeRegistration(Registration reg) {
_registrations.remove(reg);
}
public Enumeration getStudents() {
int i;
Vector students = new Vector();
for (i = 0; i < _registrations.size(); i++)
students.add(((Registration) _registrations.elementAt(i)).getStudent());
return(students.elements());
}
} // school
24
Example – Many-to-many
Association (cont’d)
class Person {
private String _name;
private Vector _registrations;
public Person(String name) {
_name = name;
_registrations = new Vector();
}
String getName() {
return(_name);
}
void setName(String name) {
_name = name;
}
25
Example – Many-to-many
Association (cont’d)
// Class Person continues
public void addRegistration(Registration reg) {
_registrations.add(reg);
}
public void removeRegistration(Registration reg) {
_registrations.remove(reg);
}
public Enumeration getSchools() {
int i;
Vector schools = new Vector();
for (i = 0; i < _registrations.size(); i++)
schools.add(((Registration) _registrations.elementAt(i)).getSchool());
return(schools.elements());
}
} // Person
26
Example – Many-to-many
Association (cont’d)
class Registration {
private Person _student;
private School _school;
private int _studentNo;
private Registration(Person student, School school, int studentNo) {
_school = school;
_student = student;
_studentNo = studentNo;
}
static public void register(Person student, School school, int studentNo) {
Registration reg = new Registration(student, school, studentNo);
school.addRegistration(reg);
student.addRegistration(reg);
}
27
Example – Many-to-many
Association (cont’d)
// Class Registration continues
public void deregister() {
this._school.removeRegistration(this);
this._student.removeRegistration(this);
}
public School getSchool() {
return(_school);
}
public Person getStudent() {
return(_student);
}
} // class Registration
28
Example – Many-to-many
Association (cont’d)
public class Main3 {
public static void main(String argv[]) {
int i;
String schoolNames[] = {"TWGS", "KCTS", "LKP", "CMT", "KKY"};
String studentNames[] = {"Peter Chan", "Alan Tong", "John Lee", "Venice
Tsui", "Mary Lui"};
Person students[] = new Person[5];
School schools[] = new School[5];
for (i = 0; i < 5; i++) {
students[i] = new Person(studentNames[i]);
schools[i] = new School(schoolNames[i]);
}
29
Example – Many-to-many
Association (cont’d)
Registration.register(students[0], schools[0], 1241);
Registration.register(students[1], schools[1], 1234);
Registration.register(students[2], schools[1], 1111);
Registration.register(students[3], schools[2], 9878);
Registration.register(students[4], schools[3], 6782);
Registration.register(students[4], schools[4], 9807);
Registration.register(students[4], schools[0], 9080);
Enumeration s = Registration.getSchools("Mary Lui");
System.out.println("Mary Lui studies in the following schools:");
for (;s.hasMoreElements();) {
System.out.println (((School) s.nextElement()).getName());
}
}
}
30
Composition & Aggregation
 Aggregation can be implemented as a plain
association.
 Composition is a special case of aggregation. The
parts of the whole object is deleted before the whole
object is deleted.
31
Persistent Classes
 Persistent objects have long life spans and need to
be stored in permanent storage media, such as hard
disk.
 Usually a database system is used to store the
persistent objects.
 Two choices of database technologies: OO database
vs Relational database.
 Relational database is more mature and commonly
used technology.
 Need to map the classes into database tables if
relational database is used.

More Related Content

What's hot

class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Learn Concept of Class and Object in C# Part 3
Learn Concept of Class and Object in C#  Part 3Learn Concept of Class and Object in C#  Part 3
Learn Concept of Class and Object in C# Part 3
C# Learning Classes
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Inheritance
InheritanceInheritance
Inheritance
Pranali Chaudhari
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
farhan amjad
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
Majid Saeed
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
rajveer_Pannu
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
harshaltambe
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30
myrajendra
 
Chapter1 - Introduction to Object-Oriented Programming and Software Development
Chapter1 - Introduction to Object-Oriented Programming and Software DevelopmentChapter1 - Introduction to Object-Oriented Programming and Software Development
Chapter1 - Introduction to Object-Oriented Programming and Software Development
Eduardo Bergavera
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
mohamedsamyali
 
Object and class
Object and classObject and class
Object and class
mohit tripathi
 
11. Objects and Classes
11. Objects and Classes11. Objects and Classes
11. Objects and Classes
Intro C# Book
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
Avinash Kapse
 
java tutorial 2
 java tutorial 2 java tutorial 2
java tutorial 2
Tushar Desarda
 
Basic c#
Basic c#Basic c#
Basic c#
kishore4268
 
C++ oop
C++ oopC++ oop
C++ oop
Sunil OS
 

What's hot (20)

class and objects
class and objectsclass and objects
class and objects
 
Learn Concept of Class and Object in C# Part 3
Learn Concept of Class and Object in C#  Part 3Learn Concept of Class and Object in C#  Part 3
Learn Concept of Class and Object in C# Part 3
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30
 
Chapter1 - Introduction to Object-Oriented Programming and Software Development
Chapter1 - Introduction to Object-Oriented Programming and Software DevelopmentChapter1 - Introduction to Object-Oriented Programming and Software Development
Chapter1 - Introduction to Object-Oriented Programming and Software Development
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
C# Summer course - Lecture 4
C# Summer course - Lecture 4C# Summer course - Lecture 4
C# Summer course - Lecture 4
 
Object and class
Object and classObject and class
Object and class
 
11. Objects and Classes
11. Objects and Classes11. Objects and Classes
11. Objects and Classes
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
java tutorial 2
 java tutorial 2 java tutorial 2
java tutorial 2
 
Basic c#
Basic c#Basic c#
Basic c#
 
C++ oop
C++ oopC++ oop
C++ oop
 

Similar to Jar chapter 5_part_i

Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4
Matt
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
shubhra chauhan
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
henokmetaferia1
 
Design pattern
Design patternDesign pattern
Design pattern
Thibaut De Broca
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
MikeAdva
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
Inocentshuja Ahmad
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
chetanpatilcp783
 
Intake 37 4
Intake 37 4Intake 37 4
Intake 37 4
Mahmoud Ouf
 
06 inheritance
06 inheritance06 inheritance
06 inheritance
ROHINI KOLI
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
farhan amjad
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Renas Rekany
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
Abu Saleh
 
20 Object-oriented programming principles
20 Object-oriented programming principles20 Object-oriented programming principles
20 Object-oriented programming principles
maznabili
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
Tushar Desarda
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
Amritsinghmehra
 
Object oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsObject oriented programming Fundamental Concepts
Object oriented programming Fundamental Concepts
Bharat Kalia
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
Mahmoud Alfarra
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
bunnykhan
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Boro
 

Similar to Jar chapter 5_part_i (20)

Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Design pattern
Design patternDesign pattern
Design pattern
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer Programming
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 
Intake 37 4
Intake 37 4Intake 37 4
Intake 37 4
 
06 inheritance
06 inheritance06 inheritance
06 inheritance
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
20 Object-oriented programming principles
20 Object-oriented programming principles20 Object-oriented programming principles
20 Object-oriented programming principles
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Object oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsObject oriented programming Fundamental Concepts
Object oriented programming Fundamental Concepts
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 

More from Reham Maher El-Safarini

Ux
Ux Ux
Global threat-landscape report by fortinet.
Global threat-landscape report by fortinet.Global threat-landscape report by fortinet.
Global threat-landscape report by fortinet.
Reham Maher El-Safarini
 
Dynamics AX/ X++
Dynamics AX/ X++Dynamics AX/ X++
Dynamics AX/ X++
Reham Maher El-Safarini
 
Microsoft sql-and-the-gdpr
Microsoft sql-and-the-gdprMicrosoft sql-and-the-gdpr
Microsoft sql-and-the-gdpr
Reham Maher El-Safarini
 
AWS Cloud economics
AWS Cloud economicsAWS Cloud economics
AWS Cloud economics
Reham Maher El-Safarini
 
Cloud skills development
Cloud skills developmentCloud skills development
Cloud skills development
Reham Maher El-Safarini
 
AWS cloud adoption framework (caf)
AWS cloud adoption framework (caf)AWS cloud adoption framework (caf)
AWS cloud adoption framework (caf)
Reham Maher El-Safarini
 
Application and database migration workshop
Application and database migration workshopApplication and database migration workshop
Application and database migration workshop
Reham Maher El-Safarini
 
Containers on AWS
Containers on AWSContainers on AWS
Containers on AWS
Reham Maher El-Safarini
 
Security and governance with aws control tower and aws organizations
Security and governance with aws control tower and aws organizationsSecurity and governance with aws control tower and aws organizations
Security and governance with aws control tower and aws organizations
Reham Maher El-Safarini
 
Digital transformation on aws
Digital transformation on awsDigital transformation on aws
Digital transformation on aws
Reham Maher El-Safarini
 
Security in the cloud
Security in the cloudSecurity in the cloud
Security in the cloud
Reham Maher El-Safarini
 
2. migration, disaster recovery and business continuity in the cloud
2. migration, disaster recovery and business continuity in the cloud2. migration, disaster recovery and business continuity in the cloud
2. migration, disaster recovery and business continuity in the cloud
Reham Maher El-Safarini
 
1. aws overview
1. aws overview1. aws overview
1. aws overview
Reham Maher El-Safarini
 
Pgp
PgpPgp
ssl for securing
ssl for securingssl for securing
ssl for securing
Reham Maher El-Safarini
 
03 unity 3_d_part_2
03 unity 3_d_part_203 unity 3_d_part_2
03 unity 3_d_part_2
Reham Maher El-Safarini
 
02 unity 3_d_part_1
02 unity 3_d_part_102 unity 3_d_part_1
02 unity 3_d_part_1
Reham Maher El-Safarini
 
01 unity 3_d_introduction
01 unity 3_d_introduction01 unity 3_d_introduction
01 unity 3_d_introduction
Reham Maher El-Safarini
 
unity basics
unity basicsunity basics

More from Reham Maher El-Safarini (20)

Ux
Ux Ux
Ux
 
Global threat-landscape report by fortinet.
Global threat-landscape report by fortinet.Global threat-landscape report by fortinet.
Global threat-landscape report by fortinet.
 
Dynamics AX/ X++
Dynamics AX/ X++Dynamics AX/ X++
Dynamics AX/ X++
 
Microsoft sql-and-the-gdpr
Microsoft sql-and-the-gdprMicrosoft sql-and-the-gdpr
Microsoft sql-and-the-gdpr
 
AWS Cloud economics
AWS Cloud economicsAWS Cloud economics
AWS Cloud economics
 
Cloud skills development
Cloud skills developmentCloud skills development
Cloud skills development
 
AWS cloud adoption framework (caf)
AWS cloud adoption framework (caf)AWS cloud adoption framework (caf)
AWS cloud adoption framework (caf)
 
Application and database migration workshop
Application and database migration workshopApplication and database migration workshop
Application and database migration workshop
 
Containers on AWS
Containers on AWSContainers on AWS
Containers on AWS
 
Security and governance with aws control tower and aws organizations
Security and governance with aws control tower and aws organizationsSecurity and governance with aws control tower and aws organizations
Security and governance with aws control tower and aws organizations
 
Digital transformation on aws
Digital transformation on awsDigital transformation on aws
Digital transformation on aws
 
Security in the cloud
Security in the cloudSecurity in the cloud
Security in the cloud
 
2. migration, disaster recovery and business continuity in the cloud
2. migration, disaster recovery and business continuity in the cloud2. migration, disaster recovery and business continuity in the cloud
2. migration, disaster recovery and business continuity in the cloud
 
1. aws overview
1. aws overview1. aws overview
1. aws overview
 
Pgp
PgpPgp
Pgp
 
ssl for securing
ssl for securingssl for securing
ssl for securing
 
03 unity 3_d_part_2
03 unity 3_d_part_203 unity 3_d_part_2
03 unity 3_d_part_2
 
02 unity 3_d_part_1
02 unity 3_d_part_102 unity 3_d_part_1
02 unity 3_d_part_1
 
01 unity 3_d_introduction
01 unity 3_d_introduction01 unity 3_d_introduction
01 unity 3_d_introduction
 
unity basics
unity basicsunity basics
unity basics
 

Recently uploaded

Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
RidwanHassanYusuf
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
IsmaelVazquez38
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
 

Recently uploaded (20)

Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptxBIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
BIOLOGY NATIONAL EXAMINATION COUNCIL (NECO) 2024 PRACTICAL MANUAL.pptx
 
Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.Bossa N’ Roll Records by Ismael Vazquez.
Bossa N’ Roll Records by Ismael Vazquez.
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
 

Jar chapter 5_part_i

  • 1. 1 Chapter 5 Implementing UML Specification (Part I) Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML Curtis H.K. Tsang, Clarence S.W. Lau and Y.K. Leung McGraw-Hill Education (Asia), 2005
  • 2. 2 Objectives  After you have read this chapter, you should be able to  implement a class diagram;  implement a state diagram;  implement an activity diagram; and  implement sequence and collaboration diagrams.
  • 3. 3 Class class SampleClass { private int privateAttribute; protected double protectedAttribute; long packageAttribute; public boolean publicAttribute; public boolean publicMethod(int parameter1) { … } private float privateMethod(byte parameter1,float parameter2) { … } protected double protectedMethod() { … } void packageMethod(short parameter1) { … } } A Single Class
  • 4. 4 Inheritance  Single inheritance can be easily implemented by super class and subclass in most OO programming languages.  Multiple inheritances may not be supported in some OO programming languages.  Replace some of the inheritances by interfaces.
  • 6. 6 Inheritance (cont’d) interface BaseInterface { // declaration of methods …. } class ConcreteClass : BaseInterface { // implementation of // methods of the // interface BaseInterface … } Inheritance 
  • 8. 8 class Class2: Class1, Interface3 { … define attributes from class2 define operations from interface3 } Inheritance (cont’d)
  • 9. 9 One-to-one Association (cont’d) class ClassA { ClassB _b; // declare attributes // for the // association class … } class ClassB { ClassA _a; … } One-to-one Association 
  • 10. 10 One-to-many Association (cont’d) class ClassA { Vector _b; // or hashtable … } class ClassB { ClassA _a; // declare attributes // for association // class } One-to-many Association 
  • 11. 11 One-to-many Association (cont’d) class ClassA { Vector _Bs; public ClassA() { _Bs = new Vector(); … } public Enumeration getBs() { return(_Bs.elements()); }
  • 12. 12 One-to-many Association (cont’d) // remove the link between ClassB object to this // object public void removeB(ClassB b) { _Bs.remove(b); } public void addB(ClassB b) { _Bs.add(b); } // other functions for searching objects in the // vector … }
  • 13. 13 Qualified Association (cont’d) class ClassA { Hashtable _b; … } class ClassB { ClassA _a; // declare attributes // for association // class … } One-to-many Association 
  • 14. 14 Qualified Association (cont’d) class ClassA { private Hashtable _Bs; public ClassA() { _Bs = new Hashtable(); } public Enumeration getBs() { return(_Bs.elements()); } public void addB(ClassB b, int key) { _ClassBs.put(new Key(key), b); }
  • 15. 15 Qualified Association (cont’d) public void removeClassB(ClassB b) { _ClassBs.remove(b); } public ClassB getClassB(int key) { return((ClassB) _Bs.get(new Key(key))); } } // ClassA
  • 16. 16 Qualified Association (cont’d) class Key { int _key; public ClassB(int key) { _key = key; } public boolean equals(Object obj) { if (obj instanceof Key) return(((Key) obj)._key == _key); else return(false); } public int hashCode() { return(_key); } }// Key
  • 17. 17 Many-to-many Association (cont’d)  Many-to-many Association  If the association does not have additional attributes, we can use a vector or a hashtable on each side.  If the association has attribute(s), a distinct association class is needed for holding the links between the objects and storing the additional attributes of the association.
  • 18. 18 Implementation of Association Class  One-to-one association. Assign the attributes of the association class to one of the classes of the association.  One-to-many association. Assign the attributes of the association class to the class on the many side.  Many-to-many association. Implement the association class as a distinct class.
  • 20. 20 Example – One-to-many Association (cont’d) class Car { private int EngineNo; private int ChasisNo; private int OwnershipYear; private int OwnershipMonth; private int OwnershipDay; … }
  • 21. 21 Example - Many-to-many Association Registration 9080 9807 6782 9878 1111 1234 1242 9080 9807 6782 9878 1111 1234 1242Peter Chan Alan Tong John Lee Venice Tsui Mary Lui TWGS KCTS LKP CMT KKY Example of objects and links Many-to-many Association
  • 22. 22 Example – Many-to-many Association (cont’d) class School { private String _name; private Vector _registrations; public School(String name) { _name = name; _registrations = new Vector(); } public void setName(String name) { _name = name; } public String getName() { return(_name); }
  • 23. 23 Example – Many-to-many Association (cont’d) // school class continues public void addRegistration(Registration reg) { _registrations.add(reg); } public void removeRegistration(Registration reg) { _registrations.remove(reg); } public Enumeration getStudents() { int i; Vector students = new Vector(); for (i = 0; i < _registrations.size(); i++) students.add(((Registration) _registrations.elementAt(i)).getStudent()); return(students.elements()); } } // school
  • 24. 24 Example – Many-to-many Association (cont’d) class Person { private String _name; private Vector _registrations; public Person(String name) { _name = name; _registrations = new Vector(); } String getName() { return(_name); } void setName(String name) { _name = name; }
  • 25. 25 Example – Many-to-many Association (cont’d) // Class Person continues public void addRegistration(Registration reg) { _registrations.add(reg); } public void removeRegistration(Registration reg) { _registrations.remove(reg); } public Enumeration getSchools() { int i; Vector schools = new Vector(); for (i = 0; i < _registrations.size(); i++) schools.add(((Registration) _registrations.elementAt(i)).getSchool()); return(schools.elements()); } } // Person
  • 26. 26 Example – Many-to-many Association (cont’d) class Registration { private Person _student; private School _school; private int _studentNo; private Registration(Person student, School school, int studentNo) { _school = school; _student = student; _studentNo = studentNo; } static public void register(Person student, School school, int studentNo) { Registration reg = new Registration(student, school, studentNo); school.addRegistration(reg); student.addRegistration(reg); }
  • 27. 27 Example – Many-to-many Association (cont’d) // Class Registration continues public void deregister() { this._school.removeRegistration(this); this._student.removeRegistration(this); } public School getSchool() { return(_school); } public Person getStudent() { return(_student); } } // class Registration
  • 28. 28 Example – Many-to-many Association (cont’d) public class Main3 { public static void main(String argv[]) { int i; String schoolNames[] = {"TWGS", "KCTS", "LKP", "CMT", "KKY"}; String studentNames[] = {"Peter Chan", "Alan Tong", "John Lee", "Venice Tsui", "Mary Lui"}; Person students[] = new Person[5]; School schools[] = new School[5]; for (i = 0; i < 5; i++) { students[i] = new Person(studentNames[i]); schools[i] = new School(schoolNames[i]); }
  • 29. 29 Example – Many-to-many Association (cont’d) Registration.register(students[0], schools[0], 1241); Registration.register(students[1], schools[1], 1234); Registration.register(students[2], schools[1], 1111); Registration.register(students[3], schools[2], 9878); Registration.register(students[4], schools[3], 6782); Registration.register(students[4], schools[4], 9807); Registration.register(students[4], schools[0], 9080); Enumeration s = Registration.getSchools("Mary Lui"); System.out.println("Mary Lui studies in the following schools:"); for (;s.hasMoreElements();) { System.out.println (((School) s.nextElement()).getName()); } } }
  • 30. 30 Composition & Aggregation  Aggregation can be implemented as a plain association.  Composition is a special case of aggregation. The parts of the whole object is deleted before the whole object is deleted.
  • 31. 31 Persistent Classes  Persistent objects have long life spans and need to be stored in permanent storage media, such as hard disk.  Usually a database system is used to store the persistent objects.  Two choices of database technologies: OO database vs Relational database.  Relational database is more mature and commonly used technology.  Need to map the classes into database tables if relational database is used.