Show understanding of the characteristics of a number of programming paradigms: Object Oriented

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – Programming Paradigms: Object‑Oriented

20.1 Programming Paradigms – Object‑Oriented

What is the Object‑Oriented Paradigm?

The object‑oriented (OO) paradigm models software as a collection of objects that combine data (state) and behaviour (methods). An object is an instance of a class, which defines the structure and capabilities that its objects share.

Key Characteristics

  • Encapsulation – Bundles data and the methods that manipulate that data within a single unit, hiding internal details from the outside world.
  • Inheritance – Allows a new class (sub‑class) to acquire the attributes and methods of an existing class (super‑class), promoting reuse and hierarchical relationships.
  • Polymorphism – Enables a single interface to represent different underlying forms (e.g., method overriding or overloading), allowing objects of different classes to be treated uniformly.
  • Abstraction – Provides a simplified model of complex reality by exposing only essential features and suppressing irrelevant details.

Typical OO Constructs

Below is a generic class definition in a Java‑like syntax, illustrating the four characteristics.

\$\$\begin{aligned}

\textbf{class}\; \text{Vehicle} \{\\

\quad \text{private}\; String\; make;\\

\quad \text{private}\; int\; year;\\

\quad \text{public}\; Vehicle(String m, int y) \{\\

\quad\quad this.make = m;\\

\quad\quad this.year = y;\\

\quad \}\\

\quad \text{public}\; void\; start() \{\\

\quad\quad System.out.println("Engine started");\\

\quad \}\\

\}\\[6pt]

\textbf{class}\; \text{Car} \text{ extends } \text{Vehicle} \{\\

\quad \text{private}\; int\; doors;\\

\quad \text{public}\; Car(String m, int y, int d) \{\\

\quad\quad super(m, y);\\

\quad\quad this.doors = d;\\

\quad \}\\

\quad \text{@Override}\\

\quad \text{public}\; void\; start() \{\\

\quad\quad System.out.println("Car ignition");\\

\quad \}\\

\}

\end{aligned}\$\$

Advantages of Object‑Oriented Programming

  1. Improved modularity – each class can be developed and tested independently.
  2. Code reuse through inheritance and composition reduces duplication.
  3. Easier maintenance – changes to a class affect only its objects.
  4. Enhanced readability – concepts map closely to real‑world entities.
  5. Supports polymorphic interfaces, facilitating flexible and extensible designs.

Disadvantages / Limitations

  1. Potential for over‑engineering – excessive use of inheritance can create deep, fragile hierarchies.
  2. Higher memory overhead due to object metadata and indirection.
  3. Learning curve for concepts such as abstraction, polymorphism, and design patterns.
  4. Performance penalty in some contexts compared with procedural code, especially for tight loops.

Common Object‑Oriented Languages

  • Java
  • C++
  • C#
  • Python (supports multiple paradigms, but widely used OO)
  • Ruby

Comparison with Other Paradigms (Summary Table)

AspectObject‑OrientedProceduralFunctional
Primary abstractionObjects (state + behaviour)Procedures / functionsPure functions
Data encapsulationYes (private/public access)Limited (global variables)Immutable data
Reuse mechanismInheritance, compositionModular functionsHigher‑order functions
PolymorphismMethod overriding / overloadingNone (except via pointers)Function composition
Typical use‑caseLarge, evolving systemsSimple scripts, system utilitiesMathematical modelling, concurrency

Suggested diagram: Class hierarchy showing \cdot ehicle as a super‑class and Car, Truck as sub‑classes, illustrating inheritance and polymorphic start() method.

Key Points to Remember for the Exam

  • Define and give examples of encapsulation, inheritance, polymorphism and abstraction.
  • Explain how OO promotes modularity and reuse.
  • Identify situations where OO may be less suitable (e.g., memory‑constrained embedded systems).
  • Be able to read and write simple class definitions and recognise OO concepts in code snippets.