Jump to content

OOP VS procedural

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
encio

encio

    Newbie

  • Members
  • PipPip
  • 23 posts
sorry ask this nooby question..

but can someone explain the difference between object oriented and procedural programming, in terms that a 10 yr old child can understand:crying:...

or maybe 15 yr old?

help is very much appreciated..

thank you so much...

#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Procedural Programming provides a programmer a means to define precisely each step in the performance of a task. The programmer knows what is to be accomplished and provides through the language step-by-step instructions on how the task is to be done.

Object Orientation uses objects consisting of fields and methods to design programs. It also includes programming techniques like data abstraction, encapsulation, modularity, polymorphism, and inheritance.

Data Abstraction: allows handling data bits in meaningful ways. For example, it is the basic motivation behind datatype. (Datatype meaning int, string, boolean, and other types)
Encapsulation: (Information Hiding) the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation.
Modularity: a software design technique that increases the extent to which software is composed from separate parts, called modules.
Polymorphism: the ability of one type, A, to appear as and be used like another type, B.
Inheritance: a way to form new classes (instances of which are called objects) using classes that have already been defined.

Comparison of the two:
The focus of procedural programming is to break down a programming task into a collection of variables, data structures and subroutines, whereas in Object-Oriented Programming it is to break down a programming task into objects with each "object" encapsulating its own data and methods (subroutines). The most important distinction is whereas procedural programming uses procedures to operate on data structures, object-oriented programming bundles the two together so an "object" operates on its "own" data structure.
Nomenclature varies between the two, although they have much the same semantics:


object-oriented --> procedural
method --> function
object --> module
message --> function call
attribute --> variable
-CDG10620
Software Developer

#3
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
Object Oriented programming:

Dog dog = new Dog("Pluto", 5); // Pluto is 5 years old.
dog.bark();
dog.eat();
dog.playDead(5000); // 5000 ms.
Procedural programming:

char[] dogName = "Pluto";
int dogAge = 5;
bark(dogName, dogAge);
eat(dogName, dogAge);
playDead(dogName, dogAge, 5000);
------
Something like that, although it is probably not a good example, it should give you a hint.

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Procedural programming focuses first on the process to solve a problem, and secondarily on the data that needs to be recorded.

Object oriented programming focuses first on the data to solve the problem, and secondarily on manipulations of that data.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
encio

encio

    Newbie

  • Members
  • PipPip
  • 23 posts
what seems to be my problem in understanding these concepts is the language barrier, coz english is not my native language...

your explanation gave me an idea of what it is about, but still it's a bit cloudy to me..

Is it right thing to say that procedural programming concentrates on algorithms or steps, where as object oriented concentrates on the parts or pieces or details?

Can someone give an analogy on how, for example, a HOUSE will be built using procedural compare to OOP?

I'm really really sorry to waste your time, but I really want to understand these concepts.. Unfortunately, there's nothing in my dialect has an explanation on these matters...

Again thank you..

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It's the difference between a recipe and pets.

With a recipe, you have step-by-step instructions, and you happen to need ingredients, mixing bowls, etc, to complete them (procedural).

With pets, cats and dogs have different behaviors. Just bring them into the same home and they start interacting (OOP).
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
encio

encio

    Newbie

  • Members
  • PipPip
  • 23 posts
woot!... it's starting to make sense...

thank you soooo much guys for your time...

i will hug you if you are near me:-P

hopefully you can still help me in my future dilemma:)

thx..thx..

#8
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Hmm..House Analogy.

Procedural Programming: You have a list of tasks to be performed which are performed in order by one super-worker to create the house. The super-worker has access to every method for completing a given task and every piece of information needed can be accessed in that method.
Object-Oriented Programming: You have a number of different 'workers' (types) that have different 'abilities' (methods) and 'attributes' (fields) workers can interact with each other and components of the house to build it. For example, the electrician doesn't know how to lay bricks (whereas in the Procedural example our super-worker would know how to do both these things).

Lol, that probably makes no sense at all but, hell, it was fun to write.

#9
encio

encio

    Newbie

  • Members
  • PipPip
  • 23 posts
@semprance .. thx dude!!!

But correct me if I'm wrong... this concept varies on what programming language you are using right? and not by style of your coding?

#10
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
Indeed it does. For example, Java and C# use the object-oriented approach in nearly all applications. Languages such as BASIC on the other hand go entirely for the procedural approach. And then there are languages like C++ which combine a number of different approaches within one language.

Check out this wikipedia page for more info on programming concepts and styles: Programming paradigm - Wikipedia, the free encyclopedia

#11
encio

encio

    Newbie

  • Members
  • PipPip
  • 23 posts
ooohhhhh...

now things are starting to make sense...

at first I thought programming languages were developed to support a certain paradigm... never thought there's such thing as Multi-paradigm programming language...

so i was confused after reading a thread saying something like " OOP is good for long projects and Procedural for short ones"... and then I was like " how can you switch to Procedural if the language you are using supports OOP?????"

and then you guys came and lit up my way:thumbup:

heheeh TY!!

#12
semprance

semprance

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
No problem :-)