Immutability is the inability to modify data after it has been created. Modifications are instead made by copying the data. A property of immutable data is that it is *referentially transparent*.

learn more… | top users | synonyms

0
votes
2answers
91 views

Returning a byte array from a method [on hold]

public abstract class Element { // Removed for verbosity ... protected abstract byte[] GetBytes(); } I'm attempting to create an engine that can create a ...
4
votes
2answers
118 views

Simple builder pattern implementation for building immutable objects

This is a builder pattern implementation to build immutable Person objects: Person class ...
5
votes
1answer
74 views

Yet another immutable string

I know, there are a few implementations of immutable strings out there, but my focus seems to be a little different. My goal was to have a type that provided value semantics, but didn't incur the ...
3
votes
5answers
139 views

An immutable person

I am trying to model person in OOPS using immutability. I have created an object bond with age as 25. To change the age I have created a new object and returned it. ...
8
votes
2answers
401 views

Declaration of bloatedness: the class that knew too much?

I've already expressed concerns about this type's constructor, and I've sort-of* implemented the changes suggested in the answers I got there. Recently I added even more parameters to that ...
2
votes
2answers
97 views

Immutable subclass of a Set class

If I'm creating an immutable class from an existing class, should I override methods that mutate the property or have an instance of it and write my own methods to read from the property? I have an ...
0
votes
1answer
133 views

Immutable C++ String class

I have project where I will need to create lots of immutable strings. If I am using std::string, which has huge overhead - about 60-70% against ...
6
votes
4answers
141 views

Creating SOLID immutable and mutable Location types

I have a Location type: ...
5
votes
3answers
412 views

ImmutableList implementation in C#

I tried to implement an immutable list. ...
8
votes
4answers
794 views

Creating unique registration numbers using object factories

I'm learning about immutability and uniqueness in Java, particularly the use of defensive programming and object factories. I have been asked to create a class containing an object factory that when ...
5
votes
2answers
397 views

Functions with mutable and non-mutable named tuples

I am making some functions within a function for learning which when passed information about a named tuple: it returns a reference to a class object from which we can construct instances of the ...
8
votes
2answers
109 views

Inheriting methods of an immutable type

In my project, I have a type BalanceByBucket that is an immutable type and has a bunch of methods. I have another class called a ...
1
vote
1answer
50 views

Removing getters for a custom enum [closed]

Recently, I perform re-factor on one of my frequent used custom enum, by removing its getter. My rational for doing so it. The enum's custom fields are immutable Only use getters when it is ...
3
votes
2answers
660 views

Immutable Queue in Java using an Immutable Stack

I am new to this Immutability concept and I have some coding experience in JAVA. Recently as a part of internship program, they gave me a 5-day task, which was to implement Immutable Queue. After some ...
5
votes
3answers
86 views

Generating a game board with squares in a rectangle

I am trying to generate a game board (similar to a Monopoly board). I am new to Scala and am thinking that there may be a better way to do this. But improvements to the code are also welcome. ...
7
votes
2answers
237 views

Immutable Linked List in VBA

I made an immutable list class using the head-tail idiom. If I did this correctly, it implements persistent data structures. Unfortunately it doesn't scale well ...
5
votes
4answers
846 views

Should I copy list both in constructor and in getter?

I have a simple immutable class: ...
2
votes
3answers
381 views

ObservableQueue

I'm looking for feedback on this. ...
27
votes
8answers
3k views

Immutable objects in Java

I just finished studying immutable objects and their advantages so I thought I'd create one of my own. Here is my employee class that extends a person class. It is not mutable since I have getters to ...
3
votes
1answer
159 views

Immutable Matrix

I'm writing implementations of some numerical methods to solve linear equations systems, those implementations use the following Matrix class. I'm trying to get this class immutable, due to that the ...
2
votes
2answers
192 views

Replacing an F# loop over a mutable variable by an immutable approach

Consider: let mutable m' = m while m' % i = 0L do m' <- m' / i I've refactored it into: ...
10
votes
2answers
159 views

Immutable Fraction class

Inspired by this question: Fraction class implemented in Objective-C, I have written what I feel is an improved version of the Fraction class in Objective-C. As per the tips in this answer, the class ...
3
votes
1answer
162 views

Functional SaveObject in Scala

I came across Java like Scala code that I am trying to refactor to make it functional and immutable. The first obvious flaw is that it's violating thread safety by using mutable public class level ...
6
votes
3answers
16k views

Insert a character into a string

For practicing reasons I would like to write a method which inserts a character into a string. I would like to know: What is the best practice concerning placement of a comment within methods? For ...
6
votes
1answer
122 views

Allow changing the properties of a mutable controller in a thread safe way

I have a (control engineering) controller. These controllers usually need several parameters to do their thing, and in my application it is desirable that these parameters can be changed while the ...
5
votes
1answer
801 views

How is my implementation of an immutable stack?

Below is my implementation of an immutable stack class. The reverse function is trying to return a stack with all elements reversed. Is my implementation good? Maybe the reverse function can be ...
4
votes
1answer
526 views

Functional linked list

I'm looking for feedback in general: code correctness, best practices, design patterns; everything you think about this. Is it bad code? Where can it be improved? I've been implementing functional ...
1
vote
1answer
108 views

Removing redundancy from an immutable “rules class”

I am writing a board game program in Java. Slightly similar to chess or civilization in that each player has a set of units, and each unit has certain actions that it can take. The base ...
2
votes
1answer
445 views

Creating Proxy classes for immutable objects

As a bit of a learning project, I decided to take the concept of proxying objects a bit further and extend it to creating proxy classes which create proxy'd objects. I originally found the idea of ...
5
votes
1answer
491 views

Immutable C++ stack - thoughts and performance

What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference ...
1
vote
2answers
178 views

Modify or not modify your objects when creating computing functions?

See the examples below: ...
6
votes
1answer
237 views

Circular dependencies between immutable objects; the Freeze Pattern

Generally, I structure small threadsafe immutable objects like this: ...
1
vote
2answers
540 views

Comments on my Java pattern for Mutable turned Immutable objects

Commenting omitted to give you the idea. I've been toying with this recently as a variant of the Builder pattern. I've recently fallen in love with immutable objects for the benefits they give in ...
1
vote
2answers
550 views
3
votes
2answers
741 views

Immutable pure data classes with public setters on properties

I'm putting together some classes as a model for some information (that I'm currently pulling from a website). The classes are implemented in C# - because in the current version of F# there are no ...