The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Interfaces

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

static abstract kludge example

Posted by Paul Heimiller on December 19, 2001 at 10:14 AM

I've gotten some questions on this, so here is some code that will hopefully make this clearer.

MainController method:
public static String getPrimaryTable()
{
throw new IllegalStateException(" MainCtrll.getPrimaryTable method should be overidden by subclass");
}

SubClassedController:
public static String getPrimaryTable()
{
return( "VEHICLE_LINE" );
}

Another class, has name of controller:
String strMainCtrllr = "SubClassedController";
try {
Class mccClass = Class.forName(strMainCtrllr);
Method methodMy = mccClass.getMethod("getPrimaryTable", new Class[0]);
strPrimaryTable = (String) methodMy.invoke(null, new Object[0]);
}
} catch (Exception e) {
System.out.println(" couldn't get strPrimaryTable for controller " + strMainCtrllr);
// e.printStackTrace(System.out);
// System.exit(1);
}






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us