Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • Very much this. See Principle of Least Suprise. Things should have names that ensure that people aren't surprised by what they find inside. It makes abstraction powerful, rather than annoying. Commented Dec 16, 2017 at 14:05
  • Thank you for answering, I get some of your points, but (I think) the reason not to set it private is because the derived class may also need that member. Commented Dec 16, 2017 at 14:30
  • When HP is set to private, and class Player implements the method, it is good if HP has nothing related to derived class methods. Commented Dec 16, 2017 at 14:30
  • If Warrior's fury depends on its HP, it is class Warrior which needs to implement a method, but it cannot access HP unless class Player either set HP as public/protected or provide a public/protected method. Commented Dec 16, 2017 at 14:30
  • Under such circumstances, we cannot set HP to private. Is there any concepts I am misunderstanding or misusing? Commented Dec 16, 2017 at 14:33