arrow
Return

Design pattern for reusing immutable methods in object-oriented languages

delete2026-01-01
delete0
PRE
AI
W
William Flageol *
Y
Yann‐Gaël Guéhéneuc
S
Stefan Monnier
M
Mourad Badri
DOI:10.1016/j.cola.2026.101385delete
deleteOriginal
deleteOriginal request for help
deleteShare
deleteSave
Abstract

Abstract

En 中文
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.
Keywords:
Object-oriented programming
Design patterns
Functional programming
Immutability
Language features

Journal

J
Journal of Computer Languages
IF:
1.8
Papers:
28
Citations:
323

Organization

U
university of quebec trois rivieres
Scholars:
1.3K
Papers: 1.2K
Citations: 1
C
concordia university - canada
Scholars:
8.0K
Papers: 8.9K
Citations: 4
U
university of quebec
Scholars:
2.0W
Papers: 1.9W
Citations: 19
researcher View more organizations