Board index » delphi » Model-Gui-Mediator (MGM) pattern

Model-Gui-Mediator (MGM) pattern


2005-08-23 02:53:21 PM
delphi128
Hi,
Has anybody here used the MGM pattern? It is a variation of the MVC &
MVP.
It is a quick and easy way of making standard gui controls object-aware
using the Mediator and Observer pattern.
I have implemented all my most used edit controls: TEdit, TSpinEdit,
TComboBox and TTrackBar.
I also created a Factory Method that can create and link a gui control
to a Business Object property in a single line of code. I am currently
starting on the list controls (TListView, TTreeview) and wondered if
anybody else has done this before, and could give some pointers or
donate some sample code.
All my projects are cross platform (client requirement) and the MGM
pattern is working wonders in this regards.
For more information on the MGM pattern, visit Andy Bulka's website.
www.atug.com/andypatterns/mgm.htm
Regards,
- Graeme -
 
 

Re:Model-Gui-Mediator (MGM) pattern

[ ...seems my first post didn't go through via Google Groups... ]
Hi,
Has anybody here used the MGM pattern? It is a variation of the MVC &
MVP.
It is a quick and easy way of making standard gui controls object-aware
using the Mediator and Observer pattern.
I have implemented all my most used edit controls: TEdit, TSpinEdit,
TComboBox and TTrackBar.
I also created a Factory Method that can create and link a gui control
to a Business Object property in a single line of code. I am currently
starting on the list controls (TListView, TTreeview) and wondered if
anybody else has done this before, and could give some pointers or
donate some sample code.
All my projects are cross platform (client requirement) and the MGM
pattern is working wonders in this regards.
For more information on the MGM pattern, visit Andy Bulka's website.
www.atug.com/andypatter ns/mgm.htm
Regards,
- Graeme -
 

Re:Model-Gui-Mediator (MGM) pattern

Graeme Geldenhuys writes:
Quote
For more information on the MGM pattern, visit Andy Bulka's website.
www.atug.com/andypatter ns/mgm.htm
Thansk for the link. Here's a corrected link...
www.atug.com/andypatterns/mgm.htm
--
Carl
 

Re:Model-Gui-Mediator (MGM) pattern

I only skimmed quickly, but is this basically what .net databinding does?
 

Re:Model-Gui-Mediator (MGM) pattern

Oops, slip of the finger... Thanks Carl.
G.
Quote
Thansk for the link. Here's a corrected link...

www.atug.com/andypatterns/mgm.htm

 

Re:Model-Gui-Mediator (MGM) pattern

No idea Peter. I have never done any .net development work. I will have
a look though, maybe, I can get some implementation tips.
G.
Peter Morris [Droopy eyes software] writes:
Quote
I only skimmed quickly, but is this basically what .net databinding does?
 

Re:Model-Gui-Mediator (MGM) pattern

Hoi Graeme
Take a look here:
delphi.wikicities.com/wiki/Delphi_Newsgroups
 

Re:Model-Gui-Mediator (MGM) pattern

"Graeme Geldenhuys" <XXXX@XXXXX.COM>a écrit dans le message de news:
XXXX@XXXXX.COM...
Quote
[ ...seems my first post didn't go through via Google Groups... ]
Don't post through anything but the Borland servers; other servers are just
reflectors and Borland's groups are not just usenet groups, so you can't
guarantee that your posts will be forwarded to the Borland server.
Quote
Has anybody here used the MGM pattern? It is a variation of the MVC &
MVP.
It is a quick and easy way of making standard gui controls object-aware
using the Mediator and Observer pattern.
This approach is exactly how I link standard GUI controls to MVP, it is not
a variation, it is an essential part of MVP IMO :-)
Quote
I also created a Factory Method that can create and link a gui control
to a Business Object property in a single line of code. I am currently
starting on the list controls (TListView, TTreeview) and wondered if
anybody else has done this before, and could give some pointers or
donate some sample code.
I have a base MVPForm class that creates a list of "mediator" views and it
is this list that the Presenter iterates to link Values to their appropriate
Views.
Quote
All my projects are cross platform (client requirement) and the MGM
pattern is working wonders in this regards.
Terrific news, you really have got the hang of this OO stuff :-))
Joanna
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
 

Re:Model-Gui-Mediator (MGM) pattern

Quote
This approach is exactly how I link standard GUI controls to MVP, it is not
a variation, it is an essential part of MVP IMO :-)

How does everyone else make there standard GUI controls Object-Aware? I prefer not to create new custom controls from standard ones (placed on the pallette bar), and rather use the Adapter/Mediator pattern to add Observer support to the standard GUI controls.
eg:
TListBoxMediator = class(TtiObject)
<...snip...>
public
constructor CreateCustom(
pObjectList: TtiObjectList; pListBox: TListBox);
procedure Update(pSubject: TtiObject); override;
<...snip...>
end;
The TListBoxMediator is the actual Observer and passes changes on the the TListBox associated.
Joanna, I saw in your MVP articles, you created new controls that inherit from the standard control, plus the IObserver interface. You then had to create the components in code (well the example source does it that way). Is this how you always do it? That means, you can not use the GUI designer of Delphi?
Regards,
- Graeme -
 

Re:Model-Gui-Mediator (MGM) pattern

"Graeme Geldenhuys" <XXXX@XXXXX.COM>a écrit dans le message de news:
43141ab4$XXXX@XXXXX.COM...
Quote
I prefer not to create new custom controls from standard ones (placed on
the
pallette bar), and rather use the Adapter/Mediator pattern to add Observer
support to the standard GUI controls.
This is an excellent method to enable you to use standard controls with MVP.
Quote
eg:
TListBoxMediator = class(TtiObject)
<...snip...>
public
constructor CreateCustom(
pObjectList: TtiObjectList; pListBox: TListBox);
procedure Update(pSubject: TtiObject); override;
<...snip...>
end;
The difference between this approach and mine is that I use a Presenter that
is responsible for linking the control to its "value object" and for
maintaining an Interactor to respond to the events of the mediator
"control".
Quote
Joanna, I saw in your MVP articles, you created new controls that inherit
from
the standard control, plus the IObserver interface. You then had to create
the
components in code (well the example source does it that way). Is this
how
you always do it? That means, you can not use the GUI designer of Delphi?
That article was an early example of MVP and used some very basic techniques
to demonstrate the separation between GUI and BOs. I now use the RAD
designers in Delphi to place standard controls on an MVPForm and then use
the constructor of that form class to create and link up the mediators to
their respective controls.
Joanna
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker
 

Re:Model-Gui-Mediator (MGM) pattern

This is a very interesting concept. However, this is easily acheivable
by considering TDataset as the Mediator class in VCL. This is how we
have gone ahead with our framwork and developed a huge application with
very minimal issues.
The Model:
----------
There is a TDomainObject which abstracts all the basic methods related
to CRUD. Every derived class introduces a set of published properties
and all the business validations. Relations to modules are done as
either a Collection (one to many) or as a Subset (one to one). This is
the core of the system. Simple and straight-forward. This becomes our Model.
The Mediator:
-------------
Then we use Objec Dataset and Collection data set to identify these
objects as dataset.
The GUI
-------
Well any data aware controls from any vendor.
Works simply great and we are able to use the models independently of
the user interface.
Graeme Geldenhuys writes:
Quote
[ ...seems my first post didn't go through via Google Groups... ]

Hi,

Has anybody here used the MGM pattern? It is a variation of the MVC &
MVP.
It is a quick and easy way of making standard gui controls object-aware
using the Mediator and Observer pattern.

I have implemented all my most used edit controls: TEdit, TSpinEdit,
TComboBox and TTrackBar.

I also created a Factory Method that can create and link a gui control
to a Business Object property in a single line of code. I am currently
starting on the list controls (TListView, TTreeview) and wondered if
anybody else has done this before, and could give some pointers or
donate some sample code.

All my projects are cross platform (client requirement) and the MGM
pattern is working wonders in this regards.

For more information on the MGM pattern, visit Andy Bulka's website.
www.atug.com/andypatter ns/mgm.htm

Regards,
- Graeme -
 

Re:Model-Gui-Mediator (MGM) pattern

"Jeeves" <XXXX@XXXXX.COM>a écrit dans le message de news:
XXXX@XXXXX.COM...
Quote
This is a very interesting concept. However, this is easily acheivable
by considering TDataset as the Mediator class in VCL. This is how we
have gone ahead with our framwork and developed a huge application with
very minimal issues.

The Model:
----------
There is a TDomainObject which abstracts all the basic methods related
to CRUD. Every derived class introduces a set of published properties
and all the business validations. Relations to modules are done as
either a Collection (one to many) or as a Subset (one to one). This is
the core of the system. Simple and straight-forward. This becomes our
Model.
This seems Ok as long as the TDomainObject is separated from the actual
database.
Quote
The Mediator:
-------------
Then we use Objec Dataset and Collection data set to identify these
objects as dataset.

The GUI
-------
Well any data aware controls from any vendor.

Works simply great and we are able to use the models independently of
the user interface.
In theory, using TDataset derivatives that supply objects are a good idea
but, unlike Wayne, I still can not get on with the idea.
The problems I have include the concept that a TDataset is just that: a set
of data, not a single object. When it comes to displaying a form that
represents a single object, you really don't need a class that has methods
like Next and Eof :-) OTOH, it is a relatively good match for a mechanism to
supply the data for a list or grid UI element. There are just too many
extraneous properties, methods and events in TDataset to convince me that it
is a suitable class for a UI mediator.
It would not be too much hassle however to create a mediator class that can
sit between a property of an object and a non-data-aware UI element. You
might even try doing the same thing for d-a controls ??? Although this is
where .NET really shines as their d-a controls will just as easily link to
properties of objects as they will to fields of tables.
Joanna
Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker