0% found this document useful (0 votes)
15 views

Chapter5 System Modeling

The document discusses classes, relationships among objects and classes, and different types of relationships including dependency, association, aggregation, and inheritance. It provides examples for each type of relationship like a school bus following a bus route or a doctor being a superclass of surgeon and family doctor subclasses.

Uploaded by

Elias Zaid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Chapter5 System Modeling

The document discusses classes, relationships among objects and classes, and different types of relationships including dependency, association, aggregation, and inheritance. It provides examples for each type of relationship like a school bus following a bus route or a doctor being a superclass of surgeon and family doctor subclasses.

Uploaded by

Elias Zaid
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS

Major Topic Covered


- Classes
- Relationships Among Objects And Classes

A) Class
- is a groups of similar objects which share common attributes and methods
- Objects within a class can be grouped into subclasses which are more specific categories
within a class
- A class can belong to a more general category called a superclass.

Example 1

Example 2:
Doctor
-workAtHospital
+treatPatient()

*
* * *

Surgeon
FamilyDoctor
-makeHouseCall
+treatPatient()
+giveAdvice()
+makeDecision()

o Doctor is the superclass, Surgeon and Family Doctor are subclasses.

Page 1 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106

o The treatPatient() method is overridden in the Surgeon class.


o The Surgeon class adds the method makeIncision().

o The FamilyDoctor class has a new instance variable makesHouseCalls.


o Adds a new method, giveAdvice().

o Surgeon has 1 instance variable, worksAtHospital, inherited from Doctor


o FamilyDoctor has 2 instance variables, one inherited and one of its own.
o Surgeon has 2 methods. FamilyDoctor has 2 as well.
o FamilyDoctor can treatPatient() but CANNOT makeIncision(). The latter method belongs
to another subclass.

B) Relationship among Objects


Relationships enable objects to communication and interact as they perform business functions
and transactions required by the system.
Dependence, Aggregation and Inheritance are type of relationship.

Relationship Concept Example


Dependency Uses - a A circle uses a point.

Association Has – a A car has passengers, they come and go

Aggregation Has a by value An car has an engine


(stronger Aggregation
relationship than Composition
association)
Inheritance Is - a A square is a polygon
(generalization /
specialization) polygon square

Page 2 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106

Dependency
 Dependency occurs when one objects must be informed about another.

SCHOOL BUS BUS ROUTE

Attributes Attributes
Bus number Route number
Route number Stop number
Start time Stop location
Finish time Follows Stop time
Driver Passengers

Methods Methods
Pick up Add stop
Drop off Delete stop
Change time

 An object dependency exists when there is a short-term relationship between the objects.
 For example, the relationship between a shopping cart and a checkout object would be short
term, since once the checkout operation is completed, the checkout object would no longer be
needed.
 Another example, a stock transfer object that needed to use a stock item object to get the
information on the stock item being transferred. The stock transfer object would have a
dependency relationship with the stock item object; the stock transfer object would read the
transfer information and could then discard the stock item object and continue processing.

Page 3 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106

Association
 Association is stronger than a dependency and occurs when certain attributes of one objects
determined by its interaction with another object. For example, a STUDENT object can
add/drop fitness class information on a REGISTRATION RECORD object.

STUDENT REGISTRATION RECORD

Attributes
Attributes Student number
Student number Fitness-class number
Name Adds / Registration date
Address Drops Fee
Telephone fitness Status
Date of birth class
The status or Fitness record
status of the Status
student changes
when he or she Methods
adds or drops a Add a student
fitness-class. Methods Drop a student
Add student Notify instructor of
Delete student student add
Add fitness-class Notify instructor of
Drop fitness-class student drop
Change telephone Notify all of fitness-
Change status
class cancellations
Update fitness
record

State Status
 Future
An object association represents
Registered, but hasanot
more long-term
started association than the dependency
to attend.
relationship. Registered, attending one or more fitness-classes
Current
 Past
The controlling object will
oneobtain a reference
orSTUDENT to thein
association
the past object and then use the
Attended more Object
fitness-classes
reference to call methods on the object.

Page 4 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106

Example 1
The relationship between a car and a driver is representative of association relationship. The car
will have a driver who will be associated with the car for a period of time.

drives
Driver Car

Example 2
A radiologist consults a lawyer.

AGGREGATION
- Exists when an object forms part of another object. For example, EMPLOYEE object is
belongs to a DEPARTMENT object.
- Is stronger than as association or a dependency relationship

Example 1

EMPLOYEE DEPARTMENT

Attributes Attributes
Name Department number
Date of birth Department name
Social security number Budget code
Telephone number Department head
Belongs to
Hire date Employees
Title
Pay rate
Department number

Methods
Prepare budget
Hire employees
Develop plans
Methods
Get
Pagehired
5 of 9
Terminate
Change department
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106

Example 2
A FileReader object that has been created using a File object represents a mutual dependency
where the two objects combine to create a useful mechanism for reading characters from a file.

FileReader File

Example 3
A room has a chair, a computer and desk.

Room

Chair Computer Desk

Example 4
A car consists of a chassis, an engine, wheels, and seats.

Page 6 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106

Inheritance
Inheritance enables an object to derive one or more of its attributes from another objects.
Inheritance is specific to object-oriented programming, where a new class is created from an
existing class. Inheritance (often referred to as subclasses) comes from the fact that the subclass
(the newly created class) contains the attributes and methods of the parent class.

EMPLOYEE INSTRUCTOR

Attributes Attributes
Social security number Type of instructor
Telephone number
Hire date Social security number
Title Telephone number
Pay rate Hire date
Title
Pay rate

Methods Methods
Get hired
Get fired Get hired
Change department Get fired
Change department

Page 7 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106

Object Relationship Diagram


This model shows the objects and how they interact to perform business functions and
transactions.

EMPLOYEE

Is an
(aggregation,
inheritance)

MANAGER OFFICE STAFF INSTRUCTOR

Determines Administers Indicates Teaches


(Association) (association) Availability (dependency)
(association)

FITNESS-CLASS SCHEDULE
FITNESS-CLASS

Lists open fitness- Generates Takes


classes Roster/schedule (dependency)
(dependency) (dependency)

REGISTRATION Adds
RECORD STUDENT
(association)

Page 8 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106

Apply your knowledge

Here is a class diagram showing a number of classes. It shows sales made by salespersons. Each
sale may be local or external, and is made by one salesperson. Each sale is made up of a number
of items, each of which has a price.

What is the kind of relationship between the following classes?

SALES and SALESPERSONS - association


SALES and ITEMS-IN-SALE - dependency
SALES and LOCAL-SALES - aggregation

Page 9 of 9

You might also like