Mark As Completed Discussion

The Basics of OOP

If you examine the previous example closely, then you'll see that all of these objects have two traits in common:

  1. Each object has its own properties.
    • Keyboards have keys. Keyboard A might have 30 keys and keyboard B might have 40 keys.
    • Monitors have heights and widths. Monitor A is 32 inches long and monitor B is 55 inches long.
  2. Each object can take some actions.
    • A keyboard can send a signal to a computer and enable/disable numlock.
    • A monitor can show you frames and adjust brightness/contrast.

Generally, we can say that each object has two things:

  1. Properties
  2. Methods

Formal Definition of OOP.

Wikipedia says that "Object-oriented programming (OOP) is a programming paradigm based on the concept of 'objects', which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures".

If you understood the monitor and keyboard examples, then you can easily relate to this definition now. Here "objects" are the keyboard and monitor; the "data" is the height, width, number of keys, etc.; the "code" is sending signals, displaying images, and so on.

This is the basic idea of what each object in an OOP design should have. Later, we will see that we can use instances of these objects to know certain properties. For example in Python:

PYTHON
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment