Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 2
    Getters/Setters may guard against unhindered modification of internal state but they still expose the implementation details of the internal state. You are now tightly coupling the implementation of your object to have particular state (Which makes changing or upgrading the class nearly impossible for all but the most trivial classes). Methods should be verb that indication actions that are performed on the object. If you have a getter/setter you need to ask why am I exposing this implementation detail is it because my class lacks an interface to manipulate the object that my users need. Commented Jan 20, 2011 at 18:52
  • @Martin York Although you make some good points, I'm afraid that I disagree. In my getter I've chosen to represent the internal state using the same external type (byte[]). I could just have easily wrapped it up within an object, but that would just have added complexity to the simple example. Even if the internal representation changes, the getter can act as an adapter to maintain the external interface. Also, I disagree that methods should always be verbs. In my opinion encapsulation trumps naming conventions every time. Commented Jan 20, 2011 at 21:59