12

I am making a presentation that shows the differences between structural and object oriented programming and I want to illustrate why people need OOP with an example where applying OOP concepts will make coding much easier so that the audience really feel that they need OOP .

Any Ideas ??

11
  • 2
    What is your audience? Experienced non-OO programmers (cobol, etc)? low-experienced programmers (students, etc)? Executives (non programmers at all)?
    – Andre
    Commented Apr 4, 2011 at 19:14
  • low experienced .
    – Ahmed
    Commented Apr 4, 2011 at 19:18
  • @Ahmed if they're low experience for the love of all that is good, instill in them in the real world code changes a lot!!!
    – corsiKa
    Commented Apr 4, 2011 at 19:26
  • 4
    I wish some OO programs were structured better. Commented Apr 4, 2011 at 19:29
  • Have you checked out Wikipedia yet? The article contains a brief explanation about why OO was invented and what problem it was intended to solve. Commented Apr 4, 2011 at 19:30

7 Answers 7

28

You might want to go look at this quick video blog. The upshot is that the difference between structured programming and OO programming is a matter of what they take away from programming, not about what they add. Software disciplines like Structured Programming and Object Oriented Programming are constraining, not enabling. Here are some definitions. Warning: you aren't going to like them.

  • Structured programming is discipline imposed upon goto (direct transfer of control)

  • OO programming is discipline imposed upon pointers to functions (indirect transfer of control)

  • Functional programming is discipline imposed upon assignment.

    The first is not too hard to understand. Dijkstra found that it was impossible to create general proofs of correctness when goto was allowed in algorithms. However if control structures were limited to sequence, selection, and iteration, then proofs of correctness were possible. Of course we don't even try to prove things correct nowadays, but we do like the simplicity and elegance of structured programming.

It's a little harder to understand OO. We often define OO as encapsulation, inheritance, and polymorphism. What is lesser knows is that all three of these attributes are achievable, and frequently were achieved in C. Indeed, C++ started as just a preprocessor that compiled down to C. It's not actually hard to encapsulate in C. Nor it is hard to build data structures that are subsets of each other, simulating inheritance. Polymorphism, however, is a bit harder. It requires pointers to functions which, in C, are difficult to manage well. What languages like C++ gave us was discipline imposed upon those pointers to functions. The C++ compiler built the vtables for us, and initialized the pointers within them according to a strict formalism. So in a very real sense OO is simply discipline imposed upon indirect transfer of control i.e. pointers to functions.

Structured programming is about how not to use goto. OO is about how not to use pointers to functions. And functional programming too is all about what not to do. In functional programming we do not assign variables except in the most stringently controlled cases.

So in the end, all these Programming "technologies" are actually constraining disciplines rather than enabling technologies. They tell us what not to do more than they tell us what to do. And that means that software development has not grown over the last 40 years. Rather, it has shrunk. It is become ever more constrained as we have learned all the things we shouldn't do.

Learning what not to do is good; but here's the disturbing question: What new things have we learned to do?

2
  • @Ahmed : +1 for "TL;DR, thanks for Video"-suspicious comment (kidding)
    – n611x007
    Commented Jun 23, 2012 at 17:55
  • 1
    link rot... dead link Commented Jan 12, 2017 at 20:38
8

There are 3 basic ways to program a computer:

  1. Unstructured programming -- with gotos, like in old BASIC interpreters, or in assembly language. Few people program this way anymore.
  2. Structured imperative programming -- like in C, or PASCAL.
  3. Structured functional programming -- like in Haskell, ML, or Lisp.

In my view, object oriented programming is something different. It's about how to organize your program on a larger scale. It doesn't replace or obsolete any of the 3 paradigms I mentioned above -- within a method body, you still need to pick one of the 3 paradigms from the list to write in.

2
  • I don't understand you well ! You mean we must be using one of the 3 paradigms but WE don't know .. and OOP is just about more organization ??
    – Ahmed
    Commented Apr 6, 2011 at 11:56
  • You can't program without learning either structured imperative programming or structured functional programming. Those two paradigms are about getting things done. OOP, on the other hand, is about program modularization that only comes into play once your program's reached a certain size. Though it definitely appears in the libraries you use when programming all the time, one can have a perfectly good class library without OO features like inheritance, for example the class libraries of Haskell, LISP, or Standard ML.
    – Ken Bloom
    Commented Apr 6, 2011 at 13:01
4

It's all about how you anticipate change.

Both concepts lend themselves to reusablility, but OOP opens the door to easier changes. OOP has all the reusability that Structural programming does, but you can also use it to create new functionality with less effort.

You could say that OOP inherits all the functionality of Structural Programming with the additional functionality of inheritance! :-D

9
  • I'm not very fond of inheritance at this moment.
    – Baltasarq
    Commented Apr 4, 2011 at 19:22
  • 4
    Neither am I, but that's because the government screwed my grandfather out of his pension. In terms of OOP, however, inheritance has served me quite well!
    – corsiKa
    Commented Apr 4, 2011 at 19:25
  • 2
    @Janx: "How often do you actually build a superclass as opposed to an Interface?" Huh? You don't "build superclasses"; you take existing classes and build subclasss from them, and you do that all the time. If you're not using inheritance, you're not getting the benefits of Liskov substitution and polymorphism, so what are you doing in object-oriented programming in the first place? Composition is a different tool with a different use case, not a replacement for inheritance. You shouldn't "favor" one over the other; you should use both, each for what they're useful for. Commented Apr 4, 2011 at 22:44
  • 1
    @Mason - worth noting that Barbara Liskov (of the Liskov Substitution Principle) actually said (long video) she doesn't particularly like inheritance. Commented Apr 5, 2011 at 4:03
  • 1
    that is, she doesn't like implementation inheritance, but likes type hierarchies. she talks about it at about 44 minutes into that video. Commented Apr 5, 2011 at 4:47
3

The concepts are orthogonal. Structured programming is about structuring code within procedures/functions/methods. It is perfectly possible (and desirable) to follow the principles of structured programming within class methods when doing OOP.

1
  • Structured programming is good compared to unstructured. So you should do structured programming when doing OOP.
    – gnasher729
    Commented Sep 30, 2023 at 17:02
1

That's kind of a subjective wording--structured programming and OOP are styles of solving problems, and one isn't always better than the other. Writing a numerical methods library makes a good deal of sense if done in a structured style, where you are performing transforms on input data. A simple agent driven by a state machine, though, can be easily expressed as a self-contained class in Java or C++. OOP can be a natural way of expressing storage containers for data structures.

Talking about information hiding and modularity is a good way to naturally motivate OOP as a style.

An interesting take on this issue was written up by Steve Yegge--in some ways, one of the better descriptions of the differences in approaches between the two styles.

0

OOP is easier to understand when you make business model. When you think about elements of application you use some OBJECTS and RELATIONS between them e.g. Book has Author(s), Title, ISBN. Book is to let in Library and could be borrowed by Student. Structural programming enforces thinking about specific processes, implementations not in abstraction.

OOP is designed to easy changes. Change in structural program is possible but must be described by code. Change in OO program could be described by abstract model change.

0
0

Variable Scope:

I think a principle of the languages to ensure good programming is to restrict the scope of the variables. In structured languages like C, the scope is mainly of two types-

  • Global scope
  • Local/Function/Method Scope

We all know the global scope is harmful. But sometimes the local scopes are not enough to run the program. Avoiding global scopes then tends to more wide use of pointers, which enable use of variables outside scope. But pointers are difficult to understand and use.

The OOP languages like C++ adds a new type of scope- Class/Object scope through encapsulation. This scoping is further enhanced by the private/public variations. And this solves many problems of variable scoping. The scopes are more defined in OOP. And pointers are less needed.

This is one of the great features of OOP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.