0

I think it is not necessary for me to explain what is the good thing about OOP. But I would like to know discuss is the static method violate the OOP design? or a more OOP way to do is making a singleton to do such static method?

Tattat
  • 15,548
  • 33
  • 87
  • 138
  • relevant: http://stackoverflow.com/questions/752758/is-using-a-lot-of-static-methods-a-bad-thing Additionally, static methods often cause unit testing to be more difficult. Finally -- singletons just global variables by another name. – Erik Jul 24 '11 at 17:02
  • Remember that Stack Overflow is pretty much like Jeopardy. You have to phrase your problem like a question, one that can be answered. Stack Overflow is not a discussion forum so asking for a discussion is not going to work. – Lasse V. Karlsen Jul 24 '11 at 19:13

2 Answers2

2

I would like to know what harm is done by static methods and what purpose is served by adhering to object oriented purity.

This question and its answer makes as much sense as any other argument about object-oriented purity and where a particular language falls on the continuum.

C# and Java both support the notion of methods and attributes associated with classes rather than a specific instance.

The benefit or harm of singletons in design have been explored in detail elsewhere.

duffymo
  • 305,152
  • 44
  • 369
  • 561
0

Static methods wouldn't exist if they were considered to be bad practice in the OOP paradigm. Static methods are absolutely necessary at times, if you know how to use them. If you have a method that does not make use of, or change, any member of a class object, then it is static by nature.

Jon Martin
  • 3,252
  • 5
  • 29
  • 45
  • 1
    "Static methods wouldn't exist if they were considered to be bad practice in the OOP paradigm"... you have more faith in language design that the evidence would seem to warrant. – skaffman Jul 24 '11 at 17:00
  • 3
    ^ I'm guessing you were taught Java in school. – Jon Martin Jul 24 '11 at 17:03