Summary: Allow languages without default parameters to simulate their use. [Code Pattern] Example You want to provide a method to open a file. You always need a filename, but you might have other parameters you occasionally use to specify things like buffering. C++ allows for default parameters to specify a value for when the parameter […]
Category: Java
Summary: This is a pair of code patterns for dealing with the dependencies between a subclass and a superclass caused by constructors, and for creating only one copy of a class. Designated Initializer Example It’s easy to have an unexpected constructor be called. class A { A() {System.out.print(“A(); “);} A(String s) {System.out.print(“A(“+s+”); “);} } class […]
Summary: This pair of patterns is inspired by some of the design decisions in the Java class library. Marker Class AKA Tagging Class Example: You would like to have all objects provide a clone method. This is a generally useful facility, so you want it high in the hierarchy, but it’s potentially an expensive method, […]