The fragile base class problem is a fundamental architectural problem of object-oriented programming systems where base classes (superclasses are considered "fragile" because seemingly safe modifications to a base class, when inherited by the [derived classes](https://en.wikipedia.org/wiki/Subclass_(computer_science)), may cause the derived classes to malfunction. The programmer cannot determine whether a base class change is safe simply by examining in isolation the methods of the base class.
One possible solution is to make instance variables private to their defining class and force subclasses to use accessors to modify superclass states. A language could also make it so that subclasses can control which inherited methods are exposed publicly. These changes prevent subclasses from relying on implementation details of superclasses and allow subclasses to expose only those superclass methods that are applicable to themselves.
Using closures for that tends to have performance impact, the big benefit of underscores is that it it very clearly says to other people what is intended to be part of the public api and what is intended for the internal api. Somebody can always much about with your code latter so there isn't really any guarenteed security, so you may as well avoid slowing everything down/breaking inheritance trying to get it.
3
u/bio595 Mar 28 '15 edited Mar 28 '15
I'm not a massive fan of marking private variables on this with leading underscores. I prefer to create a variable in the closure scope.
It prevents someone from changing it when you don't expect them to.