5

From time to time, there are questions which I can be answered per se with one short sentence. A detailed answer would be more valuable for both the community and the person asking the question, but a short one may contain enough information if the person asking the question is ready to make an effort to search for details on his own.

Basic example:

Question:

I notice that a few classes have a lot of code related to the creation of the instances of those classes, rather than the logic itself. For example, one class contains three short instance methods, but eight static methods which deal with its initialization.

Having all those static methods in the class itself it distracting. Moreover, I don't understand how is it possible to mock those methods for unit tests.

What should I do?

Quick and short answer:

You may be interested in factory design pattern.

For community, such answer is not particularly valuable. It doesn't explain neither why a factory is useful here, nor how to use it, nor if this is the only solution to the OP's problem. From a real answer, I would expect:

  • The general explanation of what factory pattern is about,

  • Additional benefits of the factory pattern the author of the question may not think about, such as the possibility to create instances of different types (a factory which creates either Cat inherits Animal or Dog inherits Animal depending on some criteria),

  • The explanation of the difference between a factory and an abstract factory (especially the relation with mocking, mentioned in the question),

  • The mention of the builder pattern,

  • An example (piece of code) of a factory pattern applied to a class (and how the factory pattern can be mocked),

  • Eventually additional hints, such as the usage of method chaining in a builder for a more fluent interface.

On the other hand, the question is actually answered, and if the author of the question makes an effort of searching for factory pattern, he will find everything he needs to successfully get rid of those static methods in his class.

If I can post a quick and short answer, but don't have time for a long, detailed answer (and don't have time to edit it in the near future into a detailed answer), what should I do:

  1. Post an answer?
  2. Post it as a comment?
  3. Post an answer as a community wiki, expecting other people to make it more detailed (I hardly doubt this will work; other persons would rather post their own answer instead)?
  4. Avoid posting anything and make the person wait until somebody else answers the question?
1

1 Answer 1

5

If I can post a quick and short answer, but don't have time for a long, detailed answer (and don't have time to edit it in the near future into a detailed answer), what should I do:

  1. Post an answer?
  2. Post it as a comment?
  3. Post an answer as a community wiki, expecting other people to make it more detailed (I hardly doubt this will work; other persons would rather post their own answer instead)?
  4. Avoid posting anything and make the person wait until somebody else answers the question?

Personally, I would post it as a comment and come back to it later to fully flush out the answer if another one hasn't been posted to the quality that I would hope to see.

You are exactly right in that the short answer of "You may be interested in factory design pattern." is not particularly valuable. Having answers such as these show up in results for new users suggests that they are acceptable answers and may have a less than ideal experience when they try posting "use a singleton" as an answer.

Again, personally, I'd rather avoid encouraging the short answer. Stack Overflow has difficulties with people seeing the "try ${some code}" answers and posting them themselves. Without any explanation these short answers really aren't that useful at providing the why for the next person who comes by with a similar question and doesn't understand why the "You may be interested in factory design pattern." answer was accepted (or up voted).

By providing comprehensive answers that fully answer the question rather than partial answers we not only encourage people to write interesting answers (that we want to read), but also encourage people that are willing to take the time to write the long answer (I'm quite happy that P.SE doesn't suffer much from the Fastest Gun In The West).

Unless the answer is something that is truly to be collaborative or substantial and lacks originality (e.g. an answer that is mostly a copy and paste of other sources), I wouldn't make it community wiki. This is partly because if I was to post an answer that was fully elaborating on the "use a factory pattern", I wouldn't go to the community wiki post and edit it into shape - I'd post my own answer that is substantially better (I like my internet points). Whats more, if the community wiki answer is up voted or accepted, already (coming back to the question a daly later that day to write my own), I may be less inclined to write my substantially better answer.

Posting the suggestion as a comment may indeed be the right answer for the person asking the question. It could facilitate the person realizing the proper solution to the question and writing their own self answered post. This would be a good thing (noting the challenge of writing a good self answer). It may also lead other people to create a better answer.

So:

  • Post it as a comment.
  • Point people in the right direction for more substantial answers.
  • Come back later when you have the time to write a more complete answer.

Every answer that is posted encourages other people to answer other questions in a similar manner. Post the type of answer you would like to read in other questions.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .