For new programmer OOP can be a hard concept to wrap you mind around. In this post my goal is to go over some of the concepts of OOP.
Wikipedia’s definition of OOP is: ”Object-oriented programming (OOP) is a programming paradigm that uses “objects” and their interactions to design applications and computer programs. Programming techniques may include features such as encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s. …. ”
History of OOP
SIMULA I (1962-65) and Simula 67 (1967) are the two first object-oriented languages. Simula 67 introduced most of the key concepts of object-oriented programming: both objects and classes, subclasses and virtual procedures, combined with safe referencing and mechanisms for bringing into a program collections of program structures described under a common class heading (prefixed blocks).
Simula 67 was a groundbreaking system that has inspired a large number of other programming languages, and some of these include Pascal, Lisp and in the .net world #C and VB are the most popular. OOP was also important for the development of Graphical user interfaces. This paradigm of programming has also played an important role in the development of event-driven programming.
Explanation of OOP concepts
The term “Object,” that gives OOP it’s name, refers to a conceptualobject that represents an item in our program or system. This could be anything from an on-line form or a computer file, to a real world object such as a car. Being a car guy this is analogy helps me the most.
This representation consists of attributes – the characteristics of our object; and methods – a set of functions and calculations that are either performed to modify the object itself, or are involved in some external effect.
The term “Class” represents the definition (or classification – class) of our object. For example, if we were to write a class called “car”, we could create any number of instances of that class – say “Ford”, “Honda” and “Chevy”. Each of these instances is an Object. This illustrates that a class is effectively a set of objects that all share common attributes.
The “car” object can do a number of methods or “actions”: (beep, start engine, turn on lights, and etc.) Some methods can accept parameters, for instance. Say your car class has a method called “wipers_on”, this method take a parameter for the speed of the wipers i.e. (slow, medium, and fast).
Polymorphism refers to the ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class “shape“, polymorphism enables you to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language (OOPL).
Inheritance is the process by which objects can acquire the properties of objects of other class. Inheritance provides reusability, like, adding additional features to an existing class without modifying it. This is achieved by deriving a new class from the existing one. The new class will have combined features of both the classes.