Hi
I don't know if this the proper place for this post, since its a design issue at the first place, but it is JSP/Servelt specific. So please pardon me.
In web applications we mostly need to get some data from a storage source, typically a database and the init a bean to manuplate or dispaly these data, and then may save them back to the DB. For example, in most occassions we have site members, so we need to define a member class to reprsent a site registerd member.
I would create a MemberBean with set/get functions for use in my JSP pages. But as you know we need to access the database in order to fetch the member data from the db or to save them back. Puting the database realted code into the bean is out of question IMHO since I think we should keep the bean as small and simple as possible.
My question is what approche do you suggest, and why?
1- To separate all the member behaviors into a class (i.e Memeber.class) both db-related behaviors like updateEmail() or other member behaviors like login(). And then call these methods inside servlets.
2- Same as 1 but separate the db releated methods in a class like MemberDBAccess.class and all member specific behaviors in a Member.class
3- The same as 2) but insted of making a class for data access to do all the database related actions. We do them in a servelt. For example UpdateMemberServlet and inside this servlet we'll write all the code needed to update the member record in the database after we pass the new values form a JSP page.
I hope that I made this clear.
Your input is much appreciated.
I don't know if this the proper place for this post, since its a design issue at the first place, but it is JSP/Servelt specific. So please pardon me.
In web applications we mostly need to get some data from a storage source, typically a database and the init a bean to manuplate or dispaly these data, and then may save them back to the DB. For example, in most occassions we have site members, so we need to define a member class to reprsent a site registerd member.
I would create a MemberBean with set/get functions for use in my JSP pages. But as you know we need to access the database in order to fetch the member data from the db or to save them back. Puting the database realted code into the bean is out of question IMHO since I think we should keep the bean as small and simple as possible.
My question is what approche do you suggest, and why?
1- To separate all the member behaviors into a class (i.e Memeber.class) both db-related behaviors like updateEmail() or other member behaviors like login(). And then call these methods inside servlets.
2- Same as 1 but separate the db releated methods in a class like MemberDBAccess.class and all member specific behaviors in a Member.class
3- The same as 2) but insted of making a class for data access to do all the database related actions. We do them in a servelt. For example UpdateMemberServlet and inside this servlet we'll write all the code needed to update the member record in the database after we pass the new values form a JSP page.
I hope that I made this clear.
Your input is much appreciated.