Question:

What is the differnce between strucured programming and object-oriented programming?

by  |  earlier

0 LIKES UnLike

What is the differnce between strucured programming and object-oriented programming?

 Tags:

   Report

2 ANSWERS


  1. Structured, or as I call it 'procedural', programming differs from OO (object oriented) programming in a lot of ways. Procedural is basically a program with a code which is executed line by line from top to bottom with method calling. OO programming is unique and opens doors for some real complex and exciting coding. With OO programming the code does not just start top to bottom and done, it has different files (classes) which have thier own behavior and state. You can call these classes if you need multiples of it. Example: Your recreating a zoo and you need animals.

    Animal cat = new Animal();

    Animal dog = new Animal();

    The class animal has created two 'objects' which are animals in the zoo. Inside animal the coding would look like so.

    public class Animal{

    public String animalName;

    public String animalHeight;

    public String animalWeight;

    public walk(){

    }

    }

    If you wanted the animal to have a name after you created it you can go, dog.animalName = "Puppy";

    OO programming is for programs where you need to duplicate or assign a state anbd behavior to something.  


  2. This is too complex a question to really answer in a few words or paragraphs, you need to read a book.

    But here it is in a nutshell.  Structured programming and Object Oriented programming represent what are called contrasting programming "paradigms".  A paradigm is an abstract concept somewhat hard to grasp, but it represents a distinct way of viewing the world or any particular group of concepts.  Even though most people don't think of it that way each programming language represents an approach to modeling a domain and representing problems and solutions in that domain in code.

    In a structured paradigm, you describe your concepts as a set of variables which represent the state of your domain and functions/procedures/operations on that state.  To solve your problem you start out representing your problem state (as variables) and you need to come up with the right set of procedures where you transform the problem state to the solution state and you have your answer.

    In Object Oriented Programming (OOP), you represent your domain as cohesive concepts called Objects.  Each Object represents one complete concept replete with its variables and functions/procedures (generally called methods in the OO world). You start out describing your problem state in terms of its interrelated objects and objects interact through their methods till you reach a solution state.

    I know that is very abstract so lets think about it in a tangible way. Lets say you want to boil an egg in your kitchen by taking an egg from the fridge, putting it in water in a pan, boiling it, taking it off the stove and cooling it.

    In a structured paradigm, you would define your problem solving activity as a collection of the following procedures:

    - open fridge

    - take out egg

    - fill pan with water

    - place pan on stove

    - turn on stove

    - turn off stove

    - empty water

    - peel egg

    In an OO paradigm  you will first collect the objects in your domain. These are: fridge, egg, pan, stove.  Then you describe the abilities (or methods) of each.

    Fridge - contain objects

    egg - get peeled

    stove - turn on, turn off

    pan - fill with water, put in egg

    Then you come up with the right sequence of interactions of those methods to prepare a boiled egg.

    On the one hand both approaches end up with the same solution (which is obvious).  But in the OO approach you tend to describe the domain in a manner closer to how you understand it in real life.  Since you are giving a more abstract and complete definition of each object you an more easily reuse pieces of your solution to solve a different related problem. For example if you were going to prepare pasta instead, the stove object would be unchanged, the pan modified slightly and you would have to add a pasta object.

    I won't go into all the details here but OO generally tends to be a more robust and reusable way of solving programming problems. This is the right way of thinking about it.  It is true that there are superficial differences like creating more files, writing headers, so on and so forth but they are just the mechanics.  They really represent different ways of understanding and representing problems.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.