stephenson college dp 96 1 object-orientation by derek peacock

16

Click here to load reader

Upload: juliet-rice

Post on 31-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 1

Object-Orientation

by Derek Peacock

Page 2: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 2

Types of Objects

Tangible things Cars, Cards, Books

Roles Employer, Teacher, Student

Incidents Flight, Transactions

Page 3: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 3

Types of Objects cont...

Interactions Electrical circuit, a contract

Specifications Architectural Design Engineering blueprint

Page 4: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 4

Objects in Programming

Direct representation of the application Graphical Playing Cards Documents Accounts

Artefact of Implementation Card Deck Unit stacks, queues

Page 5: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 5

What are Objects?

Attributes, States Methods, Behaviour Composed of other objects

Page 6: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 6

Program Objects

Object = (private) Data + (public) Processes

Object Name

Public Processes

Private Data

Page 7: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 7

Encapsulation

Data & Processes linked

Public interface Information is hidden private data private internal

processes

Bank Account

Account numberaccount holdercurrent balance

get current balancemake depositmake withdrawal

Page 8: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 8

Traditional Modularity

Process Driven Functional

Decomposition Data structured to

suite the process code re-use difficult

Data Driven Data Decomposition Process constrained by

the structure of data code re-use difficult

Page 9: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 9

Object Oriented Modularity

Data & Process tightly bound together (encapsulated)

Internal data and processes hidden Public interface can remain fixed while

internal workings are changed Can be extended without altering original

code

Page 10: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 10

‘Good’ Modules

Reusability Extensibility Decomposability Composability Understandability Continuity Protection

Software components

New components from old

breaking a system down

building a system up

easy to understand the partsmall changes lead to small effects

errors confined to module

Page 11: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 11

Features of OOP

Encapsulation/Abstraction Inheritance Polymorphism Aggregation

Page 12: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 12

Encapsulation/Abstraction

Abstraction is used to represent essential features of behaviours and states

Behaviours & States encapsulated into an abstract data typeabstract data type or classclass

Internal States not directly accessible Changes to internal implementation do not

effect external interface

Page 13: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 13

Inheritance

One Class can inherit the characteristics of another class. One class can be a “Kind of” other class a text window is a kind of a kind of window

A classification hierarchy shows the inheritance relationships between classes

Page 14: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 14

Polymorphism

Different objects can respond to the same message in different ways e.g. Square.Draw Circle.Draw

At runtime we might not know what object is present but for example Object.Draw will draw whatever object is available

Page 15: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 15

Aggregation

Objects can be aggregated into new relationships

Objects of one class can be composed of objects of another class Object A is a part ofis a part of Object B Engine is a part ofis a part of Car

Page 16: Stephenson College DP 96 1 Object-Orientation by Derek Peacock

Stephenson College DP 96 16

Comparing Approaches

Procedural Data Type

Variable Function/Procedure

Object-Oriented Abstract Data Type

or Class Object/Instance Method/Operation