On Tue, 24 Feb 2015, Jonas Maebe wrote:


On 24 Feb 2015, at 16:41, Bee wrote:

This is an interesting article about interface and multiple inheritance in
Java.

http://blog.cleancoder.com/uncle-bob/2015/01/08/InterfaceConsideredHarmful.html

I wonder, how modern Pascal (FreePascal in particular) answer the
questions. :)

Couldn't he solve it by using a generic class to "implement" register and notify, so he doesn't have to manually duplicate the code?

Exactly. Interface delegation solves this problem, that is why it was invented.

Something like

Property MyObserved : IFPObserved read FmyObserved Implements IFPObserved;

I have implemented this delegated object in the fpobserver unit (TObservedHook 
class).

Note that the whole "separation of concerns" argument is IMO nonsense.

The widget needs to know it CAN be observed. It needs to know that at some points, it needs to notify possible observers.
You cannot avoid that, not with interfaces, not with multiple inheritance;
This code will be present in either version of the widget.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to