Common function in base classes

I just had to implement something what I consider should be part of the extended class. In Eclipse wizards you can create panels and then have validation on those panels. I would say 99.9 percent of the time, if not more, you will want all of the fields that are required, validated. So I think the base class, in this case it is OptionTemplateSection, there should be implemented a common set of code that validates all of the required fields on the page are filled in. The code below is probably in almost every validateOptions() method that implements this. You can see the code is pretty generic and if the options are required then you need to flag an error.

I would prefer the OptionTemplateSection implements the abstract method validateOptions() from class BaseOptionTemplateSection.

public void validateOptions(TemplateOption source) {

if (source.isRequired() && source.isEmpty()) {

flagMissingRequiredOption(source);

}

validateContainerPage(source);

}

private void validateContainerPage(TemplateOption source) {

TemplateOption[] allPageOptions = getOptions(0);

for ( int i = 0; i < allPageOptions.length; i++) {

TemplateOption nextOption = allPageOptions;

if (nextOption.isRequired() && nextOption.isEmpty()) {

flagMissingRequiredOption(nextOption);
return ;

}

}
resetPageState();

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.