By accessors, I tend to think of getters and setters.
By insisting that all methods that touch the object's internal state are accessors, it seems that any instance method that actually uses the state of the object would be an accessor, and that just doesn't seem right. What kind of instance method won't use the state of the object? In other words, an instance method that doesn't use the object's state in some way shouldn't be an instance method to begin with -- it should be a class method.
For example, should the BigDecimal.add
method be considered an accessor? It is a method that will read the value of the instance that the add
method was called on, then return the result after adding the value of another BigInteger
. It seems fairly straight forward that the add
instance method is not a getter nor a setter.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…