Skip to main content
Top

2019 | Book

Java Program Design

Principles, Polymorphism, and Patterns

insite
SEARCH

About this book

Get a grounding in polymorphism and other fundamental aspects of object-oriented program design and implementation, and learn a subset of design patterns that any practicing Java professional simply must know in today’s job climate.
Java Program Design presents program design principles to help practicing programmers up their game and remain relevant in the face of changing trends and an evolving language. The book enhances the traditional design patterns with Java's new functional programming features, such as functional interfaces and lambda expressions. The result is a fresh treatment of design patterns that expands their power and applicability, and reflects current best practice.
The book examines some well-designed classes from the Java class library, using them to illustrate the various object-oriented principles and patterns under discussion. Not only does this approach provide good, practical examples, but you will learn useful library classes you might not otherwise know about.
The design of a simplified banking program is introduced in chapter 1 in a non-object-oriented incarnation and the example is carried through all chapters. You can see the object orientation develop as various design principles are progressively applied throughout the book to produce a refined, fully object-oriented version of the program in the final chapter.

What You'll Learn
Create well-designed programs, and identify and improve poorly-designed ones
Build a professional-level understanding of polymorphism and its use in Java interfaces and class hierarchies
Apply classic design patterns to Java programming problems while respecting the modern features of the Java language
Take advantage of classes from the Java library to facilitate the implementation of design patterns in your programs

Who This Book Is For
Java programmers who are comfortable writing non-object-oriented code and want a guided immersion into the world of object-oriented Java, and intermediate programmers interested in strengthening their foundational knowledge and taking their object-oriented skills to the next level. Even advanced programmers will discover interesting examples and insights in each chapter.

Table of Contents

Frontmatter
Chapter 1. Modular Software Design
Abstract
When a beginning programmer writes a program, there is one goal: the program must work correctly. However, correctness is only a part of what makes a program good. Another, equally important, part is that the program be maintainable. This chapter discusses the characteristics of well-designed software and introduces several design rules that facilitate its development.
Edward Sciore
Chapter 2. Polymorphism
Abstract
Each class in a well-designed program denotes a distinct concept with its own set of responsibilities. Nevertheless, it is possible for two (or more) classes to share some common functionality. For example, the Java classes HashMap and TreeMap are distinct implementations of the concept of a "map," and both support the methods get, put, keySet, and so on. The ability of a program to take advantage of this commonality is known as polymorphism. Polymorphism is arguably the most important design concept in object-oriented programming. This chapter explores Java interfaces and how they are used to support polymorphism. 
Edward Sciore
Chapter 3. Class Hierarchies
Abstract
Chapter 2 examined how interfaces can extend other interfaces, creating a hierarchy of types. One of the characteristics of an object-oriented language is that classes can extend other classes, creating a class hierarchy. This chapter investigates class hierarchies and the ways they can be used effectively.
Edward Sciore
Chapter 4. Strategies
Abstract
Class hierarchies are a fundamental feature of object-oriented programming languages. Chapter 3 examined their capabilities. This chapter examines their (often significant) limitations and introduces the more flexible concept of a strategy hierarchy. Strategy hierarchies are a central component of several design techniques. This chapter examines two such techniques—the strategy pattern and the command pattern—and their uses.
Edward Sciore
Chapter 5. Encapsulating Object Creation
Abstract
Polymorphism enables code to be more abstract. When your code references an interface instead of a class, it loses its coupling to that class and becomes more flexible in the face of future modifications. Such abstraction is not possible with class constructors. This chapter examines the techniques of object caching and factories, which help the designer to restrict constructor usage to a small, well-known set of classes.
Edward Sciore
Chapter 6. Iterables and Iteration
Abstract
This chapter examines the question of how to iterate through a collection of objects. The chapter examines external iteration, in which you write a loop to examine the elements, and internal iteration, in which you call a method to perform the loop for you. The methods of the Java Stream interface are discussed, which provide a powerful example of internal iteration.
Edward Sciore
Chapter 7. Adapters
Abstract
This chapter examines the concept of an adapter, which is wraps a class in order to change its functionality. Several examples are presented that illustrate the widespread applicability of adapter classes. Of particular interest are the Java library classes that adapt byte streams, which make it possible to read and write streams of characters, primitive values or objects.
Edward Sciore
Chapter 8. Decorators
Abstract
A decorator is a wrapper that implements the same interface as the object it wraps. Decorator methods enhance the methods of the wrapped object, in contrast to adapter methods, which replace the methods of the wrapped object. Moreover, an object can be decorated multiple times, with each decorator providing its own enhancement. This chapter examines several useful applications of decorators.
Edward Sciore
Chapter 9. Composites
Abstract
This chapter studies composite objects, which are similar to a decorators except that they wrap multiple objects. This seemingly small distinction makes a big difference in the structure of a composite and how it is used. Composite objects correspond to trees and composite methods tend to involve tree traversals. This chapter presents three examples of composites: predicates, graphical user interfaces, and cookbook recipes. These examples share a common class design known as the composite pattern. They also have some functional differences that illustrate the different choices a designer faces.
Edward Sciore
Chapter 10. Observers
Abstract
A program may need to respond to change events and input events.. . The use of observers is a general-purpose technique for managing a program’s responses to events. An object can maintain a list of observers and notify them when a notable event occurs. This chapter introduces the observer pattern, which is the preferred way to incorporate observers into your code.
Edward Sciore
Chapter 11. Model, View, and Controller
Abstract
This last chapter of the book takes up the issue of how to separate a program’s computation-related responsibilities from its presentation-related ones. It argues that programs should isolate the computation classes from the presentation classes, and for this you need classes to mediate between them. The computation, presentation, and mediator classes are called model, view, and controller. This chapter introduces the MVC pattern, which is the preferred way to organize these classes in a program. The chapter discusses the advantages of using the MVC pattern and gives several examples.
Edward Sciore
Backmatter
Metadata
Title
Java Program Design
Author
Edward Sciore
Copyright Year
2019
Publisher
Apress
Electronic ISBN
978-1-4842-4143-1
Print ISBN
978-1-4842-4142-4
DOI
https://doi.org/10.1007/978-1-4842-4143-1

Premium Partner