Separate allocation and initialization: provide them as separate operations rather than as a joint operation. [Low-level Design Pattern] Context You’re creating an object based on an external data structure. Part of the job is to create your object, and part is to populate it with the information from the external structure. Forces We want to […]
Category: patterns
Make expensive operations cheaper using a quick-and-dirty check. [Low-level Design Pattern] Context Performance is important. Forces You have a time-consuming operation. If only …, the operations wouldn’t be so expensive. Resolution Develop two versions of the operation: one that handles all complications, and another that deals with a common simple case. Devise a quick-and-dirty check […]
Pattern Patter: Post-Process Binaries
Summary: Add capabilities to a language without extending the language. [Architecture Pattern] Example You may have a source language that doesn’t provide a particular capability. You can’t or won’t change the source language. (Perhaps you can’t change the language; perhaps making the user recompile just to acquire that capability is too time-consuming.) Forces You want […]
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 […]
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, […]
Summary: This set of structural patterns deals with resolving the pressures caused by an attribute that turns out to have multiple occurrences. Motivation When we want to keep track of an attribute of an object, deeper analysis often reveals that the attribute occurs multiple times, or takes on different values over time. For example, in […]
Pattern Patter: Resources
Summary: There are many resources for people interested in patterns. This month, I’ll review some of the more important ones. On the Web http://billwake.blogspot.com/search/label/patterns My patterns home page. http://st-www.cs.uiuc.edu/users/patterns/The Patterns Home Page. These are the basic patterns pages, hosted by UIUC. http://www.bell-labs.com/cgi-user/OrgPatterns/OrgPatternsThe Organizational Patterns Page. Patterns for software engineering in the large. http://c2.com/ppr/Portland Pattern Repository. […]
Pattern Patter: Absorbing Exceptions
Context Exceptions are rare There is no language support for exceptions Forces Indications Code that looks like this: status = add_primitive (data_structure, value1); if (status != success) return status; status = add_routine (data_structure, value2); if (status != success) return status; Pattern Many times you are accumulating information into a data structure. For some errors, you […]
OPTIMIZATION—–7-Feb-95 message:They put “update events” in the queue. In a long-running process,you’ll periodically query the queue to see if other more importantstuff has come in. There’s a bit about regions. I think you get aregion to update, and you can start updating it, and then mark partof the region as updated. It’s probably not 100% […]