Object-Oriented Programming

Object-Oriented Programming A.K.A : OOP
is a way(paradigm) of building computer programs so that they are both intuitive to humans(problem side) and computers(solution side).

Objects have attributes and methods.

Attributes are basically the characteristics or properties, or states about the object. Like a Person has a name, gender and age.

Methods are actions or functionalities that can be performed or executed on objects from somewhere else in the programs. Like a Light can be On and Off.

If you build your programs using OOP, you basically build a collection of objects that can interact with each other by sending messages(make method call request).

Features

  • Classes and Objects
    In programming languages like C++ and Java, Class is an extensible template or blueprint for creating Objects, each object is an instance of a Class. The use of classes to create multiple objects that share the same attributes and methods with different identities (each object has a unique address in memory) is the symbol of most of Object Oriented languages. Programmers can define a class to fit the problem they want to solve (creating abstract data types). In Prototype languages like JavaScript, Lua, use the Object not the Class as the basis for object definition, you’ll create new objects in these programming languages by cloning existing ones. Object can be seen as a collection of slots as a hash, each slot can be referred to with a key.

  • Abstraction
    is a way of controlling complexity by presenting the model of the problems and hiding details and can give you the ability to create new symbols so that you can discuss problems at a higher order.
    The complexity of the problems you’re able to solve is directly related to the kind and quality of abstraction.
    Abstraction can also be found everywhere in the real world, every time you drive a car or plugin your phone into the socket, you are using an abstracted interface(steering wheel, socket) to certain services(car differential, electric power). Numbers and letters are also examples of abstraction that used to express ideas and help reduce cognitive load.

  • Encapsulation
    is basically wrapping some related things into a package. In OOP, we package access control between the data within an object and functions that manipulate those data in Class, and that keeps both safe from outside interference and misuse. But Class is not the only way to implement Encapsulation, for example, you can use package (Java), module (Python, Node.js), namespace (C++), even file to implement Encapsulation.

  • Inheritance
    is a way to create something (child) from something else (parent), and you will get the attributes or properties from that thing(parent). For example, if you have an object called Animal, with the ability to move() and eat(), then if you implement a dog that inherits from Animal, then the dog would start with the ability to move() and eat() as well.

  • Polymorphism
    means implementing multiple methods with the same name but different functionality at multiple levels of the inheritance chain. Overriding polymorphism happens at runtime(dynamic) which means within an inheritance hierarchy, a subclass can override a method of it’s superclass, and overloading polymorphism happens at compile time(static) which allows you to implement multiple methods within the same class that use the same name but a different set of parameters.