This is a follow-up thread on How to get rid of instanceof in this Builder implementation
There are some more problems with this design. Each time a new parameter is entered, a new ConcereteParameter class must be created.
It's not a problem. But you also need to add a method to CommandBuilder append(ConcreteParameter). And I do not really like this addiction.
append(ConcreteParameter)
To summarize
Commands can be configured with options. Not every team can receive the same parameters. Therefore, some should be ignored. When applied to a team (in this implementation, this is achieved by throwingUnsupportedOperationException
UnsupportedOperationException
Parameters that can be applied to specific classes are used differently in these classes (for example, FTPCommand and HTTPCommand can use IpParameter differently)
In the future, new commands and parameters may be introduced.
Upgrade Implementation, as now works. But isn’t it too difficult if I have about 30 parameters, what for each parameter should I have a separate method?
works
If there is, What is a cleaner and more flexible way / template to achieve this?
? , , , . , , String Integer - , . -, : (, , ), .
String
Integer
, , . @Parameter, . . @Parameter void setIP(String) , String am IP-. , , , , . , , , .
@Parameter
@Parameter void setIP(String)
, , , .
Map execute . Map String.
Map
execute
public interface Command { public void execute(Map<String, Object> context); } class OneCommandImpl extends Command { public void execute(Map<String, Object> context) { context.get('p1'); context.get('p2'); } }
, , . , , . , .