By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

Model 2 using reflection

P: n/a
Hi. In extension to my former qustion about the command pattern (wich im
still interested in) ive tried to implement the Servlet with reflection. My
idea is, to create a new class wich inherit from a abstract calss Action
with the public method perform, for every new "operaiton" on my website.

I then use reflection to load this class coresponding to a RequestParameter.

I am interested in hearing what you gurus ;) think about this approach? For
me its seems quite elegant from my chair. But i might be missing some
important issues such as extreem performance overhead eg.

This is from my Controller servlet.
---------------------------------------
<SNIP>
String operation = "com.pdastore.servletActions." +
request.getParameter("operation");
String NextPage = null;
Class annoclass = Class.forName(operation);

Class[] types = new Class[] { HttpServletRequest.class,
HttpServletResponse.class };
Method method = annoclass.getMethod("perform", types);
NextPage = (String)method.invoke(annoclass.newInstance(), new Object[] {
request,response });
// Redirect to the new page determined from the perfrom method
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(NextPage);
rd.forward(request, response); }

<SNIP>

-------------------------------------

Anders j, denmark
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.