parameters check outside method - declaratively configurable?

M

Maciek Zywno

hello

I guess that usually methods parameters are checked against being null,
outside of some range etc. in a method body just before an actual method
logic code. Then probably either runtime exception is thrown if there is
something wrong with parameters or proceed to the actual method logic.

I am curious of your opinion about the idea to make some parameters
check validation configuration in xml (some generic solution i.e. e.g.
checks against null) and let some proxy read this configuration and do
parameters check before invoking real method? Maybe it would be possible
to take such parameters validation outside meethod and make it this
validation declaratively configurable?

Does it sound logcal?
I would appreaciate any opinion :)

regards

Maciek Zywno
 
A

Albert Deinbeck

Maciek Zywno said:
hello

I guess that usually methods parameters are checked against being null,
outside of some range etc. in a method body just before an actual method
logic code. Then probably either runtime exception is thrown if there is
something wrong with parameters or proceed to the actual method logic.

I am curious of your opinion about the idea to make some parameters
check validation configuration in xml (some generic solution i.e. e.g.
checks against null) and let some proxy read this configuration and do
parameters check before invoking real method? Maybe it would be possible
to take such parameters validation outside meethod and make it this
validation declaratively configurable?

Does it sound logcal?
I would appreaciate any opinion :)

Could be done with aspectj quite easily. (Or some other aspect-oriented java
add-on). Why don't you just try to implement it?

Albert
 
M

Maciek Zywno

Albert said:
Could be done with aspectj quite easily. (Or some other aspect-oriented java
add-on). Why don't you just try to implement it?

Albert

Hi

I was thinking about spring proxy :) (Probably will try to make some
mini-framework during this weekend)

My main concern is whether it could be useful.., I mean.. there is a lot
of fuss nowadays with taking as much as possible outside of the code
(transaction management, logging, security..).

My question is whether it is not too much to take parameters check
outside of the method. Just because it is possible, it does not
neceserilly mean that it should be done :) What do you think?

regards

Maciek Zywno
 
C

Chris Uppal

Maciek said:
I am curious of your opinion about the idea to make some parameters
check validation configuration in xml (some generic solution i.e. e.g.
checks against null) and let some proxy read this configuration and do
parameters check before invoking real method?

Personally, I can't see the point -- not in the general case anyway.

In some /specific/ cases it might make a lot more sense. If the validation was
against business constraints (amount < 1000 UKP, for instance) rather than what
is needed for the code to work at all (reference != null, for example) then it
might be better to "externalise" the constraint. However I'd still put the
checking in the method rather than in its caller. Validation belongs as
"close" to the code that should be protected as possible -- both to reduce
duplication, and to reduce the chances of error. That doesn't mean that some
callers couldn't /also/ do the validation -- a GUI for instance might want to
validate interactively before sending the data off to the real business logic,
where it would be validated again.

-- chris
 
M

Maciek Zywno

Chris said:
Maciek Zywno wrote:




Personally, I can't see the point -- not in the general case anyway.

In some /specific/ cases it might make a lot more sense. If the validation was
against business constraints (amount < 1000 UKP, for instance) rather than what
is needed for the code to work at all (reference != null, for example) then it
might be better to "externalise" the constraint. However I'd still put the
checking in the method rather than in its caller. Validation belongs as
"close" to the code that should be protected as possible -- both to reduce
duplication, and to reduce the chances of error. That doesn't mean that some
callers couldn't /also/ do the validation -- a GUI for instance might want to
validate interactively before sending the data off to the real business logic,
where it would be validated again.

-- chris

I was thinking about general constraints i.e. such that are needed for
the code to work at all (not null, string size greater than zero.. any
other?) rather than business constraints which are not reusable across
projects.

Despite checking parameters against null in methods (copying and
pasting) you'd put info in xml that such and such methods expect not
null identifiers - what do you think?

regards

Maciek Zywno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top