2

The Decorator pattern allows behaviour to be dynamically added to an existing object, effectively "decorating" it with new behaviour. While the pattern as formalised and named seems to have been popularised by the "Design Patterns" book in 1994 by the Gang of Four, I'm curious about its origins.

In functional programming, higher-order functions can wrap other functions to add behaviour without changing their signature. In modern programming, this is frequently referred to as "decorating" - particularly in e.g. Python, Go, but also generally pretty much anywhere higher-order functions are available. This was presumably a "pattern" in ML, in Lisp, or even potentially in λ-calculus almost 60 years prior to the publication of the GoF book. In particular, I've seen examples of memoization in functional programming (replication of which is frequently a textbook use-case for the decorator pattern in OOP) going back to at least the late 60s.

  • Was this specific case (more general than memoization, but more specific than function composition in general) a formal concept in functional programming literature?
  • Was it called "decorating", and the GoF named the pattern after it, or is it now called "decorating" after the GoF pattern?
2
  • 3
    This might not have a simple answer. GoF didn't invent the patterns, they made a catalogue of what people were already using, so it's quite likely that some of the pattern names (and ideas) predate the book (and in fact, for many patterns they give alternate names that people were apparently using) - it's just that the patterns were less widely known, and their naming was inconsistent. So, GoF may have been influenced by preexisting ideas, but it's also simultaneously possible that the GoF book subsequently influenced how people named modern language features and/or practices. Oct 5, 2023 at 15:25
  • The main performance benefit of functional programming that I've heard argued is related to the memoization of pure functions. In theory this feature (or similar optimizations) can also be implemented in OO but it's mainly associated with functional programming.
    – JimmyJames
    Oct 5, 2023 at 18:11

1 Answer 1

2

The term "design pattern" in software development is inspired by the work of Christopher Alexander, an architect who wrote three books that would inspire the object-oriented programming community to explore these ideas in software: "The Oregon Experiment", "A Pattern Language", and "The Timeless Way of Building".

Kent Beck and Ward Cunningham lived and worked in Portland Oregon, so Alexander's ideas and experiments were in close proximity. In 1987, they brought the idea of software-based patterns to the OOPSLA conference.

The idea caught on, and at successive OOPSLA conferences, more patterns were discovered and shared, as their potential for revolutionizing the practice of software development captured everyone's imagination. The first mention of the Decorator pattern appears to be in a 1993 OOPSLA paper by Bruce Anderson and Peter Coad. The pattern is attributed to Richard Helm, John Vlissides, and someone identified only as Ericsson, while employed at IBM.

The pattern's name most likely originates with these three as object-oriented programmers/researchers, even though its use existed quite naturally in functional programming in the form of higher-order functions. It's a similar concept, but a different nomenclature.

1
  • Thanks! Do you happen to have a link to that paper? Nov 12, 2023 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.