943,793 Members | Top Members by Rank

Ad:
Jul 2nd, 2009
0

Best OO approach?

Expand Post »
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?!
Similar Threads
K?!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
K?! is offline Offline
95 posts
since Apr 2008
Jul 2nd, 2009
0

Re: Best OO approach?

Click to Expand / Collapse  Quote originally posted by K?! ...
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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
davidrafter is offline Offline
5 posts
since Mar 2009
Jul 3rd, 2009
0

Re: Best OO approach?

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?!
K?!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
K?! is offline Offline
95 posts
since Apr 2008
Jul 10th, 2009
0

Re: Best OO approach?

So you want one class that has a whole heap of inner classes? What benefit does that give you?
Reputation Points: 58
Solved Threads: 17
Junior Poster
Stinomus is offline Offline
109 posts
since May 2009
Jul 10th, 2009
0

Re: Best OO approach?

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.
K?!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
K?! is offline Offline
95 posts
since Apr 2008
Jul 10th, 2009
2

Re: Best OO approach?

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
php Syntax (Toggle Plain Text)
  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.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Jul 10th, 2009
0

Re: Best OO approach?

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?!
K?!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
K?! is offline Offline
95 posts
since Apr 2008
Jul 12th, 2009
0

Re: Best OO approach?

To confirm his opinion: ShawnCPlus is absolutely correct. You'd be wise to follow his advice.
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: Computer graphics
Next Thread in Computer Science Forum Timeline: Buffer memory and RAM?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC