Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

how to create intelligent invoker :)

Thread view: 
devphylosoff - 05 Nov 2007 18:28 GMT
hey

problem:
how invoke diffrent methods/contructors (depends on arguments number)
in one statement.

description:
I have many classes with constructors NameOfClass(int, int, int, ...,
int);

and I have method which invoke each of above class in switch block:
if (className == sth) {
  NameOfClass1(int a, int b);
} else if (className == sth2) {
  NameOfClass2(int a, int b, int c);
} else if ...

use ArrayList or another like solution is not acceptable.

is reflection will be helpful here ?
Daniel Pitts - 05 Nov 2007 19:47 GMT
> hey
>
[quoted text clipped - 16 lines]
>
> is reflection will be helpful here ?

You might look into the Factory pattern instead.  Why isn't the use of
ArrayList or another like solution not acceptable?  Sounds like a fairly
artificial constraint.  If className is a string, you could use
reflection, but I wouldn't recommend it.
<http://virtualinfinity.net/wordpress/program-design/2007/01/11/the-dangers-of-re
flection-or-put-down-that-mirror/
>

Alternatively, you could use the Factory pattern and have a Map<String,
Factory>, where Factory is your base-class/interface that has a method
which will invoke new SomeClass(whatever,args,you,want);

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Roedy Green - 05 Nov 2007 23:54 GMT
>how invoke diffrent methods/contructors (depends on arguments number)
>in one statement.

If your parms are all ints, you could use int...
which works as if it were int[]

That lets you have a variable number of arguments to your factory.

Otherwise you will need all manner of overloaded factory methods with
the various combinations of parms wrapped around a DEBE factory.

see http://mindprod.com/jgloss/debe.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.