You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: doc/phet-software-design-patterns.md
+14-11
Original file line number
Diff line number
Diff line change
@@ -488,7 +488,7 @@ MyTrait.mixInto( MyClass );
488
488
489
489
## Model-View-Controller (MVC)
490
490
491
-
Author: 🚧 @jessegreenberg 🚧
491
+
Author: @jessegreenberg
492
492
493
493
Model-View-Controller is a software pattern for applications where the developer separates the implementation into three
494
494
distinct categories. Model code is responsible for the application data and logic. View code is responsible for the
@@ -525,24 +525,27 @@ applied to create a simulation screen by a class called Screen.js, which may be
525
525
In this example you can see that MyModel is oblivious to the view, while the view has a reference to the model to inform
526
526
the representation.
527
527
528
+
Controller code at PhET is generally in input and event handling which is done through `Node.addInputListener`.
528
529
Communication from the model to the view is facilitated by classes in axon such as Property and Emitter.
529
530
These are Observables which contain model state information and broadcast changes to the view so that it can update
530
531
accordingly.
531
532
532
-
Model-View separation can also be found at other tiers of PhET's implementation. Scenery (which
533
-
is used extensively in simulation view code) is implemented with model-view separation as well. For example,
534
-
a scenery Node acts as a model which is responsible for state information such as visibility, transformation, bounds
535
-
and other things. Meanwhile, other view code in scenery is responsible for rendering this state information for the
536
-
user.
537
-
538
-
**Questions:**
539
-
Does PhET actually use Model-View-**Controller**? I don't think of separated "controller" code. If I were to
540
-
draw a diagram of PhET's model-view separation it would be:
533
+
The "Model" in this pattern doesn't need to be the "domain" model for a simulation. It can contain any logic
534
+
for application behavior for any context. Model-View separation can be found at other tiers of PhET's
535
+
implementation. Scenery (which is used extensively in simulation view code) is implemented with model-view separation.
536
+
For example, a scenery Node acts as a model which is responsible for state information such as visibility,
537
+
transformation, bounds and other things. Meanwhile, other view code in scenery is responsible for rendering this state
538
+
information for the user. You will find "model-view" separation in the [sun](github.com/phetsims/sun) button
539
+
implementation as well.
540
+
541
+
There are several variations on the Model-View-Controller pattern. Please see [this article for more information](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller).
542
+
PhET's usage is most similar to the Model-View-Delegate pattern used by Java in the implementation of Swing. In this
543
+
pattern, the controller code is generally packaged with view code. A diagram of this pattern would look like
0 commit comments