DePauwREU2013 / scales

2 stars 0 forks source link

Decouple Graphic from Subtypes #1

Closed mfansler closed 11 years ago

mfansler commented 11 years ago

Eventually I think we should move toward a refactoring of the entire Graphic type hierarchy.

Strong Coupling BAD

Presently, the Graphic type includes numerous definitions which explicitly reference subtypes of the Graphic class itself, e.g., Over, Beside, Transform, etc.. With such a strong coupling across multiple class files it makes us much more prone to unwittingly introduce changes which break existing functionality. Such functionality may not even be transparent, since distributing the coupling across files can obscure what the interdependencies are.

One Possible Solution

The way the Graphic class is currently designed to behave already implicitly gives every instance the ability to be composed and transformed. This leads me to believe that a Graphic as a type should include a Transform and a ReferencePoint of some sort within it. Moreover, those two types should not be implementations of a Graphic. The Graphic class should be responsible for rendering and will use the Transform and ReferencePoint properties to determine the rendering. Those latter classes should not need to know how to to render themselves, since technically they don't have anything to render - they are merely abstract information which should be equally applicable to any Graphic.

As for Over, Beside, etc, these might be combine into a single Composition type which composes two (or more) Graphic instances generally. The differences between -&, -^, and ||| operations could distinguished internally in the Composition class.

Carrying out a refactoring along these lines would likely break backward compatibility with the previous version of Scales API. Effort could be made to keep it, but, AFAIK, backward compatibility is not one of our goals.

mfansler commented 11 years ago

We did the latter part of this (merging Over, Beside and Above into Composite), and I'm going to close it for now because there are no current plans to make any further changes in this direction.