The 4 Pillars of OOP | BHM Edition

What is Object-oriented programming ?

Classes, Objects and Methods

  • Class names are written in CamelCase
Declaration of the SoftwarePioneer class, constructor method and class attribute “expertise”
  • Variable names are written in snake_case
3 Instances of the SoftwarePioneer class
  • Method names are written in snake_case
Instance method change_the_world

Abstraction

Instance method recognition

Inheritance

The child class HardwarePioneer inherits from the SoftwarePioneer parent class

Encapsulation

  • Public: Public variables and methods can be accessed from anywhere in your program, both inside of the class hierarchy it is defined in as well as outside in the rest of the program
  • Private: Private variables and methods can ONLY be accessed from within the same class they are defined in. Attempting to call private variables and methods outside of the class they are defined in will return an AttributeError.
  • Private variables and methods are prefixed with __ (double underscore).
The private variable __age_at_creation and corresponding getter and setter methods
  • Protected: Protected variables and methods can be accessed within the class they are defined in and any child classes using getter and setter methods.
  • Protected variables and methods are prefixed with _ (single underscore).

Polymorphism

Dynamic polymorphism example using the change_the_world method

Static polymorphism is based the method overloading concept.

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store