On 2014-06-08, 2:44 AM, Neil wrote:
Benoit Jacob wrote:

Strawman class diagram:

     Transformation
     /      |      \
    /       |       \
   /        |        \
  /         |         \
Identity   Matrix    Other transform types
                      e.g. Translation


In such a world, the class containing the word "Matrix" in its name
would not have a isIdentity() method; and for use cases where having a
"variant type" that can avoid being a full blown matrix is meaningful,
we would have such a variant type, like "Transformation" in the above
diagram, and the isIdentity() method there would be merely asking the
variant type for its type field.

I think roc suggested the possibility of something similar i.e.

        Transformation
        /      |      \
       /       |       \
      /        |        \
     /         |         \
Identity   2DMatrix   3DMatrix

Then from JS you would just write (matrix instanceof Identity). I don't
know whether this would make the implementation unduly complex though.

I worked a good deal on Sage [1], a general algebra computation platform, and one lesson we learned again and again is that baking mathematical properties into the type hierarchy directly caused more problems than it solved. I'd like to avoid properties encoded as instance types if we possibly can. (Exposing isIdentity as an internal instanceof is fine.)

Nick

[1] http://sagemath.org/


_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to