Search This Blog

Sunday, July 6, 2014

Validating in the Class Model

I am still working on moving the input validation from the form to the class model.
I am considering two options for passing the result of the validation to the polymer element.

  1. A bool function with a FormatException for the error message.
  2. Add validation to the setter.
  3. Or return a CustomEvent with a Map of the result and message.

In the setter

The object is more protected  if the validation is in the setter.   Defining the setter with validation requires creating a private field and removing the @observable status from the field; Observables can have setters or getters.

So that the field can continue to function as an observable, the function notifyPropertyChange needs to be added to the setter.  Seth provides an example.

Is it worth it?

Implementing the validator in the model class has complicated the code.  Is having a more robust class worth it?

No comments:

Post a Comment