Skip to content

Latest commit

 

History

History
35 lines (19 loc) · 2.44 KB

README.md

File metadata and controls

35 lines (19 loc) · 2.44 KB

Object Oriented Programming

Overview

OOP imposes discipline on indirect transfer of control.

Programming paradigm based on the concept of objects, which can contain data in the form of fields (often known as attributes or properties), and code in the form of procedures (often known as methods).

Object's procedures can access and often modify the data fields of the object with which they are associated (objects often have a notion of this or self).

OOP languages are diverse, but the most popular ones are class-based, meaning that objects are instances of classes, which also determine their types. Many of the most widely used programming languages are multi-paradigm and they support object-oriented programming to a greater or lesser degree, typically in combination with Imperative and Procedural programming.

History

Discovered in 1966 by Ole Johan Dahl and Kirsten Nygaard. These two programmers noticed that the function call stack frame in the ALGOL language could be moved to a heap, thereby allowing local variables declared by a function to exist long after the function returned. The function became a constructor for a class, the local variables became instance variables, and the nested functions became methods. This led inevitably to the discovery of polymorphism through the disciplined use of function pointers.

Objects and Classes

OOP typically uses Inheritance for code reuse and extensibility in the form of either Classes or Prototypes. Those that use classes support two main concepts:

  • Classes: definitions for the data format and available procedures for a given type or class of object, may also contain data and procedures themselves.
  • Objects: instances of classes.

Objects provide a layer of Abstraction, which can be used to separate internal from external code. External code can use an object by calling a specific instance method with a certain set of input parameters, read an instance variable, or write to an instance variable.

Objects are created by calling a special type of method in the class known as Constructor. A program may create many instances of the same class as it runs, which operate independently.

In some languages classes and objects can be composed using other concepts like Traits and Mixins.