dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: What is the difference between procedural and object-oriented programs? Write simple

  1. #1
    Join Date
    Mar 2019
    Posts
    1

    What is the difference between procedural and object-oriented programs? Write simple

    What is the difference between procedural and object-oriented programs? Write simple

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,728

    Re: What is the difference between procedural and object-oriented programs? Write sim

    Do an Internet search. There are many articles available.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.1.6)

  3. #3
    Join Date
    Feb 2017
    Posts
    444

    Re: What is the difference between procedural and object-oriented programs? Write sim

    Quote Originally Posted by rajeshkumarr4r View Post
    What is the difference between procedural and object-oriented programs?
    Procedural languages have a fixed number of data types such as for example int, float, char and string, and there is a fixed number of operations on each data type such as for example addition and multiplication.

    Most object oriented languages have a procedural base but in addition offer the so called class concept. It allows programmers to introduce own new data types and define own operations on them.

    So procedural programming is about juggling a limited number of existing data types whereas OO programming is about introducing new data types by way of classes. There's more to it but that's the difference in a nutshell.
    Last edited by wolle; April 3rd, 2019 at 02:21 AM.

  4. #4
    Join Date
    Apr 2019
    Location
    Ahmedabad
    Posts
    7

    Re: What is the difference between procedural and object-oriented programs? Write sim

    Procedural Programming is the version of structured programming that uses functions (subroutines) to take input values and return (usually) changed values to the calling routine. It is the standard programming paradigm.

    Object oriented programming believes in encapsulating behavior and values in objects, which can be seen as analogs for the tasks that the program would look to accomplish. An objects will exist in memory by virtue of being instantiated before its methods are invoked. An object will be an instance of a class, which will have data and methods, which one of the things that differentiates an OO class from a procedural function: i.e. a class can have many methods exposed via the object where a function or subroutine is going to have a single interface.

  5. #5
    Join Date
    Mar 2019
    Posts
    18

    Re: What is the difference between procedural and object-oriented programs? Write sim

    Procedural Programming is the version of structured programming that uses functions (subroutines) to take input values and return (usually) changed values to the calling routine. It is the standard programming paradigm.

    Object oriented programming believes in encapsulating behavior and values in objects, which can be seen as analogs for the tasks that the program would look to accomplish. An objects will exist in memory by virtue of being instantiated before its methods are invoked. An object will be an instance of a class, which will have data and methods, which one of the things that differentiates an OO class from a procedural function: i.e. a class can have many methods exposed via the object where a function or subroutine is going to have a single interface.

    Classes are supposed to be built around behavior of the overall program where functions are generally implementations of specific routines to accomplish task items and are generally implemented in a somewhat linear manner:

    variableC = subroutineA(variableA);

    subroutineB(variableC); #Changes variable C by reference

    subroutineC(variableC); Prints variable C

    With of course some conditional logic wrapping around the functions. An object oriented program may or may not have may or all of its classes’ objects instantiated and may consume various bits of data or messages depending on the architecture of the program in a way that is generally quite different that a procedural program would, though at times they can seem superficially similar.

    a quick and dirty version of an OO program might be:

    InstanceVariableA = new TaskClassA();

    InstanceVariable.ReadVariable(variableB)

    instanceVariable.ReadVariable.print (to output value of variableB)

    There is much more to it, but there is a nutshell version.

  6. #6
    Join Date
    Mar 2019
    Location
    USA
    Posts
    2

    Re: What is the difference between procedural and object-oriented programs? Write sim

    Procedural Object-oriented

    procedure method
    record object
    module class
    procedure call message

  7. #7
    Join Date
    Feb 2017
    Posts
    444

    Re: What is the difference between procedural and object-oriented programs? Write sim

    I'd like to clarify my post #3.

    The key difference is the class concept available in OO languages. It allows programmers and library providers to define new types. To see how this works, let's have a look at the initialization statement available in every language. Formally it's usually defined something like this,

    <type> <variable> = <value>;

    In both procedural and OO languages it can look like this where int (a primitive) is defined by the language,

    int n = 5;

    In an OO language one can also find this where Int (a class) is not defined by the language but by someone else,

    Int n = new Int(5);

    Comparing these it's easy to see that,

    - the primitive int and the class Int are both <types>,
    - n is the <variable> in both cases, and
    - the literal 5 and the object returned by new Int(5) are both <values>.

    This illustrates how the OO concept is seamlessly integrated with a procedural base. All the fundamentals of a procedural language are there. The only difference is that thanks to the class concept an OO language allows new types to be defined by way of classes. In short:

    OO language = procedural language + classes.

    So the key player is the type. It defines all operations that can be performed on the values of the type. For example the int type most likely defines a plus operation and so does the Int type. It follows that the methods of a class are not procedures in the procedural sense. They are definitions of operations on the objects of a class. But procedures are still available in OO languages. In Java for example a method can be turned into a procedure by declaring it static. Check out the Math class for example. Furthermore, an object is a value and not a record in the procedural sense. But records can easily be mimicked in OO by defining classes with publicly exposed variables only and no methods. Note that the terminology of OO is applicable also on procedural primitive types such as int, float and char. These can be viewed as classes with objects and operations, only they constitute a fixed part of the language.

    In summary, the only difference between procedural and OO languages is the class concept which allows new types to be defined. This fosters a programming style with focus on how to create and combine types, rather than how to organize procedures. As I said in #3, there's more to it but that's the difference in a nutshell.
    Last edited by wolle; April 16th, 2019 at 11:00 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)