Structured Programming vs. Object Oriented Programming

IES Virgen del Carmen (Jaén)

Structured Programming vs. Object Oriented Programming

by Rafael García Cabrera

Programming Paradigms (I)

Programming paradigms are a way to classify programming languages based on their features.

A programming paradigm is a fundamental style of computer programming.

Programming paradigms differ in how each element of the programs is represented and how steps are defined for solving problems.

Programming Paradigms (II)

Some paradigms are concerned mainly with implications for the execution model of the language, such as allowing side effects, or whether the sequence of operations is defined by the execution model.

Other paradigms are concerned mainly with the way that code is organized, such as grouping a code into units along with the state that is modified by the code.

Yet others are concerned mainly with the style of syntax and grammar.

Common Programming Paradigms

Programming language

A programming language is a formal language, which comprises a set of instructions used to produce various kinds of output. Programming languages are used in computer programming to create programs that implement specific algorithms.

Programming language

books

Multiparadigm programming languages

Many of the most widely used programming languages (such as Java, Python, C++, PHP, JavaScript etc.) are multiparadigm programming languages that support object-oriented programming to a greater or lesser degree, typically in combination with imperative, procedural programming.

Object-oriented programming

Some languages

Object Oriented Programming (OOP) and Structured Programming are two programming paradigms.

As the name suggests, OOP focuses on representing problems using real-world objects and their behavior,

while Structured Programming deals with organizing the program in a logical structure.

Structured Program Theorem (I)

The structured program theorem, also called Böhm-Jacopini theorem, is a result in programming language theory. It states that a class of control flow graphs (historically called charts in this context) can compute any computable function if it combines subprograms in only three specific ways (control structures).

Structured program theorem

Structured Program Theorem (II)

The theorem states that it is possible to write any computer program by using only three basic control structures:

  1. Sequence: ordered statements or subroutines executed in sequence.
  2. Selection: one or a number of statements is executed depending on the state of the program.
  3. Iteration: a statement or block is executed until the program reaches a certain state, or operations have been applied to every element of a collection.

Control flow

In computer science, control flow is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language.

Control flow

Sequence

Hello World Sequence

Selection (Conditional)

In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. Apart from the case of branch predication, this is always achieved by selectively altering the control flow based on some condition.

Conditional (computer programming)

Selection

If Then Else diagram

Iteration (While loop)

In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.

While loop

While loop

While loop diagram

Iteration (Do while loop)

In most computer programming languages, a do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block.

Do while loop

Do while loop

Do while loop diagram

Iteration (For loop)

In computer science, a for-loop is a control flow statement for specifying iteration, which allows code to be executed repeatedly.

A For loop has two parts: a header specifying the iteration, and a body which is executed once per iteration. The header often declares an explicit loop counter or loop variable, which allows the body to know which iteration is being executed. For-loops are typically used when the number of iterations is known before entering the loop. For-loops can be thought of as shorthands for while-loops which increment and test a loop variable.

For loop

For loop diagram

Iteration (foreach loop)

For each (or foreach, sometimes called an iterative for-loop) is a control flow statement for traversing items in a collection. Foreach is usually used in place of a standard for statement. Unlike other for loop constructs, however, foreach loops usually maintain no explicit counter: they essentially say “do this to everything in this set”, rather than “do this x times”. This avoids potential off-by-one errors and makes code simpler to read. In object-oriented languages an iterator, even if implicit, is often used as the means of traversal.

Foreach loop

What is Structured Programming? (I)

It is assumed that the birth year of Structured Programming is 1970. Structured programming is considered a subset of imperative programming.

Imperative programming is a programming paradigm that uses statements that change a program’s state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform. Imperative programming focuses on describing how a program operates.

What is Structured Programming? (II)

Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection (if/then/else) and repetition (while and for), block structures, and subroutines.

Structured programming

What is Object Oriented Programming? (I)

In OOP, the focus is on thinking about the problem to be solved in terms of real-world elements and representing the problem in terms of objects and their behavior.

Classes depict the abstract representations of real world objects. Classes are like blueprints or templates, which gather similar items or things that can be grouped together. Classes have properties called attributes or fields. Attributes are implemented as global and instance variables.

What is Object Oriented Programming? (II)

Methods in the classes represent or define the behavior of these classes. Methods and attributes of classes are called the members of the class. An instance of a class is called an object. Therefore, an object is a data structure that closely resembles some real-world object.

There are several important OOP concepts such as Data abstraction, Encapsulation, Polymorphism, Messaging, Modularity and Inheritance.

Typically, encapsulation is achieved by making the attributes private, while creating public methods that can be used to access those attributes.

What is Object Oriented Programming? (III)

Inheritance allows the user to extend classes (called sub classes) from other classes (called super classes).

Polymorphism allows the programmer to substitute an object of a class in place of an object of its super class.

Typically, the nouns found in the problem definition directly become classes in the program. And similarly, verbs become methods. Some of the most popular OOP languages are Java and C#.

The key difference

The focus of Structured Programming is to structure the program in to a hierarchy of subprograms while, the focus of OOP is to break down the programming task in to objects, which encapsulate data and methods.

OOP is considered more flexible than structured programming, because OOP separates a program in to a network of subsystems rather than structuring the program in to a hierarchy. Even though structuring provides certain clarity, a small change to a very large structured program may cause a ripple effect of having to change multiple subprograms.

Focuses on process or data

Structured Programming is designed which focuses on process/ logical structure and then data required for that process.

Object Oriented Programming is designed which focuses on data.

Top-down or bottom-up approach

Structured programming follows top-down approach.

Object oriented programming follows bottom-up approach.

Modular programming vs. OOP Concepts

Structured Programming is also known as Modular Programming and a subset of procedural programming language.

Object Oriented Programming supports inheritance, encapsulation, abstraction, polymorphism, etc.

Functions or Objects

In Structured Programming: Programs are divided into small self contained functions.

In Object Oriented Programming: Programs are divided into small entities called objects.

Data hiding

Structured Programming is less secure as there is no way of data hiding.

Object Oriented Programming is more secure as having data hiding feature.

Program complexity

Structured Programming can solve moderately complex programs.

Object Oriented Programming can solve any complex programs.

Reusability

Structured Programming provides less reusability, more function dependency.

Object Oriented Programming provides more reusability, less function dependency.

Abstraction

Structured Programming: Less abstraction and less flexibility.

Object Oriented Programming: More abstraction and more flexibility.

Practice

blah

Question 1

Follow top-down approach to program design

Structured Programming Language

Question 2

Follow bottom-up approach in program design

Object Oriented Programming Language

Question 3

Data and Functions don’t tide with each other

Structured Programming Language

Question 4

Data is hidden and can’t be accessed by the external world

Object Oriented Programming Language

Question 5

Large programs are divided into smaller self contained program segment known as functions

Structured Programming Language

Question 6

Functions are not dependent so reusability is possible

Object Oriented Programming Language

Question 7

A program is decomposed into a hierarchy of processes

Structured Programming Language

Question 8

It splits the program into objects that can be reused into other programs

Object Oriented Programming Language

Question 9

It is less secure as there is no way of data hiding

Structured Programming Language

Question 10

It can solve any complex programs

Object Oriented Programming Language

Web References

Wikipedia References

Slide presentation credits

Slides generated from Slide Show (S9):