Characterising the Use of Encapsulation in Object Oriented Systems
Degree GrantorUniversity of Canterbury
Software is commonly very large and complex, and consequently hard to develop, understand and maintain. Encapsulation is the practice of breaking a system up into well-defined pieces and hiding internal details within each piece. It supports modularisation and information hiding, making it one of the most fundamental tools software developers have for managing complexity. Object oriented design heuristics have been proposed to help developers achieve better software designs and thus improve overall software quality; many of these design heuristics concern the use of encapsulation or are based on underlying assumptions about encapsulation. However, design advice in this area often conflicts. Little is known about how developers apply encapsulation in practice. In this work, we identify and compare two radically different schools of thought that underpin encapsulation policies and lead to the conflicting encapsulation advice. We conducted a survey to reveal which encapsulation policy is more intuitive, and found that novices’ intuition about encapsulation differs from the encapsulation mechanisms supported by languages such as Java and C#. Following the survey, we empirically analysed encapsulation in real-world software to determine which encapsulation policies are followed in practice, uncovering a general culture of confusion and inconsistency around the use of encapsulation. This finding leads us to propose refactoring tools and a visualisation for helping developers improve encapsulation in software.