OOP design - validation when validation means hitting the database to check -
let's pretend we're talking html complaint form, 1 field of product list company catalog.
i gather validation (always?) goes in own class.
i gather it's practice have gateway classes can handle database queries internally, when save complaint complaint form don't have worry database details.
but validation requires accessing database - example checking product product have (and not tampering form). can done finding match in database... database abstracted behind gateway.
do add validation logic gateway? create validator gateway classes? empower validator database logic?
edit - attempt clarify...
- customer clicks link complaint form
- html complaint form built
<select><item></item></select>
dropdown x products our fictional company catalog - customer completes form , submits // wiseguy alters html product "schweddy balls" , submits
- form class validates simple things date, required fields have data, email address, etc.
at step 4, in order validate product being complained legit, you'd have hit database's product table see if it's still valid datapoint. should logic go in form class, gateway class, or somewhere else? putting in form class breeds dependencies, not?
validation should, oddly enough, not done directly through validation class. model object's class (in case complaint) should include validation class , validations should done in there. since complaint has access complaints, validation methods can use methods of complaint class, or call model class if needed.
when "gateway" database, believe you're talking on object relational mapping (orm), allows model objects, complaint, abstractly talk database. orm should have no knowledge of structure or specifics of application, should abstract api objects communicate database or other backend.
surely response not cover everything, further questions/clarifications welcome.
Comments
Post a Comment