Power JavaDynamic Binder

Power Java
Dynamic Binder

Mike Mannion

Listing 1.
Example implementation of the getCommand method.


    protected Command getCommand(Target t)
    {
        return getCommandForClass(t.getClass());
    }
    protected Command getCommandForClass(Class targetClass)
    {
        if (commandTable.containsKey(targetClass))
        {
            // Return Command most suitable for this class
            return (Command)commandTable.get(targetClass);
        }
        else
        if (targetClass.equals(java.lang.Object.class))
        {
            // This should never happen
            throw new RuntimeException(
                "No command found for class "+targetClass.getName());
        }
        // Return updater corresponding to superclass of this class
        return getCommandForClass( targetClass.getSuperclass() );
    }

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.