Question:
Difference example code Procedural Language compared to Object Orientated.?
Reesecups.
2010-02-11 13:22:19 UTC
I know both these languages are similar in a way but i would like an example of two codes under procedural language and object orientated and the differences between then.
Three answers:
J.J.'s Advice / Avis de J.J.
2010-02-11 13:41:39 UTC
Procedural code is very much a script. C is a mainly procedural language.

1- Prompt user for input

2- Scan input buffer for requested input

3- Do something with the input

4- Show the result to the user



Object-oriented programming relies on classes, functions, objects, pointers, etc. I think of it like this. When you program your microwave to cook something for 2 minutes, you don't need to know how the microwave works internally. You just need to know what type of data the microwave accepts (cold food item and cooking time) and wait for it to return something (the heated food).



1- x is an object of the class "Calculations".

2- call function x->getuserinput.

3- call function x->calculateSum

4- call function x->showResult



At first glance object-oriented computing seems more complicated than procedural computing, but for large-scale projects it's much more conveniant. With procedural code you end up writing out the same operation multiple times. You just have to write the procedure once, and call it in the main script whenever you want to use it. You can even take your classes and use them in multiple programs.
2010-02-11 14:10:07 UTC
The actual advantage to classes is that the class is a black box. Call it to get user input and it returns a string. If you find a more efficient way to get user input and make a string out of it, you change the code in the class, but the call (your actual program) stays the same. This is handy in a number of ways. Someone good at writing classes can keep improving the class, while someone good at writing interfaces doesn't have to change his use of the class. Changing operating systems may require a total rewrite of, say, how you send an email, but email>send(to, from, subject, body) remains the same call, and it returns the same result.
?
2016-11-09 01:53:57 UTC
the version is incredibly in the way you think of roughly issues getting executed. merchandise oriented programming is frequently promoted simply by fact it abstracts away lots of info. i will assert issues like myShape.section() and it could return the component to the form without you having to appreciate the small print of ways it grow to be executed. i grow to be in no way super at describing procedural, yet I even tend to think of of scripting languages like Perl.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...