LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   When to use OOP (https://www.linuxquestions.org/questions/programming-9/when-to-use-oop-83852/)

KptnKrill 08-20-2003 11:01 AM

When to use OOP
 
Hi,
I'm learning Java, and I understand the concepts of OOP. I don't understand when/why you would use it. Could someone give me a link to a website or a book on this subject. Appreciate it! :)

acjt 08-20-2003 11:06 AM

You use it all the time :)
There are so many sites out there, what about checking out the javax.swing package. You can see the uses of OOP in there.
Component - > Button (as an example) a button is a component.
From a business perspective. You may have a class such as Person, then you could have buyers, sellers, managers, workers. You really would want to use it then.
As for links, gee, just search on www.alltheweb.com and take your pick.

edit: Here's a good one http://sepwww.stanford.edu/sep/josman/oop/oop1.htm

KptnKrill 08-20-2003 12:05 PM

Great, thanks for that link, and I'll investigate javax.swing. :)

UltimaGuy 08-21-2003 05:15 AM

The need for OOP is when you are developing some components and you have the need to reuse them. Take for example C. There, you have to hardcode all the data structures if you have to develop an application. Now in C++, we have OOP and we can use templates and STL.

The best advantages of OOP are inheritance, data hiding and Polymorphism. If you need a good book on the subject , try Bruce Eckel book. It is ThThinking in Java

Try it and then you will understand OOP.

DIYLinux 08-21-2003 09:58 AM

1. OO is possible in C. It is not a language feature, but a mindset. See the GTK+ source.

2. Parametric polymorphism (templates in C++) does not make OO. It facilitates generic programming, like used in the stl.

3. There are times that OO like structuring are not beneficial, and even harmful. OO programs tend to be larger and often slower. Use OO (and design patterns !!) if you need reusability. Use straightforward imperative/functional style in leave functions/methods.

llama_meme 08-21-2003 11:19 AM

Generally OO is a good thing, but IMHO programming in an OO style won't automatically give you lots of reusable code. Code reuse comes more from careful design than from using a particular paradigm.

Alex

KptnKrill 08-21-2003 07:09 PM

thanks all for your feedback, and one day I will understand this :)

UltimaGuy 08-22-2003 02:39 AM

I agree with DIYLinux in that OO is a mindset, but I don't think that any one learning to program can immediately develop that mindset in c and start understanding the GTK+.

IMO you have to first learn through some language that supports it, like C++, or java or python, and then branch on about developing that mindset in other languages like c.

And most importantly, reusing classes and templates, and STL is a lot more easy than just reusing c functions.

coolman0stress 08-22-2003 04:04 PM

You know, i've been studying C++ and such for over half a year now and i've noticed that even to this day myself and my peers STILL aren't exactly OOP primed. Sure we know how to do it, but we don't always see the benifits. Just hard to get your mind over the normal structured alternatives.

UltimaGuy 08-23-2003 02:23 AM

Well, for this problem, you have to force yourself to use OO for even small problems. And one of the advantages of C++ is the structural alternative for small problems. And I would suggest learning java, as it is similar and your OO capacity will improve by the exposure.

Robert0380 08-24-2003 01:15 PM

me and coolman0stress are very different. because i learned Java and OO pogramming 1st. i have a hard time not coding that way. When I write C programs, i tend to make many files to serperate stuff out and make it as OO as possible because that is what im used to.


All times are GMT -5. The time now is 08:16 AM.