I want to create a factory for creation of objects implementing an abstract interface, which would return a reference to the object that is kept internally, and objects are not replicated. The idea is pretty much the same as in the log4cxx/log4j Logger class design. I would also like to hide as much details from the client as possible, i.e. that viewing the exposed .h file would not reveal implementation details like private members etc. Example:
EncryptorRef = Encryptor::getEncryptor("AES");
I wonder whether there accepted published guidelines/sample code for such design, as I wouldn't like to reinvent the wheel, and the task is pretty common. I thought of using static Factory Method, Singleton repository inside, and smart pointer/reference to the concrete object as returned type. questions:
- is there a sample simple code for such design? (the code of log4cxx is too complex to be used as a skeleton)
- how do I hide the repository from the client completely, assuming he only sees the pure abstract
Encryptor
class defined encryptor.h? - would you suggest using smart reference or pointer as a return type? is there a standard implementation for smart reference?
- any other suggestions will be appreciated
thanks a lot!