Best OO approach?

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Thread Solved

Join Date: Apr 2008
Posts: 69
Reputation: K?! is an unknown quantity at this point 
Solved Threads: 0
K?! K?! is offline Offline
Junior Poster in Training

Best OO approach?

 
0
  #1
Jul 2nd, 2009
Hi all

I have found 2 approaches in Object Oriented programming:
  1. Creating a "master" class that contains all classes, and creating a method for each operation. (With this approach you only have to pass the "master" class throughout different GUI screens)
  2. Using only the classes you need in the GUI (Then you have to see you pass through the appropriate classes)

I find that both approaches have their pro's and con's.
Using only the necessery classes fits my idea of OO better, but I'm not sure cause, well, as said, using a master class has it's advantages too.

If necessary I'll try to give some more specific pro's and con's, but I'll leave it to this for now.

What do you all think about this?

Thx in advance
Greets
K?!
Heaven ain't got no ghetto. It's got pearly gates and streets of gold.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 5
Reputation: davidrafter is an unknown quantity at this point 
Solved Threads: 1
davidrafter davidrafter is offline Offline
Newbie Poster

Re: Best OO approach?

 
0
  #2
Jul 2nd, 2009
Originally Posted by K?! View Post
Hi all

I have found 2 approaches in Object Oriented programming:
Are you talking about an approach for a specific problem like GUI programming? Because you mention that problem but I'm not sure whether that's the context or just an example.

It is hard to understand from your post what you're describing, and a more concrete pair of examples with code, or just interfaces, would make your question clearer.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 69
Reputation: K?! is an unknown quantity at this point 
Solved Threads: 0
K?! K?! is offline Offline
Junior Poster in Training

Re: Best OO approach?

 
0
  #3
Jul 3rd, 2009
Well, now it is indeed for use with a GUI (well, web pages...). But I think it can be used as a general approach too (with or without GUI), just
"using one class containing all other classes and making a method(using the appropriate classes and their methods) for each action"
or
"using only the needed classes and building up the actions by using their methods"

It's kinda hard to give you a code example.
I don't have too much time right now, I'll try to post a more accurate example later on.

Grtz, K?!
Heaven ain't got no ghetto. It's got pearly gates and streets of gold.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 109
Reputation: Stinomus is on a distinguished road 
Solved Threads: 16
Stinomus Stinomus is offline Offline
Junior Poster

Re: Best OO approach?

 
0
  #4
Jul 10th, 2009
So you want one class that has a whole heap of inner classes? What benefit does that give you?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 69
Reputation: K?! is an unknown quantity at this point 
Solved Threads: 0
K?! K?! is offline Offline
Junior Poster in Training

Re: Best OO approach?

 
0
  #5
Jul 10th, 2009
For GUI: you only have to pass through that one class.

Other example: (I'm programming in php)
If a page has a list on it where the items represent objects (classes), I can not acces these objects themselves from the list, but only, for example, their ID's. If I pass a method to this superclass(here: "program"), like: "program.changePersonName(personId, name)", I can make this superclass search for the appropriate person to update.
When not using a super class, I have to let the GUI access the database, search for the person with that ID, and then let it create a new Person with it's data. After that I'm able to do something like "person.changeName(name)", after which the Person class will access the database (to update the data).
This also means that database connection is made in the GUI and in the actual program, while using a super class, this can be kept in the actual program.
Last edited by K?!; Jul 10th, 2009 at 5:47 am.
Heaven ain't got no ghetto. It's got pearly gates and streets of gold.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Best OO approach?

 
2
  #6
Jul 10th, 2009
Or you could just write the method for (in your example) Person to change the name themselves. ie., person->setName()
There is absolutely no need for a "superclass". Their true name is "god class" and it's referred to as an anti-pattern. They are the bane of good OOP principles. Don't make them. Just don't.

There is absolutely no reason you can't do
  1. $person = new Person($somepersonid);
  2. $person->setName('Tester');

You could make the database access inside the Person constructor, it doesn't have to be in the GUI. I'm not entirely sure where you're getting this mindset.
Last edited by ShawnCplus; Jul 10th, 2009 at 1:58 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 69
Reputation: K?! is an unknown quantity at this point 
Solved Threads: 0
K?! K?! is offline Offline
Junior Poster in Training

Re: Best OO approach?

 
0
  #7
Jul 10th, 2009
Ok, thx.
Well, I heard it from a classmate. It felt kind of awkward indeed, but if it solved a problem, why not...
But I'll try solving the problems without using it.

Thx for the clear answer.

Grtz, K?!
Heaven ain't got no ghetto. It's got pearly gates and streets of gold.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,566
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 196
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: Best OO approach?

 
0
  #8
Jul 12th, 2009
To confirm his opinion: ShawnCPlus is absolutely correct. You'd be wise to follow his advice.
Out.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Computer Science Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC