Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-09

IFPObserved

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Xiangrong Fang

Hi All,

Where can I find detailed documentation on IFPObserved? This page only defines the interface but not telling about the purpose of this interface:

http://www.freepascal.org/docs-html/rtl/classes/ifpobserved.html

My questions are:

- what is this interface for?
- any example on when and why to use it?
- Where can I find documentation that contains explanation on the above 2 questions, so that I can get a "big picture"? For example, if there are any similar interfaces that form the foundation of FCL or LCL?

thanks!

Michael Van Canneyt
to Xiangrong Fang
Xiangrong Fang wrote 9 lines
Hi All, Where can I find detailed documentation on IFPObserved?  This page only defines the interface but not telling about the purpose of this interface: http://www.freepascal.org/docs-html/rtl/classes/ifpobserved.html My questions are: - what is this interface for?

There are 2 interfaces: IFPObserved and IFPObserver. Together they form the observer pattern that can be used to implement the mediator pattern.

Basically, if an object wants to notify other observers that it 'has changed', it implements the IFPObserved interface. Since TStrings is a prime candidate for this, IFPObserved has been implemented in TPersistent. This means that any component can act as an observed object. It is up to the component implementation to decide which changes must be communicated.

An object that wishes to be notified by other objects that they have changed, implements the IFPObserver pattern. It must implement 1 method which will get called whenever an object that it is observing, changes.

Both interfaces are CORBA interfaces, so they do not have the burden of reference counting.

- any example on when and why to use it?

The fpobserver.pp unit contains an implementation of a mediator and a mediator registry.

This could be used for example to implement the Live Bindings of Embarcadero in a rather trivial manner.

- Where can I find documentation that contains explanation on the above 2 questions, so that I can get a "big picture"? For example, if there are any similar interfaces that form the foundation of FCL or LCL? 

I have a complete CD-Cover design program somewhere, which is written with this technology; I also have somewhere some articles that discuss the design, I will see about publishing them on-line somewhere ASAP. I can send you a copy if you want.

Michael.

Xiangrong Fang
to Michael Van Canneyt

Hi Michael,

Thanks a lot for the explanation. I am not familiar with a few concepts in your description, such as:

1) What are "CORBA" style interfaces? I know CORBA and DCOM are for distributed or remote object call. Are they still significant in local object system?

2) Why an interface has "reference count"?

3) What are "Live Binding"? What's the difference between "IFPObserved" and the component events like OnCreate, OnShow, OnClick...?

4) You mentioned "implement the Live Bindings of Embarcadero in a rather trivial manner", does that mean IFPObserved is a FPC/Lazarus feature which is not compatible with Delphi?

5) I am very interested in your CD-Cover designer. please send me the article and code.

Thank you!

2013/9/11 Michael Van Canneyt

Show quoted text 61 lines
On Wed, 11 Sep 2013, Xiangrong Fang wrote: Hi All, > > Where can I find detailed documentation on IFPObserved? This page only > defines the interface but not telling about the purpose of this interface: > > http://www.freepascal.org/**docs-html/rtl/classes/**ifpobserved.html<http://www.freepascal.org/docs-html/rtl/classes/ifpobserved.html> > > My questions are: > > - what is this interface for? > There are 2 interfaces: IFPObserved and IFPObserver. Together they form the observer pattern that can be used to implement the mediator pattern. Basically, if an object wants to notify other observers that it 'has changed', it implements the IFPObserved interface. Since TStrings is a prime candidate for this, IFPObserved has been implemented in TPersistent. This means that any component can act as an observed object. It is up to the component implementation to decide which changes must be communicated. An object that wishes to be notified by other objects that they have changed, implements the IFPObserver pattern. It must implement 1 method which will get called whenever an object that it is observing, changes. Both interfaces are CORBA interfaces, so they do not have the burden of reference counting. - any example on when and why to use it? > The fpobserver.pp unit contains an implementation of a mediator and a mediator registry. This could be used for example to implement the Live Bindings of Embarcadero in a rather trivial manner. - Where can I find documentation that contains explanation on the above 2 > questions, so that I can get a "big picture"? For example, if there are any > similar interfaces that form the foundation of FCL or LCL? > I have a complete CD-Cover design program somewhere, which is written with this technology; I also have somewhere some articles that discuss the design, I will see about publishing them on-line somewhere ASAP. I can send you a copy if you want. Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Michael Van Canneyt
to Xiangrong Fang
Xiangrong Fang wrote 5 lines
Hi Michael, Thanks a lot for the explanation.   I am not familiar with a few concepts in your description, such as: 1) What are "CORBA" style interfaces?  I know CORBA and DCOM are for distributed or remote object call.  Are they still significant in local object system?

CORBA is centered around the concept of interfaces. So is COM.

in COM, where Delphi got the concept of Interfaces, interfaces are reference counted.

FPC wished to introduce interfaces that do not have the overhead associated with reference counted. So we decided to name them 'CORBA' interfaces.
So CORBA interfaces are simply interfaces that are not reference counted. The name is by and large coincidental.

2) Why an interface has "reference count"?

Because COM makes it so.

3) What are "Live Binding"?  What's the difference between "IFPObserved" and the component events like OnCreate, OnShow, OnClick...?

See IFPObserved as a general event mechanism.

The main difference is that a component can have only 1 OnCreate handler. whereas, in theory, an unlimited number of observers can observe one object.

4) You mentioned "implement the Live Bindings of Embarcadero in a rather trivial manner", does that mean IFPObserved is a FPC/Lazarus feature which is not compatible with Delphi?

It is not compatible on purpose, for 2 reasons:

1. It was designed long before Live Bindings existed.

2. The Live Bindings are simply horribly designed, I have no wish to introduce this mess in FPC.

5) I am very interested in your CD-Cover designer. please send me the article and code.

I will do so later today.

Michael.

Xiangrong Fang
to Michael Van Canneyt

Hi Michael,

3) What are "Live Binding"? What's the difference between "IFPObserved"

> and the component events like OnCreate, OnShow, OnClick...? > See IFPObserved as a general event mechanism.
The main difference is that a component can have only 1 OnCreate handler. whereas, in theory, an unlimited number of observers can observe one object.

OK, then who defines "changed"? i.e. if I hook an event handler by using a TComponent's FPOAttachObserver method, WHEN will my code gets called?

Thanks.

Michael Van Canneyt
to Xiangrong Fang
Xiangrong Fang wrote 13 lines
Hi Michael, 3) What are "Live Binding"?  What's the difference between "IFPObserved" and the component events like OnCreate, OnShow, OnClick...? See IFPObserved as a general event mechanism.    The main difference is that a component can have only 1 OnCreate handler. whereas, in theory, an unlimited number of observers can observe one object. OK, then who defines "changed"?  i.e. if I hook an event handler by using a TComponent's FPOAttachObserver method, WHEN will my code gets called?

That depends entirely on the implementation of the component and needs to be documented. The implementor of the component needs to decide when to call this.

For instance, for TStrings, this is called whenever the list changes

For TList, this is called when items are added/deleted etc.

Michael.

Graeme Geldenhuys
to Xiangrong Fang: Where can I find detailed documentation on IFPObserved? This page only defines the…
Xiangrong Fang wrote
Where can I find detailed documentation on IFPObserved?

It forms part of the Observer design pattern. The Observer design pattern works the same, irrespective of which language was used to implement it. So any Observer design pattern documentation should suffice. Google is your friend... here are the first two links I found:

http://www.oodesign.com/observer-pattern.html
http://en.wikipedia.org/wiki/Observer_pattern

- any example on when and why to use it?

I use the Observer design pattern in part, when I implemented the compound Model-GUI-Mediator design pattern. Model-GUI-Mediator allowed me to make any standard GUI component "object-aware", without needing any descendant components like the DB-aware ones. The Observer design pattern is used to syncronise in both directions, any data changes between a GUI component and the Business Object.

I have written some articles on design patterns - strangely no article on the Observer, but that is probably because it is such a simple [easy] design pattern.

http://opensoft.homeip.net/articles/

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/