Let's say i have Bird class and BirdMorph class. Birds have a position, and i want BirdMorphs to change their position on the screen, whenever the corresponding bird changes it's position.
What is the intended way to connect a Morph to the Object it is supposed to visualize in Morphic?
Typically a BirdMorph would hold a Bird in an instance variable, and update its own position in its
step
method.Think of it this way: Every object needs to be "held" somewhere. If there is no reference to it, it gets garbage-collected automatically. In Morphic, that reference is normally rooted in the
World
, every morph is referenced via its container'ssubmorphs
collection.So it makes sense then that your morph holds onto the "domain model". E.g. you might have an object BirdSimulation which holds all the Birds, and a window on screen holding onto the BirdSimulation. Then when you close the window, the simulation objects will be gone, too.
If your program is mainly visual you might not even need a separate Bird class. Instead, the morph could just be "a bird". That can simplify the design considerably.