LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-20-2003, 11:01 AM   #1
KptnKrill
Member
 
Registered: Apr 2003
Location: US, MA
Distribution: Nandu-0.ab, Arch 0.7.2
Posts: 229

Rep: Reputation: 30
Smile 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!
 
Old 08-20-2003, 11:06 AM   #2
acjt
Member
 
Registered: Dec 2002
Location: Australia
Distribution: Gentoo
Posts: 161

Rep: Reputation: 30
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

Last edited by acjt; 08-20-2003 at 11:10 AM.
 
Old 08-20-2003, 12:05 PM   #3
KptnKrill
Member
 
Registered: Apr 2003
Location: US, MA
Distribution: Nandu-0.ab, Arch 0.7.2
Posts: 229

Original Poster
Rep: Reputation: 30
Great, thanks for that link, and I'll investigate javax.swing.
 
Old 08-21-2003, 05:15 AM   #4
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
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.
 
Old 08-21-2003, 09:58 AM   #5
DIYLinux
Member
 
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 18
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.
 
Old 08-21-2003, 11:19 AM   #6
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
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
 
Old 08-21-2003, 07:09 PM   #7
KptnKrill
Member
 
Registered: Apr 2003
Location: US, MA
Distribution: Nandu-0.ab, Arch 0.7.2
Posts: 229

Original Poster
Rep: Reputation: 30
thanks all for your feedback, and one day I will understand this
 
Old 08-22-2003, 02:39 AM   #8
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
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.
 
Old 08-22-2003, 04:04 PM   #9
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
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.
 
Old 08-23-2003, 02:23 AM   #10
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
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.
 
Old 08-24-2003, 01:15 PM   #11
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
OOP in PHP patpawlowski Programming 5 11-20-2005 04:37 PM
OOP Help Please InvisibleSniper Programming 41 09-18-2005 03:19 AM
What is true OOP? tumana Programming 4 09-13-2004 06:51 AM
Why use OOP when OBP will do? unholy Programming 2 08-27-2004 04:56 PM
newbie oop Isitme Programming 3 10-10-2001 12:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration