(1) , ?
, . "validate" ( "Animal" ) . (, /) validate "InvalidContentException" "ErrorHandler", .
(2), , : , . , - "Animal", ?
Validator, ( Animal). , Validator "" (, "" ), "Cat" "Eagle" ( ). , , , "Cat": Cat (, , ,...)
-> I think you should ask yourself if you want to be able to check animals in general. Having no idea about your problem area (which may have reasons not to do this), I would recommend using the "proven" method for the animal. You can also use the visitor template, but this requires that Animal have a method of “accept (AnimalVisitor visitor)” and a bit more code to write (presumably more than you want)
source
share