Intuitiveness of Class and Object Encapsulation
Encapsulation is one of the most fundamental programming language mechanisms available to software developers for managing the complexity of software systems. One might therefore expect clear guidelines and consistent practices to be used in mature programming languages, and particularly in object oriented (OO) languages, with their rich support for encapsulation. However, the encapsulation practices employed by OO developers are surprisingly variable, even within a given OO language. Published advice on how best to use encapsulation is conflicting and little research has been done to determine what developers do in practice and why. In this work, we focus on one aspect of encapsulation: the encapsulation boundary in OO systems. In the archetypal OO language Smalltalk, object data is private to an object. On the other hand, in statically typed OO languages such as C# and Java, object data is private to a class. This difference has broad implications for software design and maintenance, especially when inheritance is considered. Using a survey of both novice and experienced software developers, we show that the encapsulation boundary supported by mainstream statically typed languages does not coincide with the intuition of most developers.