[fpc-devel] Interface delegation fix: backport to FPC 2.4.2 ...?
Graeme Geldenhuys
graemeg.lists at gmail.com
Thu May 20 22:09:48 CEST 2010
On 20 May 2010 17:40, Dimitri Smits wrote:
> one of the first rules when using GoF book/patterns is:
> use them wisely/appropriately.
Which is what we want to do.
> that said, I've encountered many design pattern noobs who made it a fetish
Neither Michael or myself are new to design patterns. I for one have
used them for about 10 years already.
> but yet at other times unneeded.
When it's not needed, you simply do nothing (nothing observing
something else) and it will be as if Observer functionality is not
there - just like it is now.
> ventsystem? (ISO single event handlers)
We are *not* touching the event handler system. Observer is a separate
functionality and more versatile and intelligent than OnXXX events,
which much less effort.
> Why it has to be on TPersistent is beyond me.
Because many of the classes we want to observe descend from
TPersistent. So it make sense to put the basic workings of Observer
there, and then descendant components will decided what must trigger
notifications.
Also we couldn't implement Observer earlier in FPC because FPC did not
have the required features to do it. Now that Interface Delegation
works for Corba-style interfaces, we can move to the next step.
> And either way, you definately need a clean separation of concerns.
The bulk of the Observer pattern is implemented in a separate class,
we than bolt that onto TPersistent via interface delegation.
TPersistent will then implement the IObserverable (or whatever it will
be called) interface. And not we are talking about Corba-style
interface, so there is NO reference counting to worry about.
> When your event occurs, you still need to call fireOpen() or fireClose() to notify
Yes, descendant classes of TPersistent will decide when notifications
occur. In that even notification it will pass a reference of itself
and an enum type which will give a clue as to what changed. eg:
TStringList could no notification when a item text change, a new item
was added or when a item was deleted.
> Either way, you still need to (somehow) link back. Does your observer know it gets
Nothing will automatically observer something else. That's up to the
developer to decide what they want to observer. We simply want to put
the Observer functionality in place.
> while I 100% agree with you on the crappyness of Delphi Ocho, I must say that it was a .Net only release!
Yes, and later it was moved to Win32 Delphi where it is still crappy.
--
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
More information about the fpc-devel
mailing list