Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a class which consists mostly of data storage responsibilities. The context for the use of this class will, in general, be retrieving an array of objects of this type for display later. In light of that, I've created a static method, build_question_array(), which queries the database, instantiates the objects, and returns the array. Does this violate the "SOLID" principle?

share|improve this question
(1) will a constructor be sufficient? (2) can the array of such objects be stored in a standard array or collection? (3) does your static method talk directly to the database (issuing the queries directly)? (My opinion is that your static method is probably a "utility function", and as such it can be placed anywhere, not necessary inside your data object.) – rwong Oct 2 '11 at 3:04
up vote 2 down vote accepted

Firstly, it does not obey the Open/Closed principle, because you won't be able to change anything at runtime in a static method.

I don't know whether it obeys the Single Responsibility principle, because I don't know whether it implements or delegates all of its work. If it implements it, it doesn't obey this principle.

EDIT: If that static method is inside the data structure's class, then it definitely does not obey SRP. The data class should not know or care about its various types of uses.

The Liskov Substitution principle isn't a factor since it's only one class, and it's a static method.

Interface Segregation also doesn't apply here.

Dependency Inversion is questionable here, because unless you can pass a delegate to this function or you're using a dynamic language, you're making every one of your clients depend on this sole implementation of this functionality.

So all in all, no, it doesn't.

share|improve this answer
"you won't be able to change anything at runtime in a static method" - the OCP does not mandate runtime changes specifically. – Péter Török Oct 2 '11 at 6:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.