Discussions

EJB design: Command pattern in Actions

  1. Command pattern in Actions (3 messages)

    Hi there! The project I'm working in now, has so many chainned actions, that the entire project is almost a single block. You almost can not change a line in one action, and not affecting behaviour of other actions.
    I need to fix this. First I think in use the Command pattern, using a command manager to manage the commands, and all commands registred for a given action, would be done on the by an action superclass according a xml file. I'm in the desing phase yet, no code implemented so far. But one issue that came, is that the execute method of the Command interface is a void type, sometime I might need to have something in return, a data struct, a given ADT, or other things. So what's the best approach? return a Object, and do the proper casting on the invoker?

    Thanks all

    Vinicius Carvalho

    Threaded Messages (3)

  2. Command pattern in Actions[ Go to top ]

    Hi

    Let the execute method return a "CommandResult" object
    you can have different getter methods to get Errors, data struct etc

    Regards
    Shoj
  3. Command pattern in Actions[ Go to top ]

    As the parent poster suggested, define a CommandResult object, which should have the following methods:

    1. public int getOutcome(): returns from a list of predefined outcomes (you can have named constants for ERROR, WARNING, SUCCESS, etc)
    2. public Object getValue() : returns the default return value.
    3. public Object getProperty(String name): returns a named value from the list of returned properties
    4. public Iterator getProperties() - self explanatory
    5. public Iterator getPropertyNames() - self explanatory
    6. public Iterator getPropertyMedataData() - Returns type information about the return values (if you have several).
  4. Command pattern in Actions[ Go to top ]

    As the parent poster suggested, define a CommandResult object, which should have the following methods:1. public int getOutcome(): returns from a list of predefined outcomes (you can have named constants for ERROR, WARNING, SUCCESS, etc)2. public Object getValue() : returns the default return value.3. public Object getProperty(String name): returns a named value from the list of returned properties4. public Iterator getProperties() - self explanatory5. public Iterator getPropertyNames() - self explanatory6. public Iterator getPropertyMedataData() - Returns type information about the return values (if you have several).


    I am new to java. Can you elaborate alittle bit more on the specifics of CommandResult's methods above? I like the idea, I think, I am working with command pattern right now and came across this post. Would appreciate any help you can afford.

    Thanks