Closed typischmann closed 9 years ago
Pro & Cons of static method
Advantages
Can do meta object operations ( like validating something before creating objects , keep count of number of objects )
Can do operations which have nothing to do with objects but still you want them to be tied to Class.
Disadvantages
Commonly used to static variables sometime leads to problems due to access by different objects.
Are not tied to objects so doesn't reflect pure Object Oriented approach.
Needs to be synchronized so as to avoid update conflicts by mutiple objects and threads.
It would be hard in Mock Test
Mock test shouldn't test static method. But for synchronize issue, why toJson method needs it, it doesn't need to change shared objects.
Okay!
Pro & Cons of static method
Advantages
Can do meta object operations ( like validating something before creating objects , keep count of number of objects )
Can do operations which have nothing to do with objects but still you want them to be tied to Class.
Disadvantages
Commonly used to static variables sometime leads to problems due to access by different objects.
Are not tied to objects so doesn't reflect pure Object Oriented approach.
Needs to be synchronized so as to avoid update conflicts by mutiple objects and threads.
It would be hard in Mock Test