What is Object Oriented Programming (OOP)?
Also know as OOP, Objected Oriented Programming is a programming paradigm. The concept of object-oriented is almost literal, such as an animal (for example a snail), have different attributes and properties that identifies the object (for example color, size, shape, gender) and methods to make specific actions with the object (for example walking, sleeping, eating).
Object Oriented Programming – Brief History
Simula 67, the first language of OOP
The concept of Object Oriented Programming (OOP) begins from the idea of creating identifiable objects through their properties. This concept was originally formulated by Ole-Johan Dahl and Kristen Nygaard at the University of Oslo. These Norwegian scientists invented the Simula programming language in 1967.
Simula incorporated new programming concepts such as the birth of the object concept, classes, inheritance, virtual quantities and multithreading, so that each object was independent of other objects of the same type and that it could have coroutines, without presenting a concurrency as such.
Likewise, with Simula 67 there were no kind of objects called abstract class either, but its implementation of objects and paradigm makes Simula 67 the first language using the concept of Object Oriented Programming.
SmallTalk and refinement of the OOP concept
At the same time that Simula 67 existed, Alan Kay, a Computer Science scientist who did important research at MIT (Massachusetts Institute of Technology) and the University of Utah, coined the term as a new programming paradigm around the years 1966 and 1967.
In developing the concept, Alan Kay specified that he never had in mind to create a language similar to C or another existing at the time, where functional languages were in full swing. His idea was to create a language that would allow a symbiosis between humans and computers, making everything that existed in the computer resemble what human beings experienced in real life.
Following this hypothesis, Alan Kay developed in 1972 the Smalltalk programming language. This programming language was inspired by Simula 67, and was developed for Xerox Palo Alto Research (PARC), a research center.
Due in SmallTalk everything is considered an object, SmallTalk is frequently known as the father of all current object-oriented programming languages, for example, Objective-C, Java, Python and Ruby.
SmallTalk also incorporated one of the first pattern design concepts: the MVC (Model – View – Controller), as well as the concepts of Entity-Relation, model objects, abstract classes, etc.
Components of Object Oriented Programming
Object oriented programming requires the exchange of messages between objects, to work naturally and more similar to what exists in real life, one of the objectives of the OOP from the formulation of its concept.
The fundamental components of the OOP are as follows:
Attributes: There are variables that make up the physical structure of an object, which can be of different types, for example boolean, integer, string, array or even a nested object. They can be declared with default values (called constructor) or without initializing, leaving the user the responsibility of initializing their values.
Methods: They are all the functions and procedures that the object can perform. These methods are specific to the object and can only be used once the user declares the object.
To access an attribute or method within an object, it can be done using the dot (.) Operator (only if the attribute is public in some programming languages such as Java), and depending on the programming language, it can be encapsulated by doing its private scope and only accessible to value by means of an internal method towards the attribute of the object, further resembling the class to a real life object.
Advantages of Object Oriented Programming
Some of the advantages of object-oriented programming are as follows:
- They can be reused, that is, declaring the object makes a new instance of the object class.
- By having the declared object, you can access and modify the desired object directly, without modifying the others.
- Encapsulation allows the attributes of objects to be accessible only through its methods and not directly.
- Facilitates the creation of a graphical user interface or GUI.
- Each object is an entity, which can be sent to a database to be stored, or retrieve its value from a BD operation.
- Clean code is required to understand how the object works, any encapsulation failure or paradigm break can bring serious problems to the developer to follow the design pattern.
- Private attributes could be out of the scope of communication between other objects, if not directly specified in the message (or its value).
- Poor documentation increases the difficulty of knowing how the object works, since the methods used do not provide information on its variables.
- It is not so trivial to understand for novice programmers. It requires knowledge of how classes work, unlike imperative paradigms.
Is useful the OOP?
Object Oriented Programming allows the developer to consider everything as if it were an object with attributes and methods. This greatly facilitates the generation of code, avoiding repetitive code thanks to the instances towards the classes that the OOP allows us.
Each instance is independent, so we can declare two objects of the dog class called Ruffo and Firulais, and these can have different values and execute their methods at our convenience, without altering the other’s values.
Class inheritance also allows parent objects to inherit characteristics from their children, that is, we can declare another object as one of the attributes of the object, inheriting the methods from the parent to the child, this is known as extend in some programming languages like Java and Kotlin.
By extending, it is possible to override the parent’s existing methods on the child using Override.
We also recommend learning more about accessing objects through DAO in Kotlin, to learn how to access the entities of this programming language for Android.