The subject of immutability was raised in JENA-1391 
(https://issues.apache.org/jira/browse/JENA-1391).

Specifically, the `getUnionModel` method in Jena 3.4 returns an immutable model 
view, and the implementation of the aforementioned story includes methods that 
will return an immutable dataset view.

The question is whether these immutable views deserve their own interfaces. 
Currently, the views are returned using what I called "unexpected immutability" 
because they implement mutable interfaces. This introduces the potential for 
`UnsupportedOperationException`s.

Unfortunately, that (degenerate) pattern is used in Java's `Collections` 
utility as well 
(https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html) but 
Scala is a clean example to draw inspiration from: by implementing immutable 
interfaces as parents to their mutable counterparts (rather than vice verse) we 
can satisfy the Liskov Substitution Principle.

Obviously, implementing that solution is easier to do from scratch than in an 
existing code base; but I imagine it could be done in multiple phases, by 
introducing the new interfaces and using them in new methods (with easy 
conversion to mutability via union) while gradually retrofitting older methods.

The question then, is whether such a change is worthwhile...

Reply via email to