BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Object Validation

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Cesar Romero
Guest





PostPosted: Tue Aug 22, 2006 7:43 pm    Post subject: Object Validation Reply with quote



Im starting to figure out how object validation should work, but no
good design comes to my mind.

I think to implement something like (AOP) aspect, but design only to my
ValueTypes, so I can write the validation in a separeted unit,
register, and when necessary call validation, that will apply the
validation rule in the ValueType.

But I can see a whole picture this, does anyone done something like
that, any paper to suggest?

Thank you in advance.



--
Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki/index.php/English
Back to top
Joao Morais
Guest





PostPosted: Wed Aug 30, 2006 1:12 am    Post subject: Re: Object Validation Reply with quote



Cesar Romero wrote:

Quote:
Im starting to figure out how object validation should work, but no
good design comes to my mind.

I think that I've missed something, but what do you mean with object
validation? Something that a protected virtual method cannot help?

--
Joao Morais
Back to top
Cesar Romero
Guest





PostPosted: Wed Aug 30, 2006 1:55 am    Post subject: Re: Object Validation Reply with quote



Quote:
I think that I've missed something, but what do you mean with object
validation? Something that a protected virtual method cannot help?

yes this kind of methods can help, but Im developing a Validation
Framework that can be injected to a existing object (like AOP) only if
necessary, and in this whay you can separate the default Getters and
Setters of the real Business logic.

[]s


Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki/index.php/English
Back to top
Hechicero
Guest





PostPosted: Tue Sep 05, 2006 8:57 pm    Post subject: Re: Object Validation Reply with quote

Hi Cesar,
I may have a sugestion. (I had to design a similar
functionality to let final users customize some validations).

If you want to mimmic some AOP like behaviour for validations
it may come handy the hability to "hook" every method/property of your
domain objects. Then you could write your own validations like "before
executing Person.Age setter validate that the age is between 1 and 99"

In Delphi 7 I achieved a similar behaviour generating a proxy
for each BO, but had some restrictions: each method should be virtual. In
..NET you could take advantage of the proxys that are automatically generated
if you inherit from ContextBoundObject.

Are you planning to do it in Delphi 7 or in a Delphi.NET?

Esteban Calabria

"Cesar Romero" <cesar (AT) liws (DOT) com.br> escribió en el mensaje
news:44eb1815$1 (AT) newsgroups (DOT) borland.com...
Quote:
Im starting to figure out how object validation should work, but no
good design comes to my mind.

I think to implement something like (AOP) aspect, but design only to my
ValueTypes, so I can write the validation in a separeted unit,
register, and when necessary call validation, that will apply the
validation rule in the ValueType.

But I can see a whole picture this, does anyone done something like
that, any paper to suggest?

Thank you in advance.



--
Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki/index.php/English
Back to top
Cesar Romero
Guest





PostPosted: Tue Sep 05, 2006 11:34 pm    Post subject: Re: Object Validation Reply with quote

Quote:
Are you planning to do it in Delphi 7 or in a Delphi.NET?

Delphi 7


[]s


Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki
Back to top
Hechicero
Guest





PostPosted: Wed Sep 06, 2006 7:31 pm    Post subject: Re: Object Validation Reply with quote

Cesar,
What we did in delphi 7 to achieve a similar result was to have an
application that automatically generates a proxy for each buisness object.
Unfortunately it has the drawback that each method should be declared
virtual.

Let me give you an example. You have a class:

TPerson = class(TBuisnessObject)
procedure DoSomething;virtual;
procedure DoSomethingElse;virtual;
end;

The proxy generator would automatically generate a

TPersonProxy = class
procedure DoSomething;override
procedure DoSomethingElse;override;
end;

A possible implementation would be:

procedure TPersonProxy.DoSomething;override
Begin
TNotificationServices.getInstance.NotifyBeforeMethodExecution('DoSomething',Self);
inherited;
TNotificationServices.getInstance.NotifyAfterMethodExecution('DoSomething',Self);
end;

and somewhere in your app you could hook

myHook := TMyHook.Create;
TNotificationServices.getInstance.HookMethod('Do*', myHook); //This will
hook every method that starts with Do

Whenever a TPerson is created, a proxy should be created. This can
be achieved overriding TObject.NewInstance class method in your
TBuisnessObject class. (it would be like overriding the classloader in
java).

For this, to code your proxy generator, you may need to get your
hands on a good Object Pascal parser (or code your own). Also you can use
the proxy generator to validate that each object should be virtual.

I think I am not missing anything.

I hope this helps. Tell me if this is info is usefull.

Esteban Calabria

(PD: It would be really really fun to see if you could hook every method
using madCodeHook library and you save from having a proxy for each BO)

"Cesar Romero" <cesarliws (AT) gmail (DOT) com> escribió en el mensaje
news:44fdc349$1 (AT) newsgroups (DOT) borland.com...
Quote:
Are you planning to do it in Delphi 7 or in a Delphi.NET?

Delphi 7


[]s


Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki
Back to top
Cesar Romero
Guest





PostPosted: Wed Sep 06, 2006 8:31 pm    Post subject: Re: Object Validation Reply with quote

Esteban,

Really usefull, I will start to play with that, and post here my
results, thank you...


--
Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki
Back to top
Cesar Romero
Guest





PostPosted: Thu Sep 07, 2006 8:12 am    Post subject: Re: Object Validation Reply with quote

Esteban,

All this is really very nice, and I think that works (at least make
sense to me).

This is what I should try, if I need to Proxy any method, But at
moment, my needs is more simple, I forgot to mention that I have a
ValueType Framework done, and my first goal is "inject code" in Get/Set
method of BO properties.

Like this:

TPerson = class(TObjectType, IPerson)
private
FName: IStringType;
protected
function GetName: string;
procedure SetName(const Value: string);
property Name read GetName write SetName;
public
procedure AfterConstruction; override;
end;

procedure TPerson.AfterConstruction;
begin
inherited;
AddMember(FName, 'Name');
end;

function TPerson.GetName: string;
begin
Result:= FName.Value;
end;

procedure TPerson.SetName(const Value: string);
begin
FName.Value:= Value;
end;


For this, I think that I can put the code to hook with "Validator" in

TStringType
GetValue
SetValue

eg:

procedure TStringType.SetValue(const Value: string);
begin
if FValue <> Value then
begin
---> here hook the before set code
FValue:= Value;
Changed;
---> here hoom the after set code
end;
end;

So, for this kind of implementation, I need to create a "Register" for
the object validation methods and the hook code....


But, I still need to have some "IsValid: boolean" function is my BO,
and that I can use your way Smile
And in this particular case, I will put the IsValid function as virtual
in TObjectType, or I still dont know, in a TProxyObjectType, that can
be always created, here your opinion is again welcome. :)

If you want to take a look at my VTF/OPF framework, please take a look
at:
http://www.liws.com.br/wiki/index.php/English
http://jazz.liws.com.br/download/jazz_a4.1.zip (last alpha version)
all your critics and comments are welcome :)


Best regards,


Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki




Hechicero wrote:

Quote:
Cesar,
What we did in delphi 7 to achieve a similar result was to have
an application that automatically generates a proxy for each buisness
object. Unfortunately it has the drawback that each method should be
declared virtual.

Let me give you an example. You have a class:

TPerson = class(TBuisnessObject)
procedure DoSomething;virtual;
procedure DoSomethingElse;virtual;
end;

The proxy generator would automatically generate a

TPersonProxy = class
procedure DoSomething;override
procedure DoSomethingElse;override;
end;

A possible implementation would be:

procedure TPersonProxy.DoSomething;override
Begin

TNotificationServices.getInstance.NotifyBeforeMethodExecution('DoSomet
hing',Self); inherited;
TNotificationServices.getInstance.NotifyAfterMethodExecution('DoSometh
ing',Self); end;

and somewhere in your app you could hook

myHook := TMyHook.Create;
TNotificationServices.getInstance.HookMethod('Do*', myHook); //This
will hook every method that starts with Do

Whenever a TPerson is created, a proxy should be created. This
can be achieved overriding TObject.NewInstance class method in your
TBuisnessObject class. (it would be like overriding the classloader
in java).

For this, to code your proxy generator, you may need to get
your hands on a good Object Pascal parser (or code your own). Also
you can use the proxy generator to validate that each object should
be virtual.

I think I am not missing anything.

I hope this helps. Tell me if this is info is usefull.

Esteban Calabria

(PD: It would be really really fun to see if you could hook every
method using madCodeHook library and you save from having a proxy for
each BO)

"Cesar Romero" <cesarliws (AT) gmail (DOT) com> escribi en el mensaje
news:44fdc349$1 (AT) newsgroups (DOT) borland.com... >> Are you
planning to do it in Delphi 7 or in a Delphi.NET?

Delphi 7


[]s


Cesar Romero
http://blogs.liws.com.br/cesar
http://www.liws.com.br/wiki



--
Back to top
Joao Morais
Guest





PostPosted: Fri Sep 08, 2006 3:08 am    Post subject: Re: Object Validation Reply with quote

Cesar Romero wrote:

Quote:
I think that I've missed something, but what do you mean with object
validation? Something that a protected virtual method cannot help?

yes this kind of methods can help, but Im developing a Validation
Framework that can be injected to a existing object (like AOP) only if
necessary, and in this whay you can separate the default Getters and
Setters of the real Business logic.

Hello,

Reading your thread with Esteban I discovered that I hadn't understood
what you mean. Let's try again ;-)

Currently I'm using the InstantObjects approach on my framework, that
is, using rtti. Look:

TMyObj = class(TPressObject)
_MyProp: TPressString; // the 'value type' object
private
function GetMyProp: string;
procedure SetMyProp(const Value: string);
published
property MyProp: string read GetProp write SetProp;
end;

The framework get the published MyProp property and use it to update
business attributes, so your validation can be written into the BO setters

For the whole object validation I am, currently, using a virtual
protected method.

HTH.

--
Joao Morais
Back to top
Cesar Romero
Guest





PostPosted: Fri Sep 08, 2006 7:05 am    Post subject: Re: Object Validation Reply with quote

Quote:

Reading your thread with Esteban I discovered that I hadn't
understood what you mean. Let's try again Wink

:)


Quote:
The framework get the published MyProp property and use it to update
business attributes, so your validation can be written into the BO
setters

For the whole object validation I am, currently, using a virtual
protected method.

Still is not the Point João, what I am doing is separate the validation
code from getters and setters, I want to have a BO unit auto generated
and read only, so the developer will write the validation in other unit
like a class plugin...

Thank you, for your reply

[]s


Cesar Romero
http://blogs.liws.com.br/cesar
Back to top
Joao Morais
Guest





PostPosted: Fri Sep 08, 2006 6:44 pm    Post subject: Re: Object Validation Reply with quote

Cesar Romero wrote:

Quote:
The framework get the published MyProp property and use it to update
business attributes, so your validation can be written into the BO
setters

For the whole object validation I am, currently, using a virtual
protected method.

Still is not the Point João, what I am doing is separate the validation
code from getters and setters, I want to have a BO unit auto generated
and read only, so the developer will write the validation in other unit
like a class plugin...

Just curiosity - why a separate class? Personally, I'm planning to
generate code via a Pascal parser so changed getters and setters won't
be touched if I need to change the model.

Thanks.

--
Joao Morais
Back to top
Cesar Romero
Guest





PostPosted: Fri Sep 08, 2006 7:23 pm    Post subject: Re: Object Validation Reply with quote

Quote:
Just curiosity - why a separate class? Personally, I'm planning to
generate code via a Pascal parser so changed getters and setters
won't be touched if I need to change the model.


It is more than a if Value <> '' Validation, It is to inject code,
improve code without have the class code, inject code from a dll, a lot
of cases.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.