phetsims / equality-explorer

"Equality Explorer" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
2 stars 3 forks source link

Class hierachy improvements #198

Closed pixelzoom closed 2 years ago

pixelzoom commented 2 years ago

The class hierachy for variables, terms, and term creators could stand to be improved. It's a little confusing, and lacks some symmetry.

Current implementation:

// model

Variable
  ObjectVarable (has an artificial symbol, not shown in the UI)

Term
  ConstantTerm
  VariableTerm
      ObjectTerm

TermCreator
  ConstantTermCreator
  ObjectTermCreator
  VariableTermCreator

// view

TermNode
  ConstantTermNode
  ObjectTermNode
  VariableTermNode

TermCreatorNode (overloaded to handle all TermCreator types)

VariableValuesNode (overloaded to handle both Variable and ObjectVariable)

VariableNode (overloaded to handle both Variable and ObjectVariable)

Instead, we should differentiate between "symbolic variables" (which have a symbol, like 'x') and "object variables" (which are represented by an image, like turtle.png).

So perhaps something like this:

// model

Variable
  ObjectVariable
  SymbolicVariable

Term
  ConstantTerm
  VariableTerm
    ObjectTerm( variable: ObjectVariable )
    SymbolicTerm( variable: SymbolicVariable )

TermCreator
  ConstantTermCreator
  ObjectTermCreator
  SymbolicTermCreator

// view

TermNode
  ConstantTermNode
  ObjectTermNode
  SymbolicTermNode

TermCreatorNode (overloaded to handle all TermCreator types)

VariableValuesNode  (overloaded to handle both ObjectVariable and SymbolicVariable)

ObjectVariableNode( variable: ObjectVariable )
SymbolicVariableNode( variable: SymolicVariable )

This would be a big change, so I may ultimately punt. But it's worth investigating.

pixelzoom commented 2 years ago

I've taken multiple passes at this, spent a good 2 hours on it, and it's just too difficult and destabilizing. So punting, and closing.