The question is pretty simple .Currently i am working on a project which have a class lets call it ResoureceHandler.cpp . This class has some properties , method which is needed by the remaining classes . some properties like username, userid which i can get , set simply by calling resourceHandler->getUserName() or vice versa . I can think of two ways
Method 1: Make the class singleton and access the method to get , set.
Method 2 make the class and properties static and access them without any instance .
But i am not sure either of them fall into proper design . What should be the ideal way to solve this kind problem ?
Rather suggesting a 3rd method. Avoid using global variables or singletons. A clean code should be the key. Use helper functions when necessary and namespaces like so. If your class is complex, use a proxy design pattern to reduce complexity of class objects and for a cleaner code.
//foo.h ( Avoid instantiating the foo class yourself)
// foo.cpp
//poo.h
main.cpp