Jump to content

Your thoughts on this design issue


rubenski

Recommended Posts

Hi,

 

I think I ran into a design problem with the PHP application I'm building.

 

I have this function called validateFormElement() that takes FormElements polymorphically. A FormElement can be a FormElement or a TextFieldFormElement, or a TextAreaFormElement, etc. Inside the method I use a factory to obtain the proper FormElementValidator. Passing a TextFieldFormElement to the validateFormElement() function will make the factory return the specific TextFieldFormElementValidator.

 

 

function validateFormElement(FormElement $formElement){
$validator = FormElementValidatorFactory::getInstance(get_class($formElement));

// .. if-elsing here
} 

 

But now I don't know what functions I can call on the $validator. Each type of Validator returned by the factory has different functions and now I find myself if-elsing to see what type of $validator I have and consequently what functions I can call on $validator.

 

This is not good. Is it?

 

How would you do this? I need a specific validator for each type of $formElement. The issue is not that I can't get it to work. If-elsing does the job, but it just seems... wrong.

 

 

Link to comment
https://forums.phpfreaks.com/topic/190796-your-thoughts-on-this-design-issue/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.