Understanding Morphic programming

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Understanding Morphic programming

Alex Schenkman
Hello list:

I've read "Squeak by Example" and looked at some Morphic tutorials and example Morphs.
I still don't understand how to organize my code with Morphic, =(

1) How should I separate the model from the graphical representation?


Object  subclass: #Person
   instanceVariableNames: 'name address email'

Morph sublcass: #PersonMorph
   instanceVariableNames: 'person'

The morph can then show and update the model when changed. 

2) What happens if the model is changed by another class. How does the morph gets notified?


What is the preferred approach?
Thanks in advance!

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Understanding Morphic programming

Igor Stasenko
2009/11/12 Alex Schenkman <[hidden email]>:

> Hello list:
> I've read "Squeak by Example" and looked at some Morphic tutorials and
> example Morphs.
> I still don't understand how to organize my code with Morphic, =(
> 1) How should I separate the model from the graphical representation?
>
> Object  subclass: #Person
>    instanceVariableNames: 'name address email'
> Morph sublcass: #PersonMorph
>    instanceVariableNames: 'person'
> The morph can then show and update the model when changed.
> 2) What happens if the model is changed by another class. How does the morph
> gets notified?
>

The way how you wiring a presenter with model is using dependency.

person addDependant: myMorph.

then in Person class, whenever something is changed, like:

name: aNewName

  name := aNewName.
  self changed: #name  "notify dependants that receiver is changed"

then your morph get notified about such change and could decide to
refresh the displayed data.


There always could be better ways (like using Announcements), but
above one sits there quite a while :)

> What is the preferred approach?
> Thanks in advance!
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project