In traditional iterative programming languages data is stored in variables and programs perform the processing. The data and the processing are kept separate.
In Object Oriented Programming the programmer develops objects that contain the data and the operations (called methods) that can be performed on the data.
Object Oriented Programming is a Programming Paradigm
A way of looking at things – or an approach to programming.
We’ve had:
Sequential (Assembly)
Procedural (BASIC)
OOP (C#)
Database Query Languages (SQL)
Functional Programming (Haskell)
Features:
Selection
Iteration
Subroutines
Objects
Function calls
Recursion
Most modern languages (e.g. C#) are multi-paradigm, although some still specialise (e.g. Haskell)
The OOP approach is about modelling the world as ‘things’.
Things can be made of other things (e.g. a car has 4 wheels) or can be linked with other things (a car is maintained by a mechanic).
An object can be defined by:
Descriptive Attributes (data)
Behaviours (what it does)
There are five main elements of OOP that we will explore:
Association (Aggregation & Composition)
Polymorphism
It encourages reuse of code therefore reduces development time
Each class can be adapted without the users of the class being aware of any changes being made
It improves robustness because each class can be thoroughly tested to ensure that it meets all the required standards.