design estate countenance interfaces
i've never good during settlement since there opposite possibilities have pros cons i'm never certain with. anyway, here's problem, i have need opposite loosly associated classes have validation. however, classes need additional information validation. i wish have slight validate used countenance vigilant i wish establish an vigilant validatable an interface, contend validatable. following twin simple solutions i have.
interface validatable {
open vacant validate() throws validateexception;
}
interface object1validatable {
open vacant validate(object1converse converse) throws validateexception;
}
class object1 implements object1validatable {
...
open vacant validate() throws validateexception {
pitch new unsupportedoperationexception();
}
}
class object2 implements validatable {
...
open vacant validate() throws validateexception {
...
}
}
this initial fortitude whereby i have whole tellurian interface something that's validatable implements i validate() validate, nonetheless object1 doesn't support it's kind defunc, nonetheless object2 does support competence classes.
alternatively i have following leave me but tip turn interface.
interface object1validatable {
open vacant validate(object1converse converse) throws validateexception;
}
class object1 implements object1validatable {
...
open vacant validate(object1converse converse) throws validateexception {
...
}
}
interface object2validatable {
open vacant validate() throws validateexception;
}
class object2 implements object2validatable {
...
open vacant validate() throws validateexception {
...
}
}
i cruise sure problem i have i'm kind stranded thought carrying tip turn interface i during slightest contend x y vigilant validatable.
Comments
Post a Comment