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

Introduction To Object Orientation

njgjgjkjgj

Uploaded by

Jia Wei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Introduction To Object Orientation

njgjgjkjgj

Uploaded by

Jia Wei
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Introduction to Object Orientation

Object-Oriented Analysis & Design – Module 1


Slide 1
Objectives

In this chapter we will:


 Introduce some Object Oriented concepts
 Introduce the concept of an object as an instance
of a class
 Discuss Encapsulation
 Discuss Inheritance
 Discuss Polymorphism

Object-Oriented Analysis & Design – Module 1


Slide 2
What is Object Technology?

Object Technology (OT) covers:

 Object Oriented Analysis (OOA)


 Object Oriented Design (OOD)
 Object Oriented Programming (OOP)
 Object Oriented Databases (ODBMS)

Object-Oriented Analysis & Design – Module 1


Slide 3
What is Object Oriented?

 The Object Oriented (OO) approach to software


development is based on a method of thinking
about the world in abstract terms
 We identify objects in the world around us in
terms of „things‟, properties of things and the
actions that things perform
 Objects are instances of a specific class
 For example you may think of Book as a class and a
specific instance of the class Book is an object
 The Object Oriented style of development takes
this approach and uses it to implement software

Object-Oriented Analysis & Design – Module 1


Slide 4
Why Object Oriented?

 Modern life depends on computers


 As computers become more powerful we expect
more from them
 Software systems are very very complex not easily
understood and are becoming more so all the time
 Traditional software techniques cannot offer the
same benefits as OO in tackling these problems

Object-Oriented Analysis & Design – Module 1


Slide 5
What are the problems with Software?

 Complexity
 Reliability
 Interoperability
 Maintainability
 Extendibility
 Re-Usability

Object-Oriented Analysis & Design – Module 1


Slide 6
What are the Traditional techniques?

 Procedural Programming (C, Pascal, ADA etc.)


 Functional Programming (LISP, ML)
 Logic Programming (Prolog)

 Structured Analysis and Design


 SSADM
 JSP

Object-Oriented Analysis & Design – Module 1


Slide 7
Why don’t they work ?

 Well, actually they do


 But at a cost !
 Most commercial software is still built using
procedural techniques
 Most modern software is BIG and very complex,
even for tasks such as word processing
 Finding and fixing design faults and bugs is time
consuming and costly
 Maintenance costs are VERY high

Object-Oriented Analysis & Design – Module 1


Slide 8
How does OT help?

 Re-use of existing designs and code


 Faster development
 More Robust solutions
 Less code
 Less complexity
 Less maintenance

Object-Oriented Analysis & Design – Module 1


Slide 9
What is an object?

 An object is an instance of a class


 An object has:
an identity
state and behaviour - what do computers hold?
a purpose or responsibility or role
 An object may:
provide a service for other objects (be a server)
require other objects to provide information for its own
purpose (be a client requiring a service)
 An object may send a message to another object
to request a service

Object-Oriented Analysis & Design – Module 1


Slide 10
A food dispensing machine: an object

For example consider a food dispensing machine;


an example of an object
How do you use the object?
 put the coin in
 press the right button
 food appears
 press another button
 change appears
You don‟t need to know what happens behind the
scenes; as long as it does what it is supposed to
and delivers the food you are happy

Object-Oriented Analysis & Design – Module 1


Slide 11
A food dispensing machine: an object

What happens if the mechanisms inside are


completely overhauled and changed?
 You don‟t care
 You only care if the interface is changed
 You care if the buttons don‟t work as you expect
 You care if the change isn‟t right

 You should think of interacting with the machine


as sending a message to the object (the machine)
 The machine is responding with a return object
(the food), resulting from an action

Object-Oriented Analysis & Design – Module 1


Slide 12
A bank account

 A bank account is another example of an object;


an instance of a class
 You interact with the account by sending
messages:
 send message: obtain balance
 send message: withdraw money
 send message: deposit money
 send message: obtain interest

Object-Oriented Analysis & Design – Module 1


Slide 13
A Person object

 What state and behaviour might this object have?


Identity

data State

procedures/functions Behaviour

 different ones for different purposes


 the purpose of the object is very important
 send message: age
 Date of birth and so on
Object-Oriented Analysis & Design – Module 1
Slide 14
A Person object -State (data)

The state of a Person object may be defined by data


such as:

 name (of person, not name of object!)


 address
 age
 insurance number
 passport number

Object-Oriented Analysis & Design – Module 1


Slide 15
A Person object - Some methods

 Example of state and behaviour

Person

name data
address
setName
procedures/functions
getName

Object-Oriented Analysis & Design – Module 1


Slide 16
A Person object

The state may or may not be changed


Methods have to be provided to change the state
How the state is changed is hidden to any outside
objects

In the example we see two kinds of methods


one that asks for information about the state
of the object - an „object‟ (value) is returned
one that changes the state of the object –
information to change the state is passed as
an argument

Object-Oriented Analysis & Design – Module 1


Slide 17
A Person belonging to an institution

 Think of the kinds of people you might find within


this institution
 What do you need to know about them?
form a hierarchy of information (data)
 Does it depend on the the
role/responsibility/purpose of the person
concerned?
 Does it depend upon the situation?

Object-Oriented Analysis & Design – Module 1


Slide 18
Person - student

 A student is a specialization of a Person


 The following information may be required for a
student:
 name (from Person)
 modules s/he is taking
 address (from person)
 which year of study
 full-time or part-time

Object-Oriented Analysis & Design – Module 1


Slide 19
Person - staff

 A staff member is a specialization of a Person


 The following information may be required for a
staff member:
 name (from person)
 modules s/he is teaching
 address (from person)
 when started employment
 how long in employment
 full-time or part-time

Object-Oriented Analysis & Design – Module 1


Slide 20
Hierarchy of classes

PERSON

STUDENT STAFF

Object-Oriented Analysis & Design – Module 1


Slide 21
Inheritance

 A Student has all the characteristics of a Person


plus a little bit more
 A Staff member has all the characteristics of a
Person plus a little bit more
 Both Student and Staff can inherit common
characteristics from Person
 Inheritance can be slightly different in different OO
languages
 we will take a simple example that is fairly standard
 A subclass of a class inherits data and methods
(procedures) from a superclass

Object-Oriented Analysis & Design – Module 1


Slide 22
The ‘is-a’ Relationship

 Inheritance can be thought of as implementing the


is-a relationship
 A Student is-a Person
 A Staff member is-a Person

 Often classes can be logically related to each


other by the „is-a‟ relation
 Car is-a Vehicle
 Lorry is-a Vehicle

 The „is-a‟ relationship allows us to identify


common characteristics in a super class and
concentrate on differences in sub classes

Object-Oriented Analysis & Design – Module 1


Slide 23
Inheritance

 For example: if we have already defined what a


Vehicle is, we don‟t need to define any of the
Vehicle properties in class Car; we only have to
define things that are unique to Car

 When a class (Car) is a kind of another class


(Vehicle) we can say „Car inherits from Vehicle‟

 Car inherits all the properties of Vehicle and


adds some of its own

Object-Oriented Analysis & Design – Module 1


Slide 24
Inheritance Diagrams

 Inheritance relationships can be shown as


diagrams:

Vehicle
inheritance classes
triangle

Car Lorry

Object-Oriented Analysis & Design – Module 1


Slide 25
The ‘has-a’ Relationship

 The „has-a‟ or „part-of‟ relationship exists between


objects when one object is a part of another
 For example a wheel is a part of a car
 a wheel is an instance of class Wheel
 a car is an instance of class Car
 The car has a set of wheels

 It is DIFFERENT from inheritance („is-a-kind-of‟)


 a wheel is not a kind of car

 Sometimes we think of the “part-of” relation as


being between classes - this is called aggregation

Object-Oriented Analysis & Design – Module 1


Slide 26
Multiple Inheritance

 A class can inherit the features of several different classes


 For example Amphibious Vehicle inherits the properties of
both Land Vehicle and Water Vehicle

Water Vehicle Land Vehicle

Vehicle

Object-Oriented Analysis & Design – Module 1


Slide 27
Polymorphism

 A message can invoke more than one method


 The actual method invoked depends upon the type of
object that the message is sent to
 For example the class Circle and the class Square
can both understand the “drawYourself” message
 However, they have different methods to
implement the drawing behaviour
 one draws a circle
 the other a square

 This is allowed in object-oriented languages


 This is called “polymorphism”

Object-Oriented Analysis & Design – Module 1


Slide 28
Using OO and finding classes

 When building OO applications:


 First, look at existing class hierarchies and see if
any suitable classes exist to use as they are
 If no existing classes do exactly what is required
can you extend any of the classes easily to give
the application classes that you need?
 Inheritance
 If not, you need to define and build your own
classes
 Think about making your classes as generic as possible
so that they can be re-used

Object-Oriented Analysis & Design – Module 1


Slide 29
Summary

In this chapter we have:


 Introduced some Object Oriented concepts
 Introduced the concept of an object as an instance
of a class
 Discussed Encapsulation
 Discussed Inheritance
 Discussed Polymorphism

Object-Oriented Analysis & Design – Module 1


Slide 30

You might also like