Interface, classes and variables issue

  • Thread starter Thread starter YankeeImperialistDog
  • Start date Start date
Y

YankeeImperialistDog

I'll really try to explain this as clearly as i can.
I'm attempting to create a de-coupled validator to be used with NHibernate,
but before you object, this is not an NHibernate question. It's a question of
a limitation of interface limitation. Actually i hope not.

OK, here is the interface.
public interface IValidationRule<T>
{
bool RuleIsBorken(T entity);
string GetMessage();
}
And here is my problem
public class LastNameIsBlank : IValidationRule<Person>
{
public bool RuleIsBorken(Person entity)
{
var test = new ValidateForBlankProperty();
return test.testForBlank(entity, propertyToTest);
}
}
is tightly coupled to Person. Is there a way to make Person a variable type?
I'm open to alternatives.
Thanks
 
YankeeImperialistDog said:
I'll really try to explain this as clearly as i can.
I'm attempting to create a de-coupled validator to be used with NHibernate,
but before you object, this is not an NHibernate question.

It appears to have at least some specific connection to NHibernate. But
that's fine, as long as you can describe the behavior that is connected
to NHibernate in a more general way, without assuming knowledge of
NHibernate.

If you can't, you'll restrict any commenting to those familiar with
NHibernate.
It's a question of
a limitation of interface limitation. Actually i hope not.

OK, here is the interface.
public interface IValidationRule<T>
{
bool RuleIsBorken(T entity);
string GetMessage();
}
And here is my problem
public class LastNameIsBlank : IValidationRule<Person>
{
public bool RuleIsBorken(Person entity)
{
var test = new ValidateForBlankProperty();
return test.testForBlank(entity, propertyToTest);
}
}
is tightly coupled to Person. Is there a way to make Person a variable type?

"Person" can be a type variable if it's used in a generic context. But
without knowing more about your ValidateForBlankProperty class, its
testForBlank() method, what "propertyToTest" means, etc. it's not really
clear how you might go about doing that.

For that matter, it's not really clear what the problem here is. You've
specifically declared your class LastNameIsBlank to implement a
Person-specific interface. Why _shouldn't_ the contents of that class
be tightly coupled to Person?

I know you said you'd try to explain your problem clearly. But I'm
afraid you haven't really been very detailed in your question. For that
matter, the phrase "limitation of interface limitation" has no clear
meaning, so I don't even know what that's supposed to convey.

Pete
 
I'll really try to explain this as clearly as i can.
I'm attempting to create a de-coupled validator to be used with NHibernate,
but before you object, this is not an NHibernate question. It's a question of
a limitation of interface limitation. Actually i hope not.

OK, here is the interface.
public interface IValidationRule<T>
{
bool RuleIsBorken(T entity);
string GetMessage();
}
And here is my problem
public class LastNameIsBlank : IValidationRule<Person>
{
public bool RuleIsBorken(Person entity)
{
var test = new ValidateForBlankProperty();
return test.testForBlank(entity, propertyToTest);
}
}
is tightly coupled to Person. Is there a way to make Person a variable type?
I'm open to alternatives.

Do you mean something like:

public class LastNameIsBlank<T> : IValidationRule<T>
{
public bool RuleIsBorken(T entity)
{

?

Arne
 
"YankeeImperialistDog" <[email protected]>
wrote in message
public bool RuleIsBorken(Person entity)
{
var test = new ValidateForBlankProperty();
return test.testForBlank(entity, propertyToTest);
}
}
is tightly coupled to Person. Is there a way to make Person a variable
type?
I'm open to alternatives.

I don't really follow the question, however, it piqued my interest and I
found this:
http://brendan.enrick.com/blog/validating-entity-objects/
 
Back
Top