Getting rid of setters/getters?

Dear all,

This is one of the two design points ( the other is about Null Objects ), that  were coming nagging at my mind ;-)

I think giving set/get harms encapsulation ;-) Some code could erroneously set only one of them and take the object in a wrong state ( One way to look at objects is that they model states ;-)

Instead, I think we should look at what the outside code is doing with these get / set and

remove these set / get

push that operation to the object ( it could internally use setters / getters and always maintain a coherent state )

Some Get operations are ok ( like  name() ) but things like setTtl()/ttl() maybe are not, IMHO ;-)
What do you all think?

—- cheers atul

Would you like to post a relpy?


This post starts a thread.
Follow-ups:
Re: Getting rid of setters/getters?
Hi Atul, I see your point how setters and getters can hurt encapsulation and I agree with you that one should be careful what part of the object’s state should directly (more...)