Pavan Kumar Dittakavi wrote:So, how can we justify encapsulation [ modification of fuelQuantity using the API provided by FuleManagementSystem alone ].
Please share your thoughts on the same.
Encapsulation gives you, the designer,
control. Nobody gets access to anything in your class except via methods
written by you - and, even then, only if
you allow it.
Personally, I'm not a big fan of setters. They smack to me of lazy thinking: "Hey, I've got this field. Let's write something so people can update it."
That's
not the way it should work. An object should move from one predictable state to another in a manner dictated by
business or application rules, not just by saying "oh sure, go ahead and change this field if you want". To be honest, I don't know what that would be for an FMS; but I'd be darn sure I did before I let
anyone change stuff in my class.
Have a look at
this article, it says what I'm trying to a lot better than me.
Winston