Say I am defining a class called Point which describes a point in 3D space. The class has a coordinate property which is a 3 entry vector ([x, y, z]) and also a separate property for each component of the coordinate (Point.X, Point.Y, and Point.Z).
A point object is always instantiated using a coordinate vector but, once instantiated, I would like the user to be able to update the value of either the coordinate vector OR the individual component values and have the two stay consistent with each other, in other words:
If the user changes the coordinate vector:
Point.coord = [newX, newY, newZ]
The X, Y and Z properties should be updated to newX, newY and newZ respectively
OR, if the user updates one of the X, Y or Z properties:
Point.X = newerX;
Point.Y = newerY;
Point.Z = newerZ;
The coord property should be updated to [newerX, newerY, newerZ]
What is the preffered way to implement this? Is it even possible at all?
My first thought was to just update the coordinate vector in the set.X, set.Y and set.Z methods and vice versa but I'm guessing this will cause some sort of infinite loop and Matlab complains saying you shouldn't set the values of properties inside the set method of another property. I know that one way dependence is easy to define using dependent properties but for this 2 way dependence I am stumped.