Nov 21, 2009

Why Must We Learn Object Oriented Programming - help me to understand the benefit of OOP

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > C/C++ Programming

Why Must We Learn Object Oriented Programming - help me to understand the benefit of OOP

.hack//GU
As a software laboratory assistant, I teach the class of Object Oriented Programming. Everything went well until one day a student of mine ask me a simple problem like this Q/A:

him : Why must we use Object oriented Programming? I thought the usual one could do almost everything.
me : Well, in Object Oriented Programming we could make a class, so basically eveything could be made to an 'object' in our mind.

him : That's why I'm asking, why must we made everything an object? What's the difference?
me : In Object Oriented Programming, Encapsulation is the basic part and because of that concept, we could make an object with parameters / data and methods / functions in just one object / class.

him : Are you saying the programming will be simpler?
me : Not really, but in our mind it is far easier when the class is made up and we just use the object freely in our program.

(okay, that's the intro, now the things I couldn't explain...)

him : Just in case I made the program in usual (not OOP), what's the difference?
me : well, you can hide the data in data hiding concept of encapsulation.

him : We hide data from our own selves as programmers, if we didn't let the user do something the data won't be shown and we don't need to hide any data.
me : I guess... that's how we put it... hmm, in OOP we could use spesific methods related to spesific class I think.

him : Instead of using like ball.animate() why don't we use animate(ball) (ball in struct)? It is easier right?
me : But, to make animate() for several class inhereted from one, we can use similar name.

him : Just use if... just like this void animate(struct ball ball) { if(ball.type==1) animate1() else if(ball.type==2) animate2(); } we could do it right??
me : ...

So I couldn't say anything to him, only to promise him to answer next time I teach them next Tuesday...
I've questioned the same ones to my friends but none of them can help. Please someone help me...

 

 

 


Comment/Reply (w/o sign-up)

pointybirds
Hi,

Certainly there are some things you can do adequately with good old procedural programming -- Turing even posited that you can simulate any possible computer with a few symbols -- it's just that certain types of programming problems lend themselves better to the OO way of doing things, and I'm thinking specifically of two of OO's main features: inheritance and polymorphism.

To use your ball example, the code could become unwieldy when you start getting lots of different ball types, and you have to keep track of them all manually with a .type element in a struct, and select between them with IF statements. The OO folks would have you create an overarching "ball" class, with basic actions for a ball such as bounce(), rollI(), animate() etc. Then, for different types of ball, you subclass this into classes like Football and Tennisball and override the generic methods as required ... some balls bounce higher than others, that kind of thing. Now the code itself is taking care of what _particular_ subclass an object is, and you don't necessarily have to know or care. You can also code other objects with animate() methods, and call them in a loop:

for object in (objects) {
object.animate()
}

There's nothing invalid about the procedural way of doing it, it's just not as clean and maintainable for certain applications such as GUI programming where objects fall naturally into classes. Also, I think you'll find that if you do it procedurally you'll spend a lot of your time reinventing ways of dealing with objects that OO specifically sets out to solve.

I would suggest reading up on some of the fundamentals of what makes OO OO (if that makes sense) before your next class so you don't get any more zingers. I've been there before and it's not comfortable. smile.gif Good luck.

 

 

 


Comment/Reply (w/o sign-up)

djole_home
OK I prefer use of strict C bat C++ have one advantage you forget! Code reuse! I make some class and do not have to write same code again if I need object like this with some more property or method, just inherit from parent class and code additional elements.

Comment/Reply (w/o sign-up)

Tetraca
I don't personally like Object Oriented Programming. Procedural programming is what I like. I find that it has a better logical flow. Which one you want to program with is up to you. Rich Stallman actually hates OOP but other people actually like it. Whichever you can program more competently in is what you should use, and it is truly your option for many popular languages.

Comment/Reply (w/o sign-up)

alex7h3pr0gr4m3r
I also dislike object oriented programming. When I have a choice between it and regular coding I always choose structured, regular coding. BUT it is sometimes necessary to use OOP (or at least OOP would make it WAY easier). For example if you are creating a game or a simulation where you must control many different instances of an object like an enemy or whatever the simulation is simulating. Instead of creating an array and hardcoding all of the objects into the program it is much easier to make a class and make instances of that class (for me at least).

For your ball.animate example, what if the animate function changes ball in some way? that would be impossible using animate(ball) unless you are using pointers which is extremely annoying to me.

Comment/Reply (w/o sign-up)

Tran-Gate
With Oriented-Object Programming (OOP), you can encrypt data making it safe with encapsulation? Can you also have an object access a general class of attributes/elements? I am confused on what an object is.... Game-wise, is it like an object in a game kinda like what pointybirds said where it has somewhat like characteristics?

QUOTE
To use your ball example, the code could become unwieldy when you start getting lots of different ball types, and you have to keep track of them all manually with a .type element in a struct, and select between them with IF statements. The OO folks would have you create an overarching "ball" class, with basic actions for a ball such as bounce(), rollI(), animate() etc. Then, for different types of ball, you subclass this into classes like Football and Tennisball and override the generic methods as required ... some balls bounce higher than others, that kind of thing. Now the code itself is taking care of what _particular_ subclass an object is, and you don't necessarily have to know or care. You can also code other objects with animate() methods, and call them in a loop:


Objects like cars, houses, people, creatures, etc.?

Comment/Reply (w/o sign-up)

xpress
QUOTE(Tran-Gate @ Oct 24 2008, 05:47 AM) *
With Oriented-Object Programming (OOP), you can encrypt data making it safe with encapsulation? Can you also have an object access a general class of attributes/elements? I am confused on what an object is..
Objects like cars, houses, people, creatures, etc.?


No No No...Encapuslation is not Encryption. Even they have no relation at all. Encapusulation is hiding data. It is the mechanism that binds the code and the data it manipulates.... OK, I will make it clear with an example.

First let us see what is a class, object etc...later we will see these definitons relate to our example. Later we will go to encapsulation.

Class: A class is a logical construction. It defines the structure and behavior (data and code) that will be shared by a set of objects.

Object: Object is the physical reality of the class.

For example, As you said, we can call cars, houses etc....as Objects. Then what is a class? It is logical construction of the object. That is for example, A Four Wheeler is a class. It is logical. Four wheeler can be anything. A car, a bus, a jeep.

So The Class FourWheeler defines that a FourWheeler has Four wheels, It has a steering, it has breaks. This is the structure of the FourWheeler.

And, The behavior of FourWheeler is, it runs when you press accelerator. It stops when you apply break. So we can call accelerate and pressingBreak as methods(or functions).

And A Car is one Object of FourWheeler. It has 4 wheels, it has steering etc...It runs when you press accelarator.
So the Object Car has all properites of its Class FourWheeler. A bus is also an object of FourWheeler class. It has the same properites. If you change the behavior or structure of the class, all of its objects will be affected.
I think, it is clear to you now, what is object and what is class.

OK, lets move to Encapsulation. I already told you, encapsulation is hiding data. But how? With encapsulation, data in a
class can be kept private and cannot be accessed directly outside by its class. So, with encapsulation data can be kept safe from corruption. You can access this data only by well defined methods(or functions).

Lets see it by taking our Forum as an example. As a normal member of this forum, you can make a new post. You can also edit your post. But, can you edit other's posts? No. Why? That is encapsulation. Your posts are private to you. Others have no access to edit your posts. Edit button( simply Edit function) is well defined function for your post(data). But Editing to your post is visible to you only. Others cannot see it. So the data is hidden from them.

I hope you understand it now. Ask any doubts you have, if you don't understand this.

And about our concept, Why must we learn Object Oriented Programming....
Object oriented programming is meant to manage the complexity easily. For small programs, the procedural programming (structured programming) looks easy, but as the program grows longer and logner (complexity increases) it is very difficult to
write and manage the program. Object oriented programming makes it easy. And also with OOP it is very easy for teams to work on a single project. Procedural programming is based on flow charts and top down approach. OOP based on Objects.
Pesonally I prefer Object Oriented Programming.

Comment/Reply (w/o sign-up)

Sandeep Singh
QUOTE
Hi,

Certainly there are some things you can do adequately with good old procedural programming -- Turing even posited that you can simulate any possible computer with a few symbols -- it's just that certain types of programming problems lend themselves better to the OO way of doing things, and I'm thinking specifically of two of OO's main features: inheritance and polymorphism.

To use your ball example, the code could become unwieldy when you start getting lots of different ball types, and you have to keep track of them all manually with a .type element in a struct, and select between them with IF statements. The OO folks would have you create an overarching "ball" class, with basic actions for a ball such as bounce(), rollI(), animate() etc. Then, for different types of ball, you subclass this into classes like Football and Tennisball and override the generic methods as required ... some balls bounce higher than others, that kind of thing. Now the code itself is taking care of what _particular_ subclass an object is, and you don't necessarily have to know or care. You can also code other objects with animate() methods, and call them in a loop:

for object in (objects) {
object.animate()
}

There's nothing invalid about the procedural way of doing it, it's just not as clean and maintainable for certain applications such as GUI programming where objects fall naturally into classes. Also, I think you'll find that if you do it procedurally you'll spend a lot of your time reinventing ways of dealing with objects that OO specifically sets out to solve.

I would suggest reading up on some of the fundamentals of what makes OO OO (if that makes sense) before your next class so you don't get any more zingers. I've been there before and it's not comfortable. smile.gif Good luck.


Notice from serverph:
copied from old trap17 post

Comment/Reply (w/o sign-up)

Tran-Gate
xpress.....I LOVE YOU~!!! I always find you helping me with questions or doubts. So Encapsulation is hiding data. Encryption is transforming information using an algorithm. A class is a set of properties. Objects of a class are like things that contain properties of the class. THANKS XPRESS~!! Oh, and if I misunderstood, please PM me. =)

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : learn, onject, oriented, programming, understand, benefit, oop

  1. I Want To Learn Programming
    (7)
  2. Finding The Rgb Color Of An Image
    Using any programming language (6)
    hello friends i am doing a project , in that i am inneed to fine the mean RGB value of a particular
    image , is there any program in any language which can do this ? the input to the program will be
    any image ( can be linked in the program) and the putput must be the mean RGB value of that
    particular image , is this Possible ? If so please post the Coding , no matter in what ever language
    it may be written.Thanks in Advance....
  3. Alright, I'm Taking Computer Programming As A Class In School.
    (10)
    Is there anything I should personally be worried about or anything I really need to know? I'm
    pretty much good with computers and such and pretty much spend my whole life on them, lol.....
  4. Discussion On Dynamic Programming
    (3)
    Dynamic Programming is one of the powerful programming approach now a day. DP applicable when sub
    problems share sub sub problems. (No independent sub problems). Solve each sub problem once, save
    the answer, and when needed use the previously computed result. Like for Fibonacci series. To get
    f(n+1) we need addition of f(n), f(n-1) and for f(n) we need f(n-1), f(n-2). so to get f(n+1) we
    need f(n) and f(n-1) and again for f(n) we need f(n-1) and f(n-2). In this approach we are
    calculating same thing more then once . That is a very bad idea. But what if we store the data....
  5. C Programming Video Tutorials
    This is for all the memebers out there looking or need some mroe help (3)
    Hello per this is for the memeber that want to start programming in " C "... C is a
    very powerful Programming Lang In fact mayb to powerful.. Well there is 138 Videos in the
    TUT.. I Have uploaded the it so per .rar is per chapter /smile.gif"
    style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> P@ssword for ALL .rar files
    is : sid3arm chapter #1 = Introduction to C ** Download link ** chapter #2 = A
    basic C program ** Download link ** chapter #3 = Basic Elements of a C Program **
    Download link ....
  6. C Or C++ Easy Programming Generator
    You need a program? (6)
    Hi i just had a stupid question on how to program is C or C++. I would like to know if there is any
    program like Photoshop to create C codes or how to put them together. If someone could show me it
    would be great. I appreciate it as i love computers and want to be like a wiz at it and also
    everything related to it. I know that this is crazy and i have heard that from people they tell me
    you're a GFX person stay there but i want to explore. Thanks if helped.....
  7. How Many of You Use the C Programming language?
    (23)
    Just wanted to know how many of you are currently using C language for programming. If you can tell
    what sort of programs you do, it would be useful. ....
  8. C Programming: Arrays
    A Clear Description of Arrays (4)
    C programming provides a capability that enables a user to design a set of similar data types,
    called Arrays. For understanding the arrays properly, let us consider the following program CODE
    main() { int x; j=5 j=10; printf("\nj= %d",x); } No doubt, this program will print the value
    of j as 10. This is because when a value 10 is assigned to j, the earlier value of j, i.e. 5, is
    lost. Thus, ordinary variables are capable of holding only one value at a time. However, there are
    situations in which we would want to store more than one value at a time in a single ....
  9. Beginners Guide To C/c++ Programming?
    (3)
    ok so I was wondering if anyone knows where I can find a good, c/c++ dummy friendly guide? my main
    reason for want to learn it so that I can make .cab files that do registry edits for ppc. I know
    this should be easy to do, Any help would be greatly appreciated. Thx in advanced, Mike....
  10. C/c++ Programming Experince
    How long does it take before programming useful programs? (3)
    I've been teaching my self C++, slowly but surely. Everything I try to program is just mediocre,
    and much simplier to use something already made. How long does it take before I can start
    programming useful decent programs?....
  11. Detailed C Beginner Tut
    basis for learning any application programming language (2)
    QUOTE The best way to learn programming is to dive right in and start writing real programs.
    This way, concepts which would otherwise seem abstract make sense, and the positive feedback you get
    from getting even a small program to work gives you a great incentive to improve it or write the
    next one. Diving in with ``real'' programs right away has another advantage, if only
    pragmatic: if you're using a conventional compiler, you can't run a fragment of a program
    and see what it does; nothing will run until you have a complete (if tiny or trivial) prog....
  12. Dos Programming, Undocumented Dos, And Dos Secrets
    (3)
    This web site is devoted to DOS programming for those of us who still enjoy programming in DOS some
    of its containt are Disk/Files - Programming the disk and/or file info. DOS - DOS programs, DOS
    prompt, DOS compilers, etc. Encryption/Compression - Encryption and Compression. Games - Programming
    Games. Hardware/System programming - Memory, BIOS, CMOS, and other Hardware/System items.
    Input/Output Devices - Mice, Joystick, Keyboard, Modem, Printer, etc.. Misc - Item that don't
    fit in any/all the other subjects. Sound - Sound programming Video/Graphics - Graphics progr....
  13. Dos Game Programming In C For Beginners
    (1)
    There are a number of tutorials available for the intermediate game programmer, but there are very
    few good tutorials for beginners who have never drawn a pixel on the screen. A quick search on the
    net reveals hundreds of sites devoted to 3D, polygons, texture- mapping and other advance topics,
    but the beginner has no where to get started. This tutorial is for C programmers who want to get an
    introduction to game programming. find this tutorial at Dos Game Programming in C for Beginners
    ....
  14. 256-color Vga Programming In C Site
    (0)
    what some say is the best VGA programming site on the web VGA Basics Setting the video mode,
    plotting a pixel, and mode 0x13 memory. Primitive Shapes & Lines Drawing lines, polygons,
    rectangles, and circles. Also, Bresenham's algorithm, fixed-point math and pre-computing tables.
    Bitmaps & Palette Manipulation The BMP file format, drawing bitmaps, and palette manipulation. Mouse
    Support & Animation Animation, mouse motion, and mouse button detection. Double Buffering, Page
    Flipping, & Unchained Mode Double buffering, page flipping, structure of unchained mode,....
  15. Win32: Dialog Box And Accelerator
    Win32 API programming (3)
    ok my problem is how do i make or assign a keyboard accelerator with modal dialog boxes since the
    message loop is inside the function call of DailogBox() functions, unlike the modeless dialog box in
    which you are the one who will create the message loop for the dialog box... is it even possible?....
  16. Programming A Malloc
    (1)
    A little background about what I am doing is this: I have an array which holds a linked list
    containing the memory that is currently taken from the system. Each index I have like 16 size
    memory or less can be stored only in index 0, index 1 is for memory inbetween 16-32, index 2 is for
    memory inbetween 32-64, etc all the way up to 2048 which is the max allocatable memory. Now the way
    my malloc is to work is that it first will run through my list to see if any memory is available
    that is greater than or equal to the size I need, if there is any at all it will return it....
  17. Where To Start Learning C++ Programming Language
    Resources for C++ (4)
    I'm planning on learning c++ but I'm having some problems. First, I need a compiler.
    I've downloaded Digital Mars (www.digitalmars.com) but how the heck do I compile something????
    There's this other free compiler that loooks great but seems hard to install. Does anyone know a
    good freeware compiler??? Also does anyone know what some good tutorial resources are? I've
    found a few sites, but does anyone know a really good one? Or maybe a good book? But my main
    problem is with the compiler. Can't get anything done without one.......
  18. Never Ending Books For C++ Programming
    C++ Programming Books (3)
    /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Hello Friends As I m
    doing MCA so I have so many ebooks for u. Anybody that wants C++ Programming Knowledge ,can get from
    these books,it includes all basic and expert features programming.So here is the collection Only For
    Trap17 Users.If u like this Post Please reply. Thanx ....................
  19. Vesa Programming Viewer In D O S
    Graphics in C/C++ (3)
    Hello friends, I wanna make an image viewer in DOS...can any one help me how to deal with high
    resolution screens in DOS uning mouse using VESA interrupts. Please help.. thanks acumentech....
  20. Vesa Programming Viewer In C
    Graphics in C (2)
    Hello friends, I wanna make one image viewer program in C please help me how to deal with high
    resolution video using VESA programming. Thanks acumentech....
  21. Life In Programming?
    wheres this headed? (12)
    Hey guys im 16 and really like programming (although im fairly new at it) ive already taken a year
    of basic html and what not. This year im taking a class in c++ and VB next year i hope to take java
    and php. However next year will be my senior year and i will have to start applying for colleges
    and im trying to convince my parents that there ARE jobs in computers its hard for them to do this
    they like to stay locked up in there own little world **cough cough** stone age **cough** so what i
    was wondering is what jobs are actually out there for this kinda stuff what are ....
  22. Programming Help
    (7)
    Hi there, I have C++ programming in my college syllabus this semister.Once this paper+ Oral exams
    over i think i may loose touch with C++. Can you suggest me any good forum where i can keep in touch
    with C++.Any project where i can keep my creative juices flowing? PLs can you help me with this.....
  23. Where Can I Learn Linux Programming?
    any good resources for linux programming (2)
    Where can i learn linux system programming? Topic titles and descriptions are important. Try and
    make them as descriptive as possible. Linux Programming, Linux is not very descriptive. Renamed.
    ....
  24. Good Books On C++ Game Programming
    I need some books! (5)
    I am looking for some good books on game programming in c++ if any body out there has any
    suggestions feel free to post them. Oh by the way should i start out with an easier language like
    BASIC or should I just work on c++. Ineed some help people please reply fast. Tahnx
    David H /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /> ....
  25. Game Programming
    (17)
    I'm looking into going into game programming and I want to know if there is another programming
    language I should learn to go along with C++? Or should I just learn C++(Master Blaster of C++,
    Master Shake of C++, Lord and Master of C++, Jedi Master of C++) and then learn(more)/master it in
    college? Thanks, Kvarner express....
  26. D Programming Language
    (9)
    hi friends, surprised... was that a type???? It is not a type... I know this is a C/C++
    programming language forum.. Just wanted to share something I came across today... A new
    programming language based on C and C++ is being developed.. It would have all the power of C/C++,
    in other words as the spec says "retains the ability to write high performance code and interface
    directly with the operating system API's and with hardware." The specification of the language
    and alpha phase compilers are available at www.digitalmars.com I just browsed throught the spec a....
  27. C Most Popular Programming Language
    Look at title :) (3)
    http://www.tiobe.com/tiobe_index/tekst.htm C is most popular programming language altought market
    share is ~2 %. The most projects is worked in other programming language like .NET and C++. I think
    C is too old. What do you think?....
  28. A Question About C++ Programming Under Linux
    (8)
    Hello guys! i prepare to develop under linux using c++, but i don't know what tools i should
    use...some one tell me to use vim, but i think vim is so hard to use!can u recommend me some ide???
    thank u very much....
  29. Simple C++ Programs
    programming C++ (16)
    what simple programs would a beginner should code in order to get some understanding the c++ along
    with leaning as well....
  30. C Programming Help
    (4)
    Hey, does anyone know of any good direct sites that would help me in some scripting of c programming
    or maybe even a tutrorial that would help with some advanced scripting. Thanks.....

    1. Looking for learn, onject, oriented, programming, understand, benefit, oop

Searching Video's for learn, onject, oriented, programming, understand, benefit, oop
See Also,
advertisement


Why Must We Learn Object Oriented Programming - help me to understand the benefit of OOP

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com