How does Object-Oriented Programming compare to Structured Programming?

In this article, I’ll compare object-oriented programming (OOP) to structured programming. I will do my best to describe the key concepts of OOP and structured programming languages and described this...

In this article, I’ll compare object-oriented programming (OOP) to structured programming. I will do my best to describe the key concepts of OOP and structured programming languages and described this somewhat complex and technical topic using words and terms that the average individual (someone without professional training in the subject area) can understand so that they may comprehend the issue to some degree.

First of all, let’s start by saying that object-oriented programming and structured programming are two of the most recognized programming paradigms, or simply said, two of the most known programming styles.

So, how do they differ?

Structured Programming

Structured programming is one of the oldest programming paradigms, it “emerged in the late 1950s with the appearance of the ALGOL 58 and ALGOL 60 programming languages” (Structured programming, 2016).

Structured programming is using a step-by-step list of direction, which communicate to a computer exactly what need to be done. This paradigm of programming works fairly nicely since it is very intuitive. All that must be made is to provide the logical list of steps. The logical list of steps in structured programming is very often expressed using a flow chart, such as the one outlined in Diagram 1 below:

Diagram 1:

structured_program-1

Above flow chart shows a simplifies logical steps, that describe how the structured programming works. But the structured programming isn’t as simple as the diagram is trying to portrai. Structured programming uses many more elements, such as control structures (sequences, selections, iterations, recursion), modules, subroutines, blocks, which inherently makes programming style to be very complex.

One of the most known structured programming languages today is ALGOL, then Pascal, PL/I and ADA. Assembly language is also a good example of the structured programming because it does not have an intrinsic construction that would be imposed by the programming language.

Some programmers claim that structured programming in assembly language, cannot be compared to any other programming. And they tell stories of how the code written using structured programming is the best and the fastest.

Structured programming (also known as modular programming) means that the program needs to be broken down into modules and much well designed before writing a single line of code. For the structured program to be successful, the process usually happens in three steps:

- The first is to write the algorithm (the list of steps) or logical flow of the program (such as the one in Diagram 1).

- The second phase is to modularize the program. This step “emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality (Modular programming, 2016).

- The third is to create a thorough documentation for the program.

However, following such a time-consuming process is not always easy and thus structured programming is often plagued by issues. “Like jackpot winners in a gambling casino, for every one of these "success stories," there are thousands of untold tales of programmers whose programs never ran properly, if at all. Furthermore, even the "successes" are usually programs that only the author can understand and that only last until he starts on his next project. Such code is sometimes known as a write-only code (i.e. no-one can ever read it) “ (Mowforth, 2016).

Other problems are the inability to write a useful code due to constraints imposed by the logic-bound code, failure to properly package modules for re-use, etc. And this very often creates a system that is more complicated than it needs to be (especially for large projects), very hard to understand (particularly to new programmers looking at the code written by someone else) and quite expensive to maintain.

So, after a while, programmers and programming scientists started to explore different ways of increasing efficiency of programs and programmers. Object oriented programming introduces a different paradigm of programming. Let’s look at how it differs from structured programming.

Object-oriented Programming (OOP)

Object-oriented programming was created mainly to manage the complexity of procedural/structured languages. And with the introduction of object-oriented languages such as Java, C++, C#, Python, PHP, Ruby, Perl, Delphi or Objective-C, it became instantaneously successful. Even that we should mention, that some of the OOP languages are not purely object oriented and still can be using a bit of a structured programming.

**So what is OOP? **

Object-oriented programming is a programming paradigm that is “based on the concept of "objects", which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods” (OOP, 2016).

I bet the Wikipedia excerpt above didn’t make it much clearer, right? So let me explain this on an example.

Imagine you’re a business owner who’s occupational is to print the ‘business cards’. As you can probably envision, instead of designing each and every business card from scratch, you’d probably want to create a generic business card first. An object, a generic mold.

Let’s break this process into steps:

Create Object

- Find all common generic ‘**Attributes** (properties)’ that define a business card.

Example: card width, card height and material

- Find all common generic ‘**Behaviours** (functions) that can be found on a business card.

Example: phone number, fax number, business url

Use Object

Now that you have created a generic "blueprint," we have described a generic Object called a Business Card, and you can use it specify any future business card you’ll need to produce. Below example shows how we can encapsulate the object called ‘Business Card’ into attributes and behaviors:

Business Card #1

Attributes:

- Width: 5 inch

- Height: 2 inch

- Material: paper

Behaviours:

- Phone Number: 855.8546

- Fax Number: 855.8547

- Business Url: business1.com

Business Card #2

Attributes:

- Width: 4 inch

- Height: 3 inch

- Material: plastic

Behaviours:

- Phone Number: 855.8546

- Fax Number: 855.8547

- Business Url: business2.com

Diagram 2, explains how an object-oriented program works. As the picture shows, it consists of many encapsulated objects that interact by sending messages.

Diagram 2:

structured_program-2

Conclusion

Today, OOP languages are much more attractive than structural programming languages. The main reason for object oriented programming being so successful is the fact that it brings the concepts we use in the real world (along with the business logic) into programming and allows programmers to characterise object properties and behaviours precisely.

We could go into lenghy discussion about pros and cons of OOP vs Structured programming, go into details about what is a class, association, aggregation, inheritance, etc., but let’s just conclude by saying that Object Oriented programming makes it possible to simplify, and abstract anything we may want to describe in our code. Simply said, the OOP languages better reflect the human way of thinking about conceptualising objects.

References

Programming paradigm (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Programming_paradigm#Further_paradigms (Accessed: 25 September 2016).

Mowforth, L. (2016) What is object oriented programming?. Available at: http://blog.careerfoundry.com/web-development/what-is-object-oriented-programming (Accessed: 26 September 2016).

Structured Programming (2016) Available at: http://www.et.byu.edu/~rhelps/eet340/html/structured_program_design.htm (Accessed: 26 September 2016).

Structured programming (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Structured_programming (Accessed: 26 September 2016).

Modular programming (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Modular_programming (Accessed: 26 September 2016).

OOP (2016) in Wikipedia. Available at: https://en.wikipedia.org/wiki/Object-oriented_programming (Accessed: 26 September 2016).

How to explain OOP concepts to a nontechnical person? (2016) Available at: http://programmers.stackexchange.com/questions/34584/how-to-explain-oop-concepts-to-a-non-technical-person (Accessed: 26 September 2016).

Business card size specifications and dimensions (no date) Available at: http://www.printingforless.com/Business-Card-Specifications.html (Accessed: 26 September 2016).