Design pattern for reusing immutable methods in object-oriented languages. Flageol, W., Gu�h�neuc, Y., Monnier, S., & Badri, M. Journal of Computer Languages (COLA), 86:101385, Elsevier, February, 2026. 25 pages.
Design pattern for reusing immutable methods in object-oriented languages [pdf]Paper  abstract   bibtex   
Programming concepts from functional programming have grown in popularity and have been introduced in object-oriented programming. Among these concepts, immutability is a core concept of functional programming, which brings advantages to software development. However, introducing immutability in object-oriented programming languages presents some challenges. Problem: One of these challenges, in the concept of inheritance, is overriding of non-destructive mutators. Mutators are necessary for updating data as a software is running. Non-destructive mutators are mutators on immutable objects, which return new objects instead of modifying the receiver. When inheriting non-destructive mutators, a naive implementation will yield code duplication and have code scalability issues. Contribution: We analyze an example of overriding non-destructive mutators, discuss the challenges, and propose a solution that takes the form of a new design pattern, inspired from the Factory Method pattern. We also discuss the advantages and limitations of this pattern, as well as implementations in eight languages (Clojure, Common Lisp, C#, Java, Kotlin, OCaml, Rust, and Scala). We finally identify and discuss the language features that mostly affect the implementation of this pattern, and present a language extension to Common Lisp to demonstrate the effects of those features on the implementation. Conclusion: Our proposed design pattern helps reduce the code duplication and improve the code scalability of a naive implementation of inherited non-destructive mutators. However, using a language which includes features for functional updating is required to completely remove the code scalability issues of the implementation. We conclude that object-oriented programming languages should consider adding functional updating to their language features to better support their new functional programming features.

Downloads: 0