4

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.

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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