[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
The Nightstar Zoo • View topic - refactor(this);

The Nightstar Zoo

Nightstar IRC Network - irc.nightstar.net
It is currently Sat May 25, 2019 5:56 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: refactor(this);
PostPosted: Sat Apr 29, 2006 5:42 pm 
Offline
Nightstar Graveyard Daemon
User avatar

Joined: Mon Jun 03, 2002 8:30 pm
Posts: 1071
Location: Wouldn't you rather observe my Velocity?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 8:39 pm 


Top
  
 
 Post subject:
PostPosted: Mon May 08, 2006 10:16 am 
Sorry for the delay on this, but I don't think I've checked this forum in a while. Anyway, assuming I'm not still asleep this morning, I can see three really simple solutions.

First off, you can simply use Object as the return type. Since Java uses a singly-rooted object hierarchy, this would cover all non-primitive cases (unlike in C++, where you often have objects with no common superclasses). However, this won't work with primitive types (though you can of course use the equivalent wrapper classes), you'll need to downcast the objects, and you may need to use instanceof() to check the correct type first. In the function itself, you can use a HashMap or some other form of lookup collection to select the correct table name.

Second, you can make this method and the class it is in abstract, and create a subclass for each of the cases which handles the specific instances, calling the parent's method to handle the actual performance. I doubt that this would be much more acceptable than the current situation, however, as there would still be a lot of redundancy, but it would at least reduce the amount of duplication.

Finally, if you are using the newest version of Java (1.5), you can use generics, which work very similarly to C++ templates. There are some differences, however, and you'll want to check to make sure that what you have in mind would work.


Top
  
 
 Post subject:
PostPosted: Sat May 27, 2006 3:09 am 
Offline
Knight of Daisies, Tulip Slayer
User avatar

Joined: Sat May 11, 2002 3:03 am
Posts: 1621
Location: Sector ZZ9 Plural Z Alpha
Not sure if I entirely grok what's going on here... It seems to me that your factory is there to instantiate objects in various families...

In which case, the Abstract Factory pattern might be useful. http://en.wikipedia.org/wiki/Abstract_factory_pattern

If this is not what you're doing, then feel free to ignore me.

If this is what you're doing, and Abstract Factory does indeed prove useful, then I have only one thing to say: IN YOUR FACE, VORN!

_________________
Fandemonium 2010 -- No Boundaries.
http://www.fandemonium.org
Friday - Sunday, August 6th - 8th, 2010
Nampa Civic Center - Nampa, Idaho (Only 20 minutes from the airport!)
(Idaho: It ain't just potatoes anymore.)


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 27, 2006 4:09 am 
Offline
Energizer Bunny
User avatar

Joined: Wed May 22, 2002 12:24 am
Posts: 1634
Nope.

The abstract factory method does not reduce duplication within a single class, which is the problem.

If you want to reduce this kind of duplication, you make a table, keyed on an enum, stuffed with the class to create, the query string, etc. Then you have to write an interface overlaying the creatable classes, and call a method with the enum as an argument.

Vorn


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group