What Is Encapsulation?


Encapsulation is a technique of linking together attributes and procedures to form an object. The only way to access attributes and procedures of an object is to create an instance of the object.

As you ll recall from Chapter 2, you create an object within a program by defining a class. The class definition contains the definitions of attributes and procedures (functions in C++ and methods in Java).

Figure 3-1 shows a diagram of a class that defines the object Student. The top of the diagram is the list of attributes that describe a student. These are a student s ID, student name , and whether or not the student graduated . The bottom of the diagram is a list of procedures associated with a student. These write and display information about a student. The attributes and procedures described in Figure 3-1 are said to be encapsulated in the Student class.


Figure 3-1: A class diagram showing attributes and procedures that are encapsulated in the Student class definition.



OOP Demystified
OOP Demystified
ISBN: 0072253630
EAN: 2147483647
Year: 2006
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net