Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Store managedStore = Store::getInstance();
- managedStore.doSomething();
- managedStore.doSomethingElse();
- //etc.
- someVar = SomeControllerClass(managedStore, menuBar, editor, sasquatch, ...)
- var parameterClass1 = new MenuParameter(menuBar, editor);
- var parameterClass2 = new StuffParameters(sasquatch, ...);
- var ctrl = new MyControllerClass(managedStore, parameterClass1, parameterClass2);
- // The Rather Unfortunate Singleton Class
- public class SingletonStore {
- private static SingletonStore _singleton
- = new MyUnfortunateSingleton();
- private SingletonStore() {
- // Do some privatised constructing in here...
- }
- public static SingletonStore getInstance() {
- return _singleton;
- }
- // Some methods and stuff to be down here
- }
- // Usage:
- // var singleInstanceOfStore = SingletonStore.getInstance();
- public class StoreWithFactory {
- public StoreWithFactory() {
- // If the constructor is private or public doesn't matter
- // unless you do TDD, in which you need to have a public
- // constructor to create the object so you can test it.
- }
- // The method returning an instance of Singleton is now a
- // factory method.
- public static StoreWithFactory getInstance() {
- return new StoreWithFactory();
- }
- }
- // Usage:
- // var myStore = StoreWithFactory.getInstance();
- class Log
- {
- void logmessage(...)
- { // do some stuff
- }
- };
- int main()
- {
- Log log;
- // do some more stuff
- }
- class Database
- {
- Log &_log;
- Database(Log &log) : _log(log) {}
- void Open(...)
- {
- _log.logmessage(whatever);
- }
- };
Add Comment
Please, Sign In to add comment