| View previous topic :: View next topic |
| Author |
Message |
Bart Guest
|
Posted: Tue Dec 06, 2005 11:20 pm Post subject: Who is willing to comment (ValueTye and Mediator) |
|
|
Hi All,
After a lot of googling and reading Joanna's, Iman, and Lee's source code I
have finally (at least I hope) found a solution for my problems.
Now I hope if someone willing to look at my code and comment.
I have posted in the attachment group: TVMediator.zip
Hope to hear,
Bart
|
|
| Back to top |
|
 |
Lee_Nover Guest
|
Posted: Wed Dec 07, 2005 1:03 am Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
| Quote: | Now I hope if someone willing to look at my code and comment.
|
separate Observer and Subject
ideally each class/interface should be in it's own unit (unless they're tightly coupled like _lists of_ some type)
if you do it the way I do then RegisterAttributes should be called from TProperties class (also naming the classes more appropriately wouldn't hurt)
again I'd use a hashed list .. you can use (drop/replace) THashedStringList from IniFiles unit
(I'll replace it with a TStringHash soon - enormous speed boost ! talking about 100x gain)
instead of returning a pointer in RegisterAttribute you should return a class .. TValueType in this case (I'll check why I return a pointer :/)
why does TValueType have two value fields ? fAsBoolean and fAsInteger ? (each ValueType entity should represent only one Value)
create a TBoolean and a TInteger class instead
I'm not using mediators coz I'm keeping the framework as lightweight as possible .. but your code looks ok :)
|
|
| Back to top |
|
 |
Bart Guest
|
Posted: Wed Dec 07, 2005 10:59 am Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
Thanks Lee, you really helped me a lot.
|
|
| Back to top |
|
 |
Bart Guest
|
Posted: Wed Dec 07, 2005 11:04 am Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
Thanks Lee, you really helped me a lot.
|
|
| Back to top |
|
 |
Marcos Guest
|
Posted: Wed Dec 07, 2005 1:35 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
See the post "OPF Questions" above. I talk about infra framework it have
ValueTypeFramework ready!
|
|
| Back to top |
|
 |
Joanna Carter [TeamB] Guest
|
Posted: Wed Dec 07, 2005 1:48 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
"Bart" <@> a écrit dans le message de news:
43961c73$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Now I hope if someone willing to look at my code and comment.
I have posted in the attachment group: TVMediator.zip
|
Sorry to say, but you are mixing all sorts of different techniques and
coming up with a bit of a mess :-(
I will try to answer more fully when I get back home on Friday, but in the
meanwhile :
Contrary to Lee, I would say that keeping two related classes like TObserver
and TSubject in the same unit is fine.
Do not use things like AsInteger and AsBoolean in the same Value Type, there
is absolutely no need for this and it will get even more confusing when you
get to the stage of adding CustomerValueType, OrderValueType, etc...
Take heart though, we all started somewhere and those of us who made the
most mistakes (and corrected them) ended up with the most competent
frameworks. :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
|
|
| Back to top |
|
 |
Bart Guest
|
Posted: Wed Dec 07, 2005 2:33 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
Hi Joanna,
Thanks for responding:
| Quote: | Contrary to Lee, I would say that keeping two related classes like
TObserver
and TSubject in the same unit is fine.
|
I did some cleanup and I have seperated them in two units which I think is
also fine.
| Quote: | Do not use things like AsInteger and AsBoolean in the same Value Type,
there
is absolutely no need for this and it will get even more confusing when
you
get to the stage of adding CustomerValueType, OrderValueType, etc...
|
I have created a class for several valuetypes. They do now have a value
property. As Lee propossed.
| Quote: | Take heart though, we all started somewhere and those of us who made the
most mistakes (and corrected them) ended up with the most competent
frameworks.
|
Please feel free to comment as much as you like. I am so glad that there are
people willing to do because at my company I am the only Delphi programmer
so I cannot discuss my ideas. I just hope that I will come to a clean and
good OO design.
I have posted the latest version to the attachment group: VTMediator2.zip
Hope to hear, Thanks a lot,
Bart
|
|
| Back to top |
|
 |
Iman L Crawford Guest
|
Posted: Wed Dec 07, 2005 3:45 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
"Bart" <-> wrote in news:4396f275$1 (AT) newsgroups (DOT) borland.com:
| Quote: | I have posted the latest version to the attachment group: VTMediator2.zip
|
My only question is why you have your ValueTypes derive from TSubject and
your ControlMediator derive from TObject. What if you want your ValueType
to be an observer? Usually you would want want to use composition or
aggregation. (I think those are the correct terms)
--
Iman
|
|
| Back to top |
|
 |
Lee_Nover Guest
|
Posted: Wed Dec 07, 2005 4:00 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
| Quote: | Sorry to say, but you are mixing all sorts of different techniques andcoming up with a bit of a mess
|
agreed :)
| Quote: | Contrary to Lee, I would say that keeping two related classes like TObserver
and TSubject in the same unit is fine.
|
nothing wrong having a pattern defined and implemented in one class
it's just that I prefer implementations in separate units :)
|
|
| Back to top |
|
 |
Bart Guest
|
Posted: Wed Dec 07, 2005 4:03 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
Hi Iman,
| Quote: | My only question is why you have your ValueTypes derive from TSubject and
your ControlMediator derive from TObject.
|
My model holds the ValueType objects. These objects are the subjects that
are observered by the mediatiors. I am not quite sure which version of my
source you have but my ControlMediator derives from TObserver.
| Quote: | What if you want your ValueType
to be an observer?
|
What should it observe ?
| Quote: | Usually you would want want to use composition or
aggregation. (I think those are the correct terms)
|
Maybe that is also a possiblity but I think (still learning here)
inheritance is ok here.
Bart
|
|
| Back to top |
|
 |
Lee_Nover Guest
|
Posted: Wed Dec 07, 2005 4:10 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
| Quote: | What if you want your ValueType
to be an observer?
What should it observe ?
|
it's attributes check my code again and you'll see (Tdpo2Object)
| Quote: | Usually you would want want to use composition or
aggregation. (I think those are the correct terms)
Maybe that is also a possiblity but I think (still learning here)
inheritance is ok here.
|
since you're using strictly objects then you can't implement both Observer and Subject thru inheritance
either use composition or use interfaces
|
|
| Back to top |
|
 |
Iman L Crawford Guest
|
Posted: Wed Dec 07, 2005 4:32 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
"Bart" <-> wrote in news:4397079d (AT) newsgroups (DOT) borland.com:
| Quote: | My model holds the ValueType objects. These objects are the subjects
that are observered by the mediatiors.
|
I try to have my classes do just one thing. Even when using interfaces, I
would have another class implement the needed functionality. This is just
my opinion, I'm not a expert by any definition.
| Quote: | I am not quite sure which
version of my source you have but my ControlMediator derives from
TObserver.
|
I should have typed TObserver.
| Quote: | What should it observe ?
|
Other classes or valuetypes.
| Quote: | Maybe that is also a possiblity but I think (still learning here)
inheritance is ok here.
|
I'm still learning too. All my suggestions are just that, suggestions.
--
Iman
|
|
| Back to top |
|
 |
Bart Guest
|
Posted: Wed Dec 07, 2005 5:33 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
| Quote: | What if you want your ValueType
to be an observer?
What should it observe ?
it's attributes check my code again and you'll see (Tdpo2Object)
|
I find it rather convenient that my ValueType object is the subject. In this
way I can easy attach my mediator as an observer which on his turn can
update my view. I am trying to implement a MGM here.
Maybe I am understanding it wrong but why should a ValueType object observe
an attribute of an model which holds the list with Valuetype objects himself
?
| Quote: | since you're using strictly objects then you can't implement both Observer
and Subject thru inheritance
either use composition or use interfaces
|
I do understand this
Bart
Bart
|
|
| Back to top |
|
 |
Lee_Nover Guest
|
Posted: Wed Dec 07, 2005 8:36 pm Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
| Quote: | I find it rather convenient that my ValueType object is the subject
|
I have it like that too
in your example TProperties would want to observer it's asstributes
so you'd add a field FObserver: TObserver to your TProperties class and attach an it in the RegisterAttribute method
Procedure TProperties.RegisterAttribute(const aAttribute: TvalueType;
const Name: String);
begin
assert(Name <> '', 'Attribute name cannot be empty');
fAttributes.AddObject(Name, aAttribute);
aAttribute.Attach(fObserver);
end;
you'd create the observer in the constructor and do some wiring like
fObserver.OnUpdate := HandleObserverUpdate;
|
|
| Back to top |
|
 |
Bart Guest
|
Posted: Thu Dec 08, 2005 8:43 am Post subject: Re: Who is willing to comment (ValueTye and Mediator) |
|
|
| Quote: | I have it like that too
in your example TProperties would want to observer it's asstributes
|
And this is the point that I don't understand. It is probably my lag of
experience. What is the use ? Can you try to explain it ot me ?
Bart
|
|
| Back to top |
|
 |
|