• Tidak ada hasil yang ditemukan

3 OBJECT ORIENTED ANALYSIS

3.1 OBJECTS AND CLASSES

An object represents a real world item such as a bicycle or a person, and it contains both data and methods (operations) for processing the object’s data. The object’s data is stored as a set of attributes and these data values are hidden so as to prevent direct access from outside; this is called encapsulation.

Objects have different states during their lifetime and these states are altered by events.

Objects belong to a class, which is a group of similar objects. A class consists of a name, a set of attributes and a set of methods and is represented as shown below. For example, a racing cycle belongs to the class named bicycle. A class is the specification template for a set of objects and has attributes and methods. Each object (instance) of the class will have a particular set of attribute values and any instance of the class will be able to carry out the class methods in response to the appropriate message.

Class name

Class attributes

Class methods

Fig 3.1 shows an object class

Download free eBooks at bookboon.com

Example objects (instances) of the PERSON class:-

Barbara De Silva 21/02/86

Female 7 Av. Atlântica Rio DeJaneiro Brazil

+55 21 2323232

Mike Smith 12/06/87 Male

6 Long Row Leeds

United Kingdom +44 770454545

Ahmet Aslam 12/03/85 Male

At Meydan No:222 Sultan Ahmet Istanbul Turkey

+90 202 527 0239

Fig 3.2 Person Objects

Exercise 1

Identify three business classes for a university system. For each class identify three attributes and two methods (operations).

Download free eBooks at bookboon.com

Exercise 1 feedback

Class Attributes Methods

Student Student name

Student address Student D.O.B.

Amend address Enrol on course

Module Module name

Module length Module level

Add module Alter module level

Lecturer Lecturer name

Lecturer office Lecturer telno.

Add lecturer Amend office

Object classes can be arranged into a hierarchy in which a “sub-class” inherits the characteristics of the “super-class” The sub-class has all the attributes and methods that the super-class has.

This is called inheritance. The sub-class can have additional attributes and methods and can be broken down further into more detailed sub-classes.

Download free eBooks at bookboon.com Click on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read more

By 2020, wind could provide one-tenth of our planet’s electricity needs. Already today, SKF’s innovative know- how is crucial to running a large proportion of the world’s wind turbines.

Up to 25 % of the generating costs relate to mainte- nance. These can be reduced dramatically thanks to our systems for on-line condition monitoring and automatic lubrication. We help make it more economical to create cleaner, cheaper energy out of thin air.

By sharing our experience, expertise, and creativity, industries can boost performance beyond expectations.

Therefore we need the best employees who can meet this challenge!

The Power of Knowledge Engineering

Brain power

Plug into The Power of Knowledge Engineering.

Visit us at www.skf.com/knowledge

To alter data within an object a message must be sent to the object asking it to perform an appropriate method. A message “add person” would cause the PERSON class to add a new instance of PERSON with values for its attributes (providing class PERSON has a method to add new person). Likewise, a message “Enrol” sent from LECTURER to STUDENT would enrol the student on a course.

Fig 3.3 Sub-classes and super-classes

In the above example the STUDENT and LECTURER classes are sub-classes of the super- class PERSON and inherit the attributes and methods of the super-class.

A particular message can be sent to different objects and result in different actions being taken. For example, the following model shows a class SYMBOL which has sub-classes SQUARE and CIRCLE. If the message “Draw” is sent to the SQUARE object a square shape will be drawn; however, if the same message is sent to the CIRCLE object a circle will be drawn. This ability to interpret messages differently depending on the object is called polymorphism.

Download free eBooks at bookboon.com

Message: Draw

Fig 3.4 Polymorphism

Download free eBooks at bookboon.com Click on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read moreClick on the ad to read more

Exercise 2

Identify two sub-classes for the STUDENT class shown above in Fig 3.3. For each of the sub-classes identify two attributes and two methods which would not be in the super-class student.

Exercise 2 feedback

Sub-class Attributes Methods

Undergraduate student Personal tutor Student status

Assign personal tutor Amend status Postgraduate student Research group

Research supervisor

Add supervisor Amend research group

Full-time and Part-time students could also be considered for sub-classes of STUDENT.

Object relationship diagrams provide an overview of the system objects and how they interact, and can provide a useful overview of the system.

STUDENT Studies MODULE Teaches LECTURER

Fig 3.5 Object relationship diagram