The Goal of Programming languages and procedures has always been to give the ability to computers to imitate the human brain in how information is processed, categorized and utilized. The latest paradigm in program languages that comes the closest to reaching that goal is Object Oriented Programming also known as OOP. This newer paradigm comes in contrast with the prior Structured Programming model or SP that paved the way to computing as we know it today. What is OOP and how does it differ from its SP predecessor will set the tone for our analysis.
Object-Oriented Programming (OOP) is a programming language model organized around objects rather than “actions”. The leading languages based on OOP are C++, Java, Python, C#, Visual Basic etc… The first step in OOP is to identify all the objects the programmer wants to manipulate and how they relate to each other. Once an object has been identified, the role of the programmer is to generalize it as a class of objects and define the kind of data that it contains and list of procedures that manipulate it. Four major principles define OOP: Encapsulation, Abstraction, Inheritance, Polymorphism.
Encapsulation can be described as a protective barrier that protects the code and data within a specific class from being randomly accessed by other codes defined outside of that class. Abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer. Inheritance allows an object or class to reuse the same implementation or properties of another object or class without having to re-invent the wheel. Polymorphism manifests itself by having multiple methods all with the same name, but slightly different functionality.
To put it into perspective, let’s assume a car to be an object oriented program. The purpose of the car is to provide transportation. The car comes with several objects such as tires, lights, passenger seats and engine etc. each one of these objects has properties. The tires are defined by their brand name models and size. The seats are defined by their number and color and the material that they are made of. The engine is defined by its size and type etc. So just like a car comes with independent objects with specific properties, the OOP also comes with independent abstracted encapsulated objects that have either predefined or definable properties.
The car itself belongs to the family of transportation vehicle. And as member of this class, it shares the same properties with other vehicle such us trucks, vans and Bus etc. So even though the car is a vehicle and the truck is a vehicle the car is not a truck thus explains the principle of inheritance in OOP where child classes or object can inherit the properties of parents without impact to the parent.
Every object of the car has a color and the method of the color regardless of the object that it defines would use the same either RGB or HEX color coordinate system. This in a sense defines the polymorphism property of the OOP where multiple methods can be assigned the same name though they may fulfill different functionality.
Unlike OOP, SP is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. Certain languages such as Ada, Pascal, and dBASE are designed with features that encourage or enforce a logical program structure. It’s a programming technique in which a hierarchy of modules is used, each having a single entry and a single exit point, and in which control is passed downward through the structure without unconditional branches to higher levels of the structure. Three types of control flow are used: sequential, test, and iteration. Structured Programming was stepping up from non-structured methods such us MSX BASICS, FOCAL and Machine-level code that was considered bad programming.
Considering the OOP is first an SP with classes and objects built-in mainly for efficiency, structured programming can save time and energy when writing small and simple programs (Though Simple program is quite relative to the writer) that would essentially hold into one page. OOP however due to their ability to inherit preconfigure properties from already existing class and Objects will be more efficient when writing huge programs and web based development projects. Nonetheless, OOP by natures are much more complex not only to design but also to maintain. Yet, from a user Stand Point, the difference between OOP and SP when it comes to performance is very minimal.
While OOP might not seem to be faster than SP based on the facts that OOP still have to compute independent classes that are used in the program at run-time when SP only read the program from top to bottom, OOP appear to be more robust and reliable once they are implemented correctly. The OOP focus on object is definitely a step toward reaching the human brain computational process. But as it stands, much yet needs to be accomplished before we get there.