开发者

JSF Web application -DAO layer with static methods

开发者 https://www.devze.com 2023-02-17 23:22 出处:网络
Hi I have a question about best practices vs safe programming in building a JSF Web Applicaiton. I have employee.xhtml page having backing Bean - EmployeeBean. All the variables that I declare in the

Hi I have a question about best practices vs safe programming in building a JSF Web Applicaiton.

I have employee.xhtml page having backing Bean - EmployeeBean. All the variables that I declare in the backing bean are non static and have getter and setter methods. For example:

ArrayList <Employee> alEmployees = new ArrayList<Employee>();
int userId;

The constructor of the BackingBean loads the employees. I acheive this by calling a static method in delegate.

userId = //some value.
alEmployees = EmployeeDelegate.loadEmployees(userId);

The Delegate method calls a static method in DAO Class.

Will the static methods cause any data concurrency issues when n users are using the application at same time? I mean userId 56 seeing userId 75 list when both are using the appl开发者_开发知识库ication same time? Is it really advisable to have static methods in Delegate and DAO layer?

Please let me know if I was not clear.

Thanks


If the EmployeeDelegate does not hold any class variables which is sensitive to changes caused by method calls and/or has influence on how methods behave, then it's safe to do so.

You however have another major problem with this approach. The delegate should be an interface so that you can easily substitute it with a different implementation. This approach suggests that the delegate is not an interface at all (since it can impossibly have static methods).

0

精彩评论

暂无评论...
验证码 换一张
取 消