Beginning Java Objects: Chapter 3 Objects and Classes
Encapsulation
Encapsulation is a formal term referring to the mechanism that bundles together the
state information (attributes) and behavior (methods) of an object into a single logical
unit. Everything that we need to know about a given student is, in theory, contained
within the 'walls' of the student object, either directly as an attribute of that object
or indirectly as a method that can answer a question or make a determination about the
object's state.
Encapsulation is not unique to OO languages, but in some senses is perfected by them. For those of
you familiar with C, you know that:
A C struct(ure) encapsulates data:
struct employee {
char name[30];
int age;
}
and a C function encapsulates logic — data is passed in, operated on, and an answer is optionally
returned:
float average(float x, float y) {
return (x + y)/2.0;
}
But only with OO programming languages is the notion of encapsulating data and behavior in a
single construct called a class, to represent an abstraction of a real-world entity, truly embraced.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|