Java Reference
In-Depth Information
CHAPTER 5
■ ■ ■
The DvdDatabase Class
I n this chapter, we will start working on our assignment by developing a DvdDatabase class,
which will implement the DBClient interface described in Chapter 3. Since both the client and
the server need this class, starting the assignment with this class is quite logical.
As you work through this chapter, you will use several important concepts introduced in
Chapters 2 and 3:
Design patterns
Generics
As mentioned earlier in this topic, there are several areas in our sample project where we
feel we must deviate from the project provided by Sun. Nowhere is this more important than
with the classes presented in this chapter. Either the code used in this section of our sample
assignment will quite often be more detailed than your assignment requirements, or we
will use shortcuts that you cannot use in your assignment. In particular, we specify that
java.io.IOException can be thrown in our interfaces and classes, greatly simplifying our
development; we complicate our assignment by having timeouts on locks; and we use
ReadWriteLock s to improve concurrency. Regardless, all the information you need to develop
a good solution for your requirements is presented in this chapter.
We also discuss issues that you might want to consider for your assignment that are not
required but that may make your submission more professional. This includes the topics of
caching data, handling deadlocks, managing client crashes, and using multiple notification
objects to reduce CPU usage by threads trying to obtain a logical record lock.
Creating the Classes Required for
the DvdDatabase Class
The DvdDatabase class uses a few other classes as inputs, outputs, or exceptions. We need to
build these before we can build the Data class itself.
The DVD Class: A Value Object
The DvdDatabase class uses a class named DVD to contain the data corresponding to a DVD that
can be reserved. This type of object is referred to as a value object. The Value Object design
pattern is also referred to as the Transfer Object pattern. The name value object represents the
type of object it is; it contains all the values relating to a particular object (in our case, all the
119
Search WWH ::




Custom Search