Chapter5 System Modeling
Chapter5 System Modeling
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()
Page 1 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106
Page 2 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106
Dependency
Dependency occurs when one objects must be informed about another.
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.
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
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
EMPLOYEE
Is an
(aggregation,
inheritance)
FITNESS-CLASS SCHEDULE
FITNESS-CLASS
REGISTRATION Adds
RECORD STUDENT
(association)
Page 8 of 9
CHAPTER 5 IDENTIFYING CLASSES & OBJECTS RELATIONSHIPS ICT1106
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.
Page 9 of 9