Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't recommend this way of validating your models.</p> <p>First off, have the controller validate the input, in so far as insuring that it's a string when it should be, an integer when it should be and so on. But NOT the business logic.</p> <p>When you create a new Member, I suggest passing all the information in through the constructor instead. That way the constructor can check the OVERALL model consistency, while the setter methods should have consistency checks for each datum that they are responsible for.</p> <p>For instance, if you had another piece of information like firstHeardOf (the first time they heard of whatever site they're becoming a member of), the setter should ensure that it's a valid date and it's AFTER the date of birth, at the very least. This creates an ordering issue of methods, and requiring methods be called in a particular order isn't good practice, instead the constructor can be used to guarantee the ordering of the calls.</p> <p>The save method is now just a simple method, it saves the data, and really why should it have any other responsibility. At most it should double check that the constructed member is still valid, which is where you might want to pull the constructor validation code into a private/protected validation method and call that in both places.</p> <p>A quick word on responsibilities, and how they break down here, at least in my mind:</p> <ul> <li>The constructor is responsible for creating a valid/properly initialized Member object</li> <li>The setters are responsible for setting valid data within the member object for the datum</li> <li>The save method is responsible for saving a valid member object</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload