SlideShare a Scribd company logo
1 of 31
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 objectsPayel 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 3C# Learning Classes
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
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
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritanceharshaltambe
 
Implementation of interface9 cm604.30
Implementation of interface9 cm604.30Implementation of interface9 cm604.30
Implementation of interface9 cm604.30myrajendra
 
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 DevelopmentEduardo 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 4mohamedsamyali
 
11. Objects and Classes
11. Objects and Classes11. Objects and Classes
11. Objects and ClassesIntro C# Book
 

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 Implementing UML Diagrams in Code

Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Effective java-3rd-edition-ch4
Effective java-3rd-edition-ch4Matt
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.pptMikeAdva
 
Question and answer Programming
Question and answer ProgrammingQuestion and answer Programming
Question and answer ProgrammingInocentshuja Ahmad
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingRenas 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 principlesmaznabili
 
Object oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsObject oriented programming Fundamental Concepts
Object oriented programming Fundamental ConceptsBharat 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 javaCPD INDIA
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritancebunnykhan
 
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 Implementing UML Diagrams in Code (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

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
 
Application and database migration workshop
Application and database migration workshopApplication and database migration workshop
Application and database migration workshopReham 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 organizationsReham 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 cloudReham Maher El-Safarini
 

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

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 

Recently uploaded (20)

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 

Implementing UML Diagrams in Code

  • 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.