I have recently come across a situation where various non-related class need to share variables and methods. The first thing that came to my mind was to make a static class with static variables and methods which works fine, but I was wondering if there was a more OO way of doing this. Thanks in advance!
Sharing variables and methods between classes
Collapse
X
-
I tend to use static methods for commonly used utility functions.
I'm not sure about static variables though, these are almost global.
A more OOP way I suppose would be an abstract class from which other classes inherit, but as the other classes are unrelated this doesn't seem logical.
I am also intersted in any other solutions provided.
Comment