Passion and Vision are like Scalar and Vector Quantities, Sir Tesla had Both
Passion and Vision are like Scalar and Vector Quantities, Sir Tesla had Both
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Swapnil Mishra wrote:is There any solid reason why? can't we use setters and getters for private methods the same way we use them for private fields ?
That is an unwarranted assumption. Lots of people teach that all fields shoud be accompanied by a pair of setXXX() and getXXX() methods, but many of us believe that isn't actually true. If you look up “bean pattern,” you will find that it includes setters and getters, but you will also find that many people don't like the bean pattern; indeed some people call it an antipattern.Your Thread Title wrote:If setter and getter works well for accessing private fields . . .
Campbell Ritchie wrote:That is an unwarranted assumption. Lots of people teach that all fields shoud be accompanied by a pair of setXXX() and getXXX() methods, but many of us believe that isn't actually true.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Even some of the people who decry Beans as an antipattern will say that persistence is the one thing the Bean Pattern is good for. If you use setXXX() methods for debugging, surely you have them in a protective environment where you can be sure nobody will abuse them. And I said a fuelContent() method would be correct; I fully believe that most getXXX() methods are a Good Thing.Tim Holloway wrote:. . . the Java Persistence Architecture . . .
Agree. But if you are throwing a new exception from a subtype method, which isn't thrown by its superclass' method, is that consistent with the Liskov Substitution Method?. . . "set" methods would be inappropriate. The best they could offer would be an UnimplementedOperationException, and that's not as good as a compile-time error due to the method being undefined altogether. Leave that to subclasses that override read/write functionality. . . .
Campbell Ritchie wrote:Agree. But if you are throwing a new exception from a subtype method, which isn't thrown by its superclass' method, is that consistent with the Liskov Substitution Method?
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Campbell Ritchie wrote:There must be a better way to do that than throw an Exception. Even making the subclass' method do nothing at all might be better. Obviously that has to appear in the documentation comments.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|