Java Reference
In-Depth Information
Designing classes
Main concepts discussed in this chapter:
responsibility-driven design
Java constructs discussed in this chapter:
static (for methods), Math , enumerated types, switch
In this chapter, we look at some of the factors that influence the design of a class. What makes
a class design either good or bad? Writing good classes can take more effort in the short term
than writing bad classes, but in the long term that extra effort will often be justified. To help
us write good classes, there are some principles that we can follow. In particular, we introduce
the view that class design should be responsibility-driven, and that classes should encapsulate
their data.
This chapter is, like many of the chapters before, structured around a project. It can be studied
by just reading it and following our line of argument, or it can be studied in much more depth
by doing the project exercises in parallel with working through the chapter.
The project work is divided into three parts. In the first part, we discuss the necessary
changes to the source code and develop and show complete solutions to the exercises. The
solution for this part is also available in a project accompanying this topic. The second part
suggests more changes and extensions, and we discuss possible solutions at a high level (the
class-design level) but leave it to readers to do the lower-level work and to complete the
The third part suggests even more improvements in the form of exercises. We do not give
solutions—the exercises apply the material discussed throughout the chapter.
Implementing all parts makes a good programming project over several weeks. It can also be
used very successfully as a group project.
Search WWH ::

Custom Search