Java Reference
In-Depth Information
Chapter 15
Object-Oriented Coding
Working with Classes and Objects
Itisnowtimetoputtoworkyourknowledgeofobject-orientationandyour
skills in Java programming. So far we have been dealing with small pro-
grams that contain a single class. Our programs have used static variables
andmethods.Infact,wehaveturnedoffobjectorientationandusedJavaas
a semi-procedural language. But the advantages of Java are related to its
object-orientedfeatures.Atthispointyouarereadytostartdevelopingtrue
object-oriented programs and learning to use the OO features of Java.
Thinking Objects
AJavaprogramisacollectionofclasses.Inawell-designedandwellcoded
program, these classes interact with each other and provide a reasonable
andreusablesoftwareenvironment.Aclassisatemplate:anobjectfactory.
Theclassdefinestheattributesandbehaviorofitsobjects.Itisusedtocre-
ate objects. You must always keep in mind that the class is a programming
construct.Althoughyoudefinethedatatypesandwritemethodsinaclass,
the data the methods are contained by the object. In this sense we can say
that the class is the cookie cutter, and the object is the cookie.
Because the functionality (methods) and the information (data) is in
the object, not in the class, we sometimes say that the object knows .It
knows the information contained in its data members, and it knows how
to perform the operations in its method members. The object is a unit of
data and processing. It is for these reasons that we talk about object-ori-
ented programming, not class-oriented programming.
Search WWH ::




Custom Search