What is a Helper Class?
-
A helper class is a name commonly given to programmer-defined classes
because they help your Applets and applications perform their tasks.
-
Like the built-in classes, a class that you write will represent something.
For instance, you could design and write a class that represents an elevator,
a book, a student, a test score, an output file, or any other type of
thing.
-
Notice that all of these examples are nouns - this is because in
object-oriented design (OOD), you concentrate on the objects.
-
Once
you have a class designed, coded, and tested, you will be able to declare
objects using this new class. If you had a class that represents a test score,
you could declare an object of this class just like you declared a
a Point object to represent a 2-dimensional point or a String object to represent a string.
- The reason the a well-designed class is so simple to use is that it
is doing most of the work for you and hiding the details. This basic idea is called
encapsulation.
- Let's take a look at the documentation for a class called
OutputDataFile that I wrote.
- Reading in or writing out data is fairly complex,
however when we use this class, all we have to understand is what the class represents and how to
use it correctly; we don't have to worry about how the internals of
the class work.
- A well-designed class is easy to use because it hides details (also called
data hiding) and contains all of
the behavior that is logically associated with an object of that class. This
is called encapsulation. We will learn to follow both of these good
class-design practices as we learn how to design a class.
- You should always design your class before coding it. However, since
learning the basic syntax can help in understanding how to design, we will
cover it
briefly next, then talk about design, and then put them together to
create our own classes.