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

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

Cited Papers

The visitor pattern as a reusable, generic, type-safe component
err2008-10-19
err0
errOAAI
errBruno C.d.S. Oliveira; Meng Wang; Jeremy Gibbons
errShare
errSave
errShare
errSave
Aspect-oriented programming
err2006-05-23
err0
PREAI
errGregor Kiczales; John Lamping; Anurag Mendhekar; Chris Maeda; Cristina Lopes; Jean-Marc Loingtier; John Irwin
errShare
errSave
On the Positive Effect of Reactive Programming on Software Comprehension: An Empirical Study
err2017-12-01
err17
PREAI
errSalvaneschi, Guido; Proksch, Sebastian; Amann, Sven; Nadi, Sarah; Mezini, Mira
errShare
errSave
Code smells and refactoring: A tertiary systematic review of challenges and observations
err2020-09-01
err102
errOAAI
errLacerda, Guilherme; Petrillo, Fabio; Pimenta, Marcelo; Gueheneuc, Yann Gael
errShare
errSave
Agent design pattern catalogue: A collection of architectural patterns for foundation model based agents
err2025-02-01
err0
errOAAI
errLiu, Yue; Lo, Sin Kit; Lu, Qinghua; Zhu, Liming; Zhao, Dehai; Xu, Xiwei; Harrer, Stefan; Whittle, Jon
errShare
errSave
err
IF0
err
err0
PREAI
err
errShare
errSave
A mapping study of language features improving object-oriented design patterns
err2023-08-01
err0
PREAI
errFlageol, William; Menaud, Eloi; Gueheneuc, Yann-Gael; Badri, Mourad; Monnier, Stefan
errShare
errSave
researcher View more