I would discuss about a small geometry implementation:
Consider having all basic classes like Point, Dimension, Rectangle, Circle.
By example, you will find on a Circle a method like :
public Point getCenter();
What would be your options ?:
- Having “Point” immutable that let you the liberty to return the Point from the Circle object without any risk that somebody change it.
- Having “Point” mutable that you must enforce in a some way any modifications (like with listeners). But even if you are able to intercept changes, theses changes may corrupt some objects states. (exemple changing corners of a rectangle that do not give a rectangle anymore).
At this time, my own geometry approche it to use immutable object for all objects. But it’s not the best approche for reduce objects allocations. Each time i want to translate, rotate, … a geometry objects, i must instanciate a new one…
The mutable approches is fine when you perform an animation and translate a series of geometry objects each update() or render() depending of what you do.
Sébastien.