Accessors and mutators ('get' and 'set' methods) are either a necessary evil, or poor programming, depending on your point of view.

In his book on design patterns - 'Holub on Patterns' - Allen Holub has a section in the first chapter called 'Getters and Setters Are Evil'. This is obviously an extreme view! However, he does qualify this position somewhat:

This isn't to say that your functions shouldn't return values or that "get" and "set" fuctionality is never appropriate. ... Nonetheless, get/set functions are often used inappropriately as a means of accessing otherwise private fields, and it's that usage that will give you the most trouble.

Holub characterises misuse of accesor functions as 'laziness' - deferring decisions about object interaction until later. That is to say, when the programmer first creates a class the accessor methods are created along with the attributes of the class. This is especially true for JavaBeans - which are simply Java classes with certain requirements - including the necessity for getX and setX methods for any attribute X. These 'beans' can be created semi-automatically by an IDE (you add an attribute to the bean through some GUI and the get/set methods are created for you).

Whether you agree with this assessment or not, there are other options in other languages. You can make a private inner class in C++ (see ariels writeup) that provides you with a rich attribute that you can 'get' and 'set' with the normal language syntax (e.g. 'instance.attribute = value;' instead of 'instance.setAttribute(value);'). In Python this kind of trick is simplified to use of a property to wrap a method:

class Interval:

        def __init__(self, start, end):
                self.start = start
                self.end = end

        def getLength(self):
                return self.end - self.start

        def setLength(self, length):
                self.end  = self.start + length

        length = property(fget=getLength, fset=setLength, doc='length of the interval')

if __name__ == "__main__":
        interval = Interval(1, 10)
        print interval.length
        interval.length = 10
        print interval.end
 

What the 'length = property(...)' call does is associate the 'length' attribute with the two 'getLength' and 'setLength' methods (and a documentation string). As you can see from the test code at the end, accessing the pseudo-attribute 'length' effectively calls the 'getLength' method, while assigning to 'length' calls the 'setLength' method.