External Exam Download Resources Web Applications Games Recycle Bin

Object Oriented Programming

Object-oriented programming (OOP) focuses on creating reusable patterns of code, as opposed to procedural programming, which focuses on explicit sequenced instructions.

When working on complex programs in particular, object-oriented programming lets you reuse code and write code that is more readable, which in turn makes it more maintainable.


There are other strengths of OOP, such as abstraction, encapsulation, inheritance and polymorphism. Some definitions:

Class: blueprint in code (e.g. a bicycle class might have a speed variable and a speedUp() method)

Object: instance of a class (e.g. Ronnie's bike)

Abstraction: means hiding implementation details from the user, e.g.: self.somethingElse = AnotherClass.someOtherMethod("who knows")

Encapsulation: grouping, hiding or protecting methods or variables within classes (such as using public and private keywords in C++, or double __underscore in Python).

Inheritance: when new objects (child) to take on the properties of existing objects (parent). Example: a circle class inherits the properties of a shape class.

Polymorphism: assigning a different meaning or usage to something in different contexts. in other words, the ability for an object to take on many forms. Example #1: a method draw() could be used with triangles, stars and boxes. Example #2: creating an abstract or virtual implementation, which must be redefined.