OOP - Introduction

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

What is a paradigm?

A way of looking at things – or an approach to programming.

We’ve had:

Imperative
(I’ll tell you how to do it)

  • Sequential (Assembly)

  • Procedural (BASIC)

  • OOP (C#)

Declarative
(I’ll tell you what I want)

  • Database Query Languages (SQL)

  • Functional Programming (Haskell)

Features:

Imperative

  • Selection

  • Iteration

  • Subroutines

  • Objects

Declarative

  • Function calls

  • Recursion

Most modern languages (e.g. C#) are multi-paradigm, although some still specialise (e.g. Haskell)

Object Oriented Programming

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:

Reasons why OOP has become so popular:

  • 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.