| | |
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:
Solved Threads: 0
Hi all
I have found 2 approaches in Object Oriented programming:
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?!
I have found 2 approaches in Object Oriented programming:
- 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)
- 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.
•
•
Join Date: Mar 2009
Posts: 5
Reputation:
Solved Threads: 1
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.
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.
•
•
Join Date: Apr 2008
Posts: 69
Reputation:
Solved Threads: 0
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?!
"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.
•
•
Join Date: Apr 2008
Posts: 69
Reputation:
Solved Threads: 0
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.
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.
Or you could just write the method for (in your example) Person to change the name themselves. ie.,
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
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.
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)
$person = new Person($somepersonid); $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.
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.
![]() |
Similar Threads
- An alternative approach? (C++)
- Has any one used extremetable? (JavaScript / DHTML / AJAX)
- Alternative approach to frames....? (Site Layout and Usability)
- Unusual SW Development Approach (IT Professionals' Lounge)
- how to approach a good quality complaint form (HTML and CSS)
- learning php (PHP)
- ITZoom: Changed design and a new approach... (Website Reviews)
- The best approach to advertising for my site? (Advertising Sales Strategies)
- Is this possible? Is there a better approach? (C++)
Other Threads in the Computer Science Forum
- Previous Thread: Computer graphics
- Next Thread: Buffer memory and RAM?
| Thread Tools | Search this Thread |
ai algorithm algorithms amazon assignment assignments automata battery bigbrother binary bittorrent bizarre bletchleypark blogging bomb business cern codebreaker compiler computer computers computerscience computertrackingsoftware connect conversion csc dataanalysis dataintepretation development dfa dissertation dissertationthesis dissertationtopic ebook employment energy floatingpoint foreclosure foreclosuresoftware fuel gadgets geeks givemetehcodez government graphics hardware history homeowners homeworkassignment homeworkhelp humor ibm idea ideas internet iphone ipod itcontracts jobs kindle laser laws linkbait lsmeans mainframes marketing mobileapplication msaccess nano netbeans networking news os p2p piracy piratebay principles programming rasterizer research sam-being-cute sas science security sex simulation software spying stephenfry study supercomputer supercomputing sweden technology textfield turing turingtest two'scompliment virus ww2






