Object-Oriented & Structured Programming

Object-Oriented & Structured Programming

Computer programming can be written in a number of ways, however, we will be focusing on OOP which is short for Object-Oriented Programming and Structured Programming(SP).

What is Object-Oriented and Structured Programming?

Brookshear(2012, p276) states that the “object-oriented paradigm entails the development of active program units called objects.” this refers to an interaction between self-contained mini-programs, a lot like a car — which as an engine, doors, lights, and radio. If the light bulbs blow, it is noticeable only when a light is required, however, the engine nor the radio isn’t affected. Thus, the light does not necessarily have to be fixed as of yet.

Whereas SP also was known as Modular Programming and is a subset of Procedural programming. SP is a method that could be considered the precursor to OOP and provides for a top-down which is also “a list of instructions to tell the computer what to do step-by-step”(Mishra, 2015) design through loops, sequences, decisions, and logic blocks. In essence Structured Programming as the name suggests, follows a sequential pattern hierarchical in nature. All the components are dependent on each other such as a gas pump and an engine. If the gas pump dies, the car dies.

The major concepts of Object-Oriented Programming are:

  • Object – The instance or representation of a class
  • Class – The blueprint of an object
  • Abstraction – Used to manage complexity or hide irrelevant data
  • Inheritance –  Allow one class to encompass the properties of another
  • Polymorphism – Customized interpretation of different behaviors
  • Encapsulation – Access control for instance variables and methods

Object
An object is an instantiation of a class. Examples of these are Television, Car, and Computer.  This is how an Object is instantiated:

Nissan = new Car(). 

Where Nissan is the Object of the class Car.

Class
A class is a collection of components called methods and instance variables. This in essences offers a blueprint that is used to create an object. For example:

Class Car
{
Private Color = red;
Private WheelSize = 16; //measured in inches
Private Interior = “Leather”;

Private Model;
Private Year;
Private NumberOfDoors;

void setModel(ModelName)
{
Model <— ModelName;
}

void setYear(YearMade)
{
Year <— YearMade;
}

void setDoorsAmt(Doors)
{
NumberOfDoors <— Doors;
}
}

Abstraction
Data abstraction is the implementation of an object which contains all essential properties and methods. For example the content of the Car Class, which as all the methods that will facilitate the creation of a car.

Inheritance
Inheritance in both its biological and programmatic sense is the ability to inherits the behavior and functionalities of an existing parent or class structure. For Example, inheriting your father eyes and skin tone likewise in our example we can inherit the Engine Class which will have all the components of creating an engine.

Class Car extends Engine
{

}

Polymorphism
According to Kanzariya(2012), he stated that  “Polymorphism means an ability to assume different forms at different places. In OOP, it is a language’s ability to handle objects differently based on their runtime type and use.” This simply means that the method with a class can take on a different form based on use and context. Figure 1.0 illustrates a method cut and how it is used in a different context.

Figure 1.0 “Polymorphism in real world” (Narayan, 2008)

polymorphism.gif

Encapsulation
Encapsulation, “refers to restricting access to an object’s internal properties.”(Brookshear, 2012, p282). It also allows for the separation of an object implementation from its original behavior thereby restricting access of its instance variable value. For example, the car’s engine is not open to bystanders or passers-by because the inner workings of the engine could be manipulated without proper knowledge and this could become harmful to the overall object(Car).

Figure 1.2 Encapsulation in real world (Mohammed, n.d)

Encapsulation-and-Abstraction-example-tutorial-download.png



Advantages of OOP and SP

  1. OOP:
    1. Code Reuse and Recycling
    2. Encapsulation
    3. Design Benefits
    4. Software Maintenance
    5. Higher-quality software
    6. Debugged faster
  2. SP
    1. Reduced complexity
    2. Easy to test and correct module by module.
    3. Small codes are easy to maintain


Disadvantages of OOP and SP

  1. OOP:
    1. Size: OOP applications tend to be larger in size when compared to SP
    2. Takes a lot of effort and know how to implement
  2. SP:
  1. Large codes are harder to maintain
  2. Unstable structure and causes poor execution of functions, actions or control
  3. Does not allow reusability
  4. Takes up more computer memory
  5. Not suitable for the development of large programs
  6. Less abstraction and less flexibility

Examples of both
OOP:

//...Program Starts
Class Car
{
Private Color = red;
Private WheelSize = 16; //measured in inches
Private Interior = “Leather”;

Private Model;
Private Year;
Private NumberOfDoors;

void setModel(ModelName){
….
}

void setYear(YearMade){
….
}

void setDoorsAmt(Doors){
….
}

Function MakeCar(){
CarColor = Color;
....
//Compute all values and send to robotics
}
}

Nissan = new Car();
Nissan.setModel(“Sony B6”);
Nissan.setYear(1999);
Nissan.setDoorsAmt(4);

Result = Nissan.MakeCar();
//….Program Ends


Structured Programming:

//...Program Starts
Declarations
If (CarDoor < getCarModel(‘Nissan’)) then
Print “Car is SUV”;
else
Print “Car is sedan”;
end if;

Methods

Functions
//….Program Ends


OOP over structural programming
OOP is somewhat becoming a standard in many business practices as a result of the advantages it offers in a real-world scenario. It offers more flexibility and better maintenance especially when it comes on to the upgrading of an application with advancements in technology, reusability, inheritance and better data security with its encapsulation concept. OOP is the preferences because, unlike the SP, it allows programmers to modify any part of the code, the beginning, the center or the end of a program without affecting the overall application.

OOP, reflects the human way of thinking
By contrast is does reflect the human way of thinking. In an article by Asagba and Ogheneovo(2007) they state that “Structured programming is task-centric while object-oriented programming is data-centric, that is, structured programming is based around data structures and subroutines.”

Consider this, an online customer uses Amazon(Object) to make a purchase of a Book(Instance), without the customers know how or by what method the order will be fulfilled(Methods); the customer is assured that the order will be delivered to the address assigned. Amazon receiving the order has it’s internal encapsulated method each of which is responsible for picking the goods, labeling, ensuring it goes to the right shipper, etc. In the same way, OOP functions with each method of an object being responsible for an action or sequence of actions. In the manner, the human brain is a class which is inherited by your heart, your nervous system, your eye all of which will receive a different response or reaction(polymorphism)

References:

Asagba, P.O. and Ogheneovo, E.E., 2007. A comparative analysis of structured and object-oriented programming methods. Journal of Applied Sciences and Environmental Management, 11(4).

Brookshear, J. G., Smith, D. and Brylow, D. Computer Science: An Overview, 11th Edition. Reading, MA: Pearson (Addison-Wesley), 2012

Kanzariya, C. (2012) OOPS Concept with Real-world example, Available at:http://chiragkanzariya.blogspot.com/2012/11/oops-concept-with-real-world-example.html(Accessed: April 24, 2016).

Mishra, R. (2015) What is the difference between structured oriented objective programming and object oriented programming?, Available at:https://www.quora.com/What-is-the-difference-between-structured-oriented-objective-programming-and-object-oriented-programming (Accessed: April 24, 2016).

Mohammed, S. (n.d) Introduction to Object Oriented Programming Concepts in Java,Available at: http://my3development.blogspot.com/p/new-page.html (Accessed: April 24, 2016).

Narayan, G. (2008) Polymorphism on three classes, Available at:https://javanepal.wordpress.com/2008/10/22/polymorphism-on-three-classes/(Accessed: April 24, 2016).

Leave a Reply

Your email address will not be published. Required fields are marked *

Groope Multimedia © 2019, All rights reserved