Java Interface Usage Guidelines -- Are getters and setters in an interface bad?

Posted by user68759 on Stack Overflow See other posts from Stack Overflow or by user68759
Published on 2009-07-15T09:15:48Z Indexed on 2010/04/03 22:33 UTC
Read the original article Hit count: 445

Filed under:
|
|
|
|

What do people think of the best guidelines to use in an interface? What should and shouldn't go into an interface?

I've heard people say that, as a general rule, an interface must only define behavior and not state. Does this mean that an interface shouldn't contain getters and setters?

My opinion: Maybe not so for setters, but sometimes I think that getters are valid to be placed in an interface. This is merely to enforce the implementation classes to implement those getters and so to indicate that the clients are able to call those getters to check on something, for example.

© Stack Overflow or respective owner

Related posts about java

Related posts about interface