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. |