Erle Robotics C++ GitBook

The basic Ideas of OOP

The way you structure a program C++ is:

  1. Split it up into a set of tasks and subtasks .
  2. Make functions for the tasks .
  3. Instruct the computer to perform them in sequence.

With large amounts of data and/or large numbers of tasks, this makes for complex and unmaintainable programs.

To manage this complexity, it’s nicer to package up self-sufficient, modular pieces of code.OOP allows programmers to pack away details into neat, self-contained boxes (objects) so that they can think of the objects more abstractly and focus on the interactions between them.

There are lots of definitions for OOP, but 3 primary features of it are:

  • Encapsulation: grouping related data and functions together as objects and defining an interface to those objects.
  • Inheritance: allowing code to be reused between related types .
  • Polymorphism: allowing a value to be one of several types, and determining at runtime which functions to call on it based on its type .