由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 求教:Facade Pattern vs Static Variable
相关主题
纯ajax的app是不是比mvc的要难很多求指教: CXF Cleint API for Axis2 SOAP web service问题
design pattern in Java那本书比较好?JAVA 求解
[合集] java 得 inner class 有没有 static 有什么区别啊?Singleton vs. static class?
java EL 问题请教Help: how to use Eclipse as C++ IDE in XP? (转载)
Suggestion Re: 发现 synchronized 的一个问题about builder pattern
anyone saw this on code?A question about inheritance
自己管理session要每次手动释放么这个怎么不对?
Where does Java Store Static Variable?Core J2EE Design Pattern
相关话题的讨论汇总
话题: facade话题: static话题: variable话题: pattern
进入Java版参与讨论
1 (共1页)
l*****o
发帖数: 214
1
I am maintaining a legacy SDK. The SDK will behave differently for different
platform. It's using a static variable and requires the static variable to
be created before any API call like the following:
Example for static variable (OLD CODE):
SDKContext.init();
VideoManager manager = new VideoManager();
public void VideoManager#search() {
SDKContext.search();
}
Components like VideoManager are all over the place. My gut feeling tells me
I should use Facade pattern instead, but can't be sure.
Example for Facade (MY PREFERRED WAY):
SDKContext context = new SDKContext();
VideoManager manager = new VideoManager(context);
public void VideoManager#search() {
context.search();
}
What's the pros and cons of facade pattern vs creating all API using a
static variable and invoke it implicitly? Any recommendation/suggestion is
welcomed.
g*****g
发帖数: 34805
2
Depends on how heavy is SDKContext creation and whether it's thread safe to
share it. You may have different approach.
s******e
发帖数: 493
3
Maybe I misunderstood you. But I do not think this is the case for the
facade. I do not think you are coding a facade even you call it so.
Maybe what you really need is the factory method or abstract factory.
Usually a static variable can be coupled with the abstract factory.
1 (共1页)
进入Java版参与讨论
相关主题
Core J2EE Design PatternSuggestion Re: 发现 synchronized 的一个问题
求一本关于Design Pattern,UML和JAVA的经典书籍anyone saw this on code?
Java/J2EE的书自己管理session要每次手动释放么
JavaBean variable name standardWhere does Java Store Static Variable?
纯ajax的app是不是比mvc的要难很多求指教: CXF Cleint API for Axis2 SOAP web service问题
design pattern in Java那本书比较好?JAVA 求解
[合集] java 得 inner class 有没有 static 有什么区别啊?Singleton vs. static class?
java EL 问题请教Help: how to use Eclipse as C++ IDE in XP? (转载)
相关话题的讨论汇总
话题: facade话题: static话题: variable话题: pattern