Chapter 6. Introduction to Object-Oriented Design in Java
In this chapter, we will consider various techniques relevant to object-oriented design (OOD) in Java.
We’ll look at how to work with Java’s objects, covering the key methods of Object, aspects of OOD, and the use of exception handling schemes.
Throughout the chapter, we will introduce some design patterns—essentially best practices for solving some very common situations that arise in software design.
Toward the end of the chapter, we’ll also consider safe programs—those that are designed so as not to become inconsistent over time.
Note
This chapter is intended to showcase some examples of a complex topic and a few underlying principles. This is by no means a complete treatment, and we encourage you to consult additional resources, such as Effective Java by Joshua Bloch.
Before we get underway, let’s take a moment to discuss an OO term that we are deliberately not using. Many resources and books make extensive use of the term polymorphism (which is Greek for “many forms”) when discussing OO programming. However, although the general idea seems initially useful, on closer inspection it loses its appeal.
The word is intended to cover a wide range of language mechanisms (such as dynamic dispatch or generics), but using the word does nothing to explain the actual language feature being discussed. This leads to an overcomplication of basic mechanisms like method overloading and overriding while also giving the false sense ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access