public class FooClient {
private Foo foo;
private final static String key = "<api-key>";
private static FooClient client = new FooClient();
private FooClient() {
foo = new Foo(key);
}
public static FooClient getFooClient() {
return client;
}
}
- Is it ok to initialize
client
in the above fashion. - Should I declare private Foo foo; as static, I am guessing its not the case.
- If I have to support different singletons for different keys, should I modify
getFooClient(String key)
to take in a key and cache it, so that I can return singleton FooClients which are key specific.