I want to check my domain objects before transferring them to another part of the system. All the objects I want to check use the same interface. The problem is that I cannot figure out how to write this in a good way. I do not want to move the check inside my value object. But I donβt want to be forced to check the instances.
Example:
public interface Vehicle {} public class Car implements Vehicle {} public class MotorBike implements Vehicle {} public interface VehicleValidator { void validate(); } public class CarValidator implements VehicleValidator { @Override public void validate() {} } public class MotorBikeValidator implements VehicleValidator { @Override public void validate() {} } public void process(Vehicle vehicle) {
In Scala, I would do something similar to http://debasishg.blogspot.se/2010/06/scala-implicits-type-classes-here-i.html But these language constructs are not possible in Java.
java inheritance design-patterns validation
tbruhn
source share