stephenson college dp 96 1 object-orientation by derek peacock
TRANSCRIPT
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
Stephenson College DP 96 3
Types of Objects cont...
Interactions Electrical circuit, a contract
Specifications Architectural Design Engineering blueprint
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
Stephenson College DP 96 5
What are Objects?
Attributes, States Methods, Behaviour Composed of other objects
Stephenson College DP 96 6
Program Objects
Object = (private) Data + (public) Processes
Object Name
Public Processes
Private Data
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
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
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
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
Stephenson College DP 96 11
Features of OOP
Encapsulation/Abstraction Inheritance Polymorphism Aggregation
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
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
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
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
Stephenson College DP 96 16
Comparing Approaches
Procedural Data Type
Variable Function/Procedure
Object-Oriented Abstract Data Type
or Class Object/Instance Method/Operation