From: Robert Klemme Date: 2008-05-24T17:50:01+09:00 Subject: Re: Ruby observer module On 23.05.2008 21:30, S2 wrote: > Avdi Grimm wrote: > >> And then it is each step's responsibility to call #changed if and only >> if they actually made a change. If a change was made by one or more >> steps, our observers are notified ONCE at the end. > > Yes, in this case it makes sense, but think of this: > > def do_stuff > @mint = 'blue' > notify_observers > end > > Nice and clean, isn't it? > If I implement something like you sad, wouldn't it make more sense to create > a @changed variable in the Subject class, and call notify_observers only if > @changed == true instead of forcing a call to changed every time? What you describe is exactly what happens if you use #changed and #notify_observers the way they are intended. Look into the implementation of #changed and #notify_observers. And for simple cases nothing stops you from doing something like this: def force_notify changed notify_observers end > Well, it's perfectly fine to me how it is implemented now, it just looks a > bit ugly to me, but maybe it's just me (that call to changed does not > really add anything, and the functionality it provides is trivial (if it is > intended like you explained it)). What's wrong with having a method with trivial implementation? Note, that the method has the added advantage to be overridable and changeable - so you are a lot more flexible. Kind regards robert