encapsulation : Java Glossary
Encapsulation means detecting common patterns in your code and writing code to
handle that function once and putting it in an air-tight capsule so that other
programs are unaware of how it works inside. The benefits are:
- If you need to change the code, you need to change it in only once place.
- If you need to change the code, you can change it in one place without having
to make adjustments to all the code that uses it.
- You only have to debug it once. Debugging well-encapsulated code is much easier
since you can test each piece independently and you can easily localise where the
problem must be.
- Since you are writing encapsulated code once and for all, you can spend more
time getting it just right.
- Encapsulation makes it much easier to understand your code.
- Your encapsulated code becomes well-trusted reusable tools you can use to
consruct new programs. They become units of thought in constructing new programs.
You don’t have to start from the basics every time. Think of them as like
modular units in construction rather than always starting from raw lumber and
- Encapsulation marks you as a professional. The hallmark of a rank amateur is a
complete lack of encapsulation.
You can write encapsulated code in almost any language, even assembler. Some
languages, though, like Java make it much easier.
When in doubt, encapsulate.
~ Roedy (born:1948-02-04 age:68)