Saturday, March 20, 2010

Encapsulation

Object diagrams show that an object’s variables make up the center, or nucleus, of
the object. Methods surround and hide the object’s nucleus from other objects in the
program. Packaging an object’s variables within the protective custody of its methods
is called encapsulation.

Encapsulating related variables and methods into a neat software bundle is a
simple yet powerful idea that provides two benefits to software developers:
• Modularity: The source code for an object can be written and maintained independently
of the source code for other objects. Also, an object can be easily
passed around in the system. You can give your bicycle to someone else, and it
will still work.
• Information-hiding: An object has a public interface that other objects can use
to communicate with it. The object can maintain private information and methods
that can be changed at any time without affecting other objects that depend
on it.

No comments:

Post a Comment