<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE>@font-face {
        font-family: SimSun;
}
@font-face {
        font-family: @SimSun;
}
@page Section1 {size: 612.0pt 792.0pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; }
P.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Times New Roman"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: Arial; mso-style-type: personal-compose
}
DIV.Section1 {
        page: Section1
}
</STYLE>
</HEAD>
<BODY lang=EN-US vLink=purple link=blue bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Well you said you wanted feedback, so I hope this
isn't too picky.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>1) I find the inconsistent use of variable prefixes
a bit annoying. I tend to stick with</FONT></DIV>
<DIV><FONT face=Arial size=2>F- class field</FONT></DIV>
<DIV><FONT face=Arial size=2>A - method parameter</FONT></DIV>
<DIV><FONT face=Arial size=2>P - pointer</FONT></DIV>
<DIV><FONT face=Arial size=2>and no prefixes for class properties or local
variables.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>2) TListenerItem.FListener is redundant, since
the information it contains is already held in
TListenerItem.FBindMethod</FONT></DIV>
<DIV><FONT face=Arial size=2>It could have been implemented as a function, but I
don't see why it is needed.</FONT></DIV>
<DIV><FONT face=Arial size=2>As usual, redundancy leads to complication
elsewhere</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>eg. if
(MethodEquals(TMethod(Items[i].FBindMethod) ,TMethod(ABinder))) and
(Items[i].FListener = AListener) then</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>the second condition is
automatically satisfied by the first condition.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>3) Why define a TNotifier class when all its
methods are static? They could be defined as simple procedures/functions in the
unit.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>4) I'm not keen on the idea of passing a string
parameter to identify the message type, for the simple reason that spelling
mistakes can arise and you're never really sure at compile time what
"messages" are being broadcast/handled. This problem can of course be
ameliorated through the use of constants, but I prefer the use of an enumerated
type.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Having said all that. I like the loose coupling of
your solution. I have implemented the observer pattern previously with the lists
maintained internally by the objects involved, so removing the need to inherit
from a particular class is a great improvement. I hadn't considered that option
before. Of course you do pay a miniscule performance penalty in having to find
the correct list for the object. Perhaps the use of THashedstringlist could
mitigate this further.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Todd.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=kyley@harrissoftware.com href="mailto:kyley@harrissoftware.com">Kyley
Harris</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=delphi@ns3.123.co.nz
href="mailto:delphi@ns3.123.co.nz">NZ Borland Developers Group - Delphi
List</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Wednesday, May 10, 2006 3:36
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [DUG] Discussion &
Donation</DIV>
<DIV><BR></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">In an attempt to create some more
interesting discussion, other than talking about the crud IDE issues, I am
donating some useful code for discussion, rather than for help. Feel free to
keep/use the code if you want to. Be mean if you feel the need (but if your
personal then watch out ;) Hopefully this may introduce a discussion where
people learn something, or are able to contribute some interesting
ideas/information about the topic (which is object notification and
observation).<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p> </o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">In the attached zip is a sample
application showing a basic, but horrible use of the class in uNotifier.pas.
TNotifer is a class I wrote a long while back which loosely follows an
observer pattern for allowing one-to-many observations between an object, and
a bunch of interested object. <o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p> </o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The main difference this class has
between many observer patterns is that you do not have to modify existing
classes, or sub-class anything, or instantiate anything in your existing
objects. The TNotifier handles all the bindings, you just need to implement
one listening event on each listening object.<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p> </o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">The sample app is a corny app that
makes child forms (button click) update a memo based on changes to the memo on
the main form. God help me if I ever did anything as potentially unthread safe
as that in a real app.<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"><o:p> </o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: Arial">Fun fun fun…. (I hope the app
compiles. You never know with these tricky little sample
apps)<o:p></o:p></SPAN></FONT></P></DIV>
<P>
<HR>
<P></P>_______________________________________________<BR>Delphi mailing
list<BR>Delphi@ns3.123.co.nz<BR>http://ns3.123.co.nz/mailman/listinfo/delphi<BR>
<P>
<HR>
<P></P>Internal Virus Database is out-of-date.<BR>Checked by AVG Free
Edition.<BR>Version: 7.1.385 / Virus Database: 268.5.1/327 - Release Date:
28/04/2006<BR></BLOCKQUOTE></BODY></HTML>