Why use static methods?
1. Allow users to use those methods without having to create an instance of that class
2. The static class method apply to the class rather than instances
3. Instance methods are instance methods because they rely on the state of the specific object instance.
4. Static methods, e.g. instances() is used to track the number of instantiations at the class level. They are independant of instance states.
5. Useful for utility class (private constructor - no instantiation, but it's easily abused and lead to procedural programming) or factory class.
refer to Static Methods
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment