P
Peter Judge
Guest
I've got a bug to fix that requires me to add some validation into a property setter. The challenge is that the object is a general-purpose value object (it's an HttpHeader) and so the property (the Value) can have different validation depending on the Name of the header. I can see a couple of approaches to providing validation for particular headers 0) I nline validation. aka the ugly way. Add a CASE statement in the header object or try to patch it wherever the value might be set. Actually no ... not gonna do that
1) Subclass the HttpHeader object and add an internal validation method . This isthe easiest and is well-encapsulated. The challenge is that a developer/consumer of these header objects has to know to create a ContentTypeHeader instead of an HttpHeader. That said, I have infrastructure already in place to deal with this (an HttpHeaderBuilder) but there's still no guarantee that it will be used. Which leads me to ... 2) Provide a independent Validation module, that takes a value and returns something if the validation fails. Similar to assertions but with the capability to have more specialised logic. This validation logic can be called from various places (before setting the value, before creating output etc) as a double-check that values are correct. This also gives me a way to have validation for a particular thing in ONE place (as opposed to checking it everywhere its set). This requires creating various validation objects which would (in this particular case) be stored and keyed off of the header name (Content-Type is the one I care about right now). I would also modify the HttpHeader to call this validation logic. 3) Something completely different. Any thoughts/comments?
Continue reading...
Continue reading...