Projects

 

Object Oriented vs Structured Programming
Why Java is so popular?
How to open a coconut?

Object Oriented vs Structural Programming


Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO statement [1].

The rise of the Object Oriented concept brought us debugging comfort as well as expandability as the programs were getting larger and larger and it became difficult to debug. There were functions to reduce the size of the programs and improve readability but it was never enough.

Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data. The programming challenge was seen as how to write the logic, not how to define the data. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them [2].

Object Oriented Programming has many benefits over Structured programming. Some of them are reusability, extensibility, reliability and maintainability. OOP also helps to reduce large problems to smaller, more manageable problems. In terms of extensibility and reusability, for instance: “Encapsulation allows the internal implementation of a class to be modified without requiring changes to its services (i.e. methods). It also allows new classes to be added to a system, without major modifications to the system. Inheritance allows the class hierarchy to be further refined, and combined with polymorphism, the superclass does not have to "know" about the new class, i.e. modifications do not have to be made at the superclass” [3].

Another important discussion would be; do we really need classes? Can we not just use functions instead? Considerable amount of people think that functions are faster and require less code. On the other hand, someone would argue that classes are more modular. I do not have any strict opinion on this subject. But, I think it really depends on what you would like to achieve. For instance, I cannot think of any reason why you would want to use classes to perform a very simple task such as checking if the user fills out the name – surname field on the form.

“One of the frequently claimed benefits of the OOP is that it is natural (therefore more understandable), and is assumed to be cognitively similar to the way human beings perceive and understand the real-world (Meyer, (1988); Rosson & Alpert (1988); Rosson & Alpert(1990). Martin & Odell (1992, p.31) for example, states "The way of thinking is more natural for most people than the techniques of structured analysis and design. After all, the world consists of objects." Mcfadden & Hoffer(1994, p.) similarly note "The notation and approach of the object-oriented data model builds on these paradigms that people constantly use to cope with complexity." This claim, therefore assumes that it is more natural for developers to decompose a problem into objects, at least as compared to the traditional structured languages. In other words, it should be natural for developers and users to map the problem into objects and into classification hierarchies.” [3]

Here is an example of a procedural program in PHP:

<?php

print "Hello, world.";

?>

Here is an example of an object-oriented program that achieves the same objective:

<?php

class helloWorld {

   function myPrint() {
      print "Hello, world.";
   }

}

$myHelloWorld = new helloWorld();
$myHelloWorld->myPrint();


?>

 

As you can see from the above example, in some cases, Object Oriented Programming can be pointless and not necessary and slow as well. If you are a performance freak, procedural programming is the way you should go. However, since everything around us is made of atoms and Objects consist of atoms. It would be so true to say: Object Oriented Programming is very similar to our way of thinking and it helps us to analyse and write code easier.

 

Tayfun Bilsel

References:

[1] http://www.absoluteastronomy.com/encyclopedia/s/st/structured_ programming.htm

[2] http://searchwin2000.techtarget.com/sDefinition/0,,sid1_gci212681
,00.html

[3] http://members.aol.com/shaz7862/critique.htm

[4] http://www.zend.com/zend/art/oo-proc.php



Copyright © 2006 Tayfun Bilsel. All Rights Reserved.