Langsung ke konten utama

Structured Programming VS Object Based Programming || TASK 1

Structured Programming
Object-oriented programming
Break down programs in functions and data
Combine functions and data in classes or objects
It has the characteristics of Sequence, Selection and Repetition
It has the characteristics of Encapsulation (packaging), Inheritance (inheritance) and Polymorphism (differences in shape and behavior)
The program structure is complicated because it is a sequence of processes and functions
The program structure is concise, enough to create objects and classes and then work based on these objects and classes.
Lacking program reusing
The program code is very reusable. object and class can be used many times, so as to save memory space.
Effectively used to solve small problems and not suitable for solving complex problems, because later it will be difficult to find solutions to problems when an error occurs
Effectively used to solve large problems, because OOP consists of classes that separate each program code into small groups, according to their function
Easy to start, but complex is processed further
Difficult to start (because they have to make a class) but then it will feel easy and fast
Slower execution because each command is done sequentially
Faster execution because it is executed simultaneously, the program only manages the object, its properties and methods



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)


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)




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)

Komentar

Postingan populer dari blog ini

Portofolio Aplikasi

Maddi Website Website ini menggunakan framework django, tailwind dan bootstrap. Memiliki fitur seperti login, register, keranjang belanja, dan fitur-fitur lainya. tetapi website ini belum di deploy jadi untuk membukanya masih menggunakan localhost. Dan pada saat pernah membuat aplikasi POS simple menggunakan program java.  

DOTA 2

TPG _ Review Game DOTA 2 Klasifikasi Game Genre : MOBA (Multiplayer Online Battle Arena) , Strategy Tema : Fantasy Rating : No Rating (ESRB) Metacritic Rating : 90 Publisher : Valve Corporation Release Date : July 9, 2013 Deskripsi Dota 2 adalah video game multiplayer online battle arena (MOBA) 2013 yang dikembangkan dan diterbitkan oleh Valve. Gim ini merupakan sekuel Defense of the Ancients (DotA), yang merupakan mod buatan komunitas untuk Warcraft III: Reign of Chaos dari Blizzard Entertainment. Dota 2 dimainkan dalam pertandingan antara dua tim yang terdiri dari lima pemain, dengan masing-masing tim menempati dan mempertahankan markas mereka sendiri di peta. Masing-masing dari sepuluh pemain secara independen mengontrol karakter kuat yang dikenal sebagai "pahlawan" yang semuanya memiliki kemampuan unik dan gaya permainan yang berbeda. Selama pertandingan, pemain mengumpulkan poin pengalaman dan item untuk pahlawan mereka agar berhasil mengalahkan pahlawan tim lawan