Java Reference
In-Depth Information
have a basic understanding of the fundamental principles before you start
using object-orientation in your programs.
Encapsulation
Encapsulation means that the elements of a class, data and methods, are
packed in a single capsule. Encapsulation also relates to information hid-
ing, since the data elements contained in the capsule are, in most cases, not
accessible to code outside the class. Encapsulation hides the data. Before
object-orientation came into existence, processing operations were based
on routines and subprograms that shared global data or that received data
passed by the caller. The object-oriented approach encapsulates data and
methods in a single package, called the class, and hides the data so that it
cannot be changed without following proper procedures.
A class consists of both data elements and processing elements. The
data elements of a class are the attributes, and the processing operations
are the methods. Attributes and methods are the class members: the at-
tributes are called the data members and the methods are called the
member functions .
Incidentally...
A class is a structure visible to code, that is, it is a programming con-
struct. End users of an object-oriented program do not see or access
classes. Classes are for programmers. For this reason it is better to
speak of the “clients” of a class than of the “users” of a class.
Encapsulation hides the implementation details and stresses the inter-
face. In general, the interface is what the class exposes to its clients. In
particular the class' interface are its methods and the protocols necessary
to access these methods. The goal of encapsulation is to create a class
abstraction. This abstraction forces the programmer to think conceptu-
ally.
In most cases, the data members of a class are invisible to the client. If
a data member must be made accessible to the class' client, then the class
provides a method that inspects the data element and returns its value. A
class that exposes its data members is said to break encapsulation.
Inheritance
Scientists who study the representation of knowledge were the first to ob-
serve the inheritance of properties. In this sense inheritance refers to the
properties of a higher-level class being shared by its subclasses. Note that
Search WWH ::




Custom Search