In this installment of his Design Techniques column, I discuss the ways in which static fields and methods, which exist outside of objects, fit into object-oriented design.
This article gives advice on using runtime class information in Java programs. It talks about the method area of the JVM and the structure of Java objects, upcasting and downcasting, polymorphism and dynamic binding, java.lang.Class and reflection, and -- perhaps most importantly -- reveals how best to ask a hippopotamus to dance.
In this installment of Design Techniques, I take a look at a less commonly understood aspect of Java's architecture: dynamic extension. I discuss the two kinds of dynamic extension, forName() and class loaders, and offer guidelines on how to use these tools to make your programs more customizable.
This article describes the process I went through to understand Java's interface. I talk about multiple inheritance and the diamond problem, polymorphism and dynamic binding, separation of interface and implementation as the spirit of Java, and my ultimate epiphany on how we should think about and use interfaces when we design.
In this installment of my Design Techniques column, I analyze the flexibility and performance implications of inheritance and composition, and I give guidelines on the appropriate use of each.
In this installment of the Design Techniques column, I propose "the canonical object" as a Java idiom. The article discusses the fundamental services that all objects in general should offer, shows how objects can offer these services, and names such objects "canonical."
In this installment of the Design Techniques column, I propose the "event generator" as a Java idiom. The article provides a background on the concepts of patterns and idioms, describes the observer pattern, and demonstrates the idiomatic way to implement the observer pattern in Java.
This article gives you design guidelines pertaining to thread safety. It provides a background on thread safety and shows several examples of objects that are and are not thread-safe, including two illustrative applets. In addition, the article offers guidelines to help you decide when thread safety is appropriate and how best to achieve it.
This article gives design guidelines that pertain to exceptions. It shows how to decide when to use exceptions, using examples from the Java API that illustrate appropriate uses of exceptions. In addition, the article provides some general guidelines that can help you use exceptions in those situations where you've decided they are appropriate.
This tutorial covers the nuts and bolts of what exceptions are and how they work in the Java language and virtual machine. It discusses exception classes and objects, throwing and catching exceptions, the method invocation stack, the throws clause, checked vs. unchecked exceptions, and finally clauses.
This installment of the Design Techniques column discusses the design guidelines that pertain to the end of an object's life. I give an overview of the rules of garbage collection, discuss finalizers, and suggest ways to design objects such that finite resources aren't monopolized.
This article describes the "popular lore" that aims to improve the performance of Java programs in ways that reduce the flexibility of the code, and describes Sun's Hotspot JVM in technical detail. The article shows how Hotspot attempts to eliminate the performance bottlenecks that gave rise to the "popular lore" in the first place.
In this installment of the Design Techniques column, brush up on how -- and why -- to divide a class's functionality among its methods. I demonstrate how to maximize method cohesion while keeping the total number of methods to a manageable level.
This installment of the Design Techniques column shows how some fundamental software design techniques, like avoiding special data values and minimizing method coupling, apply to Java.
This article describes the process of object initialization in Java programs. It discusses constructors, initializers, instance initialization (<init>) methods, initialization and inheritance, object images on the heap, and the order in which an object's variables get initialized.