You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
- @assylias: "the class will be final because it can't be subclassed". It depends on your definition of "final". It's not as if the class was implicitly made final because of the private constructor (in the way, say, interface methods that aren't declared as public are implicitly public). Putting for example public final or simply public shall lead to two different .class files being generated: with final the .class has its access flags set to 0x31 (public final) while with only public its access flags are 0x21. You cannot extend it but it's still not final...TacticalCoder– TacticalCoder2012-03-08 14:14:55 +00:00Commented Mar 8, 2012 at 14:14
- @ArtB But you would agree, that the following is also nonsens?: The alternative would be, to write an "object-class" and call the constructor once, which does all the work... There is no point in using this object any further. It has no destructor, no getter, no setter... The object is pointless in this case, because all objects will be exactly the same. This is exactly, what static methods are for. And it is good practice, to encapsulate stuff into separat classes (i.e. "files"). Of course I can stuff everything in my calling class. But that would be too much...Sauer– Sauer2012-03-08 14:30:59 +00:00Commented Mar 8, 2012 at 14:30
- @Sauer It's hard to offer an alternative without knowing specifics, but after working on becoming better with object-oriented design principles I find that very rarely are static methods needed. The only cases I can really justify are those where you are adding methods that ought to have existed in the class or are for dealing with null issues.Sled– Sled2012-03-08 15:13:09 +00:00Commented Mar 8, 2012 at 15:13
- 1@ArtB Of course it is up to you, how you design your structure. But to me, static methods are a very valid part of each object oriented programm. I also write APIs at my company and I often use static methods to ENFORCE object oriented coding. Static methods are used to handle "static" and complex algorithms which are working WITH objects. That keeps the real object classes less complex and easier to understand (pojos). Sometimes there is no point in stuffing complex algorithms into object classes...Sauer– Sauer2012-03-13 14:37:12 +00:00Commented Mar 13, 2012 at 14:37
- 1@Sauer I would recommend you at least try stuffing those algorithims into objects as an excercise. I've found that over time I've found neat ways to include those algorithims in to objects, or that some design pattern solves this. I suggest that it maybe be correct more often than you suspect to push things into objects from static methods. YMMVSled– Sled2012-03-13 21:16:02 +00:00Commented Mar 13, 2012 at 21:16
Add a comment |
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-java