design - How to use open closed principle for web page operations invocation in java? -
design - How to use open closed principle for web page operations invocation in java? -
i have web page users can fill in , submit forms:
<form id=email... send email .... <input type="hidden"id="method" value="sendemail"... /> ............. <form id=writeindatabase info ............ <input type="hidden"id="method" value="writeindatabase"...
on server side:
if (method.compareto("sendemail")==0) { dosendemail(.... } else if (method.compareto("writeindatabase")==0) { dowriteindatabase(.... ..............................
i don't architecture because violates open close principle. possible refactor prepare that? thanks.
you can utilize reflection in structured, secure manner, or, command pattern.
reflection: create map<string, method>
maps each acceptable method name reflection method
object can invoke
after looking up.
command pattern: utilize map<string, callable<?>>
in manner similar above. instantiate callable
s anonymous inner classes implement call
invoking appropriate service method.
java design design-principles
Comments
Post a Comment