Unit 2 · Introduction to Object-Oriented Programming

2.2.2Self-check and practice

Self-check questions

Write your answers first, then open the answers to check them.

  1. Define a programming paradigm.
  2. Give three differences between procedural and object-oriented programming.
  3. Why is data safer in an OOP program?
  4. Name the four pillars of OOP.
Show answers
  1. A programming paradigm is a style or way of organising a program, for example procedural or object-oriented.

  2. Any three:

    • The main unit is a function in procedural code and an object in OOP.
    • Data and functions are separate in procedural code and bundled together in OOP.
    • Data is often global in procedural code but can be hidden in OOP (encapsulation).
    • Procedural code reuses functions by calling or copying them; OOP adds inheritance and composition.
    • Procedural design focuses on the steps; OOP focuses on the things taking part and what they do.
    • Large procedural programs become hard to maintain; in OOP changes stay inside classes.
  3. Each object's data can be made private and changed only through the object's own methods, which can check every change. In procedural code data is often global, so any function can change it and one mistake anywhere can corrupt it.

  4. Encapsulation, abstraction, inheritance and polymorphism.

Practice exercises

  1. For a library system, list the functions you would write in a procedural design, then list the classes, attributes and methods in an OOP design.
  2. Choose a problem (for example, a school timetable) and explain which paradigm you would choose and why.
  3. Write a short paragraph on why large teams prefer OOP.

End of Unit 2. Test yourself with the Unit 2 questions in the multiple-choice and structured question banks, tick the outcomes in the topic checklist, then go on to the next unit.