Posts

Showing posts with the label defensive copy

Encapsulation

I believe this is the most important aspect of Object-Oriented Design (OOD) and Programming (OOP). I also believe this is the most disregarded. It is disregarded because it is not fully understood. It is my opinion that this aspect of OOP is misunderstood because beginner programmers focus in learning WHAT encapsulation is, and not why it is important or needed. This article aims to explain why encapsulation is important and how to achieve true encapsulation. Although anyone could look up its definition in a dictionary, I would like to start by defining the word 'encapsulation.' Encapsulation simply means to enclose something in. To completely cover or hide something especially so that it will not touch (or come in contact with) anything else. In the real world, there are many reasons to encapsulate. For example, certain medication come in the form of capsules. The real value of medicinal capsules in in the medicine that it encloses. To make a long story short, med