'Restricting objection creation to specific class
I am trying to create a custom sdk which would wrap multiple cloud providers into one. The idea is that the client (developer) will use this generic api to do generalized operations without worrying about what platform they are connected to.
For sake of this example, lets say i am exposing methods to work with cloud storage (dropbox, azure, aws, box etc). A client would create an object like this
CloudStorage storage = CloudStorage.mount(StorageType.DROPBOX, ...);
Now the storage object will have generalized file operations i.e., storage.listDirectories(), list.createFile(...) etc.
Now my question is. I need to limit the specific implementations from client i.e., developer shouldn't be able to initiate new DropBoxClient(...).
As of now, I am doing so by restricting the class visibility i.e., by using package specific access modifier
class DropBoxClient implements CloudStorage { ... }
this means that my DropBoxClient implementation and my CloudStorage implementation has to reside in same package. Which is fine for 1-2 implementations but as i see this would increase, I would like to organize them better i.e., DropBoxClient should exist in its own package and AzureStorageClient should exist in its own.
With this in mind, what is better way to restrict these implementations?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
