[squeak-dev] Morphs and Data Question

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Sun Oct 25 17:04:49 UTC 2020


Hi Eric,


for general "reacting to changes", you could an observer pattern. I think this answer from StackOverflow explains it quite well: https://stackoverflow.com/a/17083241/13994294 For example in Squeak, you could take a look at the Pluggable morph implementations in the system categories Morphic-Pluggable Widgets as well as ToolBuilder-Morphic. For instance, in PluggableButtonMorph, you can see that the communication between morph and model is realized by defining selectors on the morph that will be performed to get necessary data and that can be signaled using the observer pattern to update the visual representation. See PluggableButtonMorph >> #update:.


Apart from that, you could also take a look at the "Object Events" pattern in Squeak, see Object >> #when:send:to: + overloads and senders. Personally, I prefer the "normal" observer pattern the most time because it feels less like coupling the morph and the model too strong to each other, and it gives you greater flexibility without necessarily defining one selector per event type on the morph class.


(Last but not least, it would be a possibility to store closures that were generated by the morph in the model and to evaluate them on every change. However, this is usually an anti-pattern because it creates a very strong coupling between the morph and the model, so I would not really recommend using this approach ...)


To learn more about the underlying design patterns, you could look up in the encyclopedia of your choice the terms "Observer pattern", "MVC", and "MVVM". I hope that helps, and if you have further questions, please don't hesitate to ask them. :-)


Best,

Christoph

<http://www.hpi.de/>
________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Eric Gade <eric.gade at gmail.com>
Gesendet: Sonntag, 25. Oktober 2020 15:44:12
An: The general-purpose Squeak developers list
Betreff: [squeak-dev] Morphs and Data Question

Hi all,

I have a quick question that is perhaps very elementary. What is the best way to design my Morph subclasses so that they "react" to changes on their models? For example, if I have some data related model with text that updates and I want the "view" (the Morph) to update whenever this occurs? In my own quick code I've always just implemented a `step` method that checks for data on the model updates, but is that too brutal and inefficient?

Thanks,

--
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20201025/a0ea9542/attachment.html>


More information about the Squeak-dev mailing list