Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

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

What constructs in OOP languages (specifically Java) allow you to enforce design decisions and intent?

I think some examples would be the 'final' keyword, access modifiers, template methods, perhaps interfaces - but clearly I am having trouble coming up with an exhaustive list.

Some constructs, like inheritance, feel like they fit this criterion but I find it difficult to explain exactly why.

[edit] Turns out I took down a few more notes: Enum types, constructors, constants, and generic types. Although as in all things explaining why will be more important than just listing examples.

share|improve this question
2  
Documentation, coding guidelines and their violent enforcement. – Philipp May 28 '13 at 8:02
1  
All of them? programmers.stackexchange.com/questions/50179/… – MarkJ May 28 '13 at 11:58
2  
Vague, open, "give me the whole list of" type of question. – Tulains Córdova May 28 '13 at 14:06
up vote 3 down vote accepted

First of all, I think that your question hits a topic which is of great importance these days, namely thinking about and documenting design decisions/intent.

In Java, the main mechanisms to really express intent besides just using the available keywords are assertions and annotations, because you can state for example pre/post-conditions, invariants or even the specification about parts of your programs which can be on a higher level of abstraction than code can be. The benefit comes to light if you have to read or maintain a piece of code written by someone else and you simply can't figure out its functionality.

In addition to that, each keyword has of course some semantics and because of this it also inherently expresses some intention when using it. As a matter of fact, you could state that using any pre-defined keyword in any language could be seen as a design decision, even the usage of a language is already a design decision.

The important point is that you simply can not express all your intentions through code and comments without loosing the "big picture", i.e. the code is definitely not the only truth. Therefore we have a "construct" called architecture which has the purpose of making visible and documenting those design decisions and intentions we are making up while thinking about a system. Sure, they can be enforced in code to make the code better readable and navigable but the code should not be the main place where the intentions are stated.

share|improve this answer

Your Answer

 
discard

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.