0

I am in a confusion where I cannot decide whether a rule is validation rule or Business rule. I have simple POJO with JSR 303 bean validation rules.

public class VehicleDto {

    @NotNull(message = "Vehicle ID is not given.")
    @Size(min = 3, max = 20, message = "Vehicle ID length is out of range of 3 to 20.")
    @Pattern(regexp = "^([0-9]+[a-zA-Z]+|[a-zA-Z]+[0-9]+)[0-9a-zA-Z]*$", message = "Vehicle ID is not alphanumeric.")
    private String id;
    @NotNull(message = "Vehicle name is not given.")
    @Size(min = 3, max = 45, message = "Vehicle name length is out of range of 3 to 45.")
    private String name;
    @Min(value = 1, message = "Organization ID is not given.")
    private long organizationId;
    private Long deviceId;
}

I believe validation rule as data validation. For example: In above pojo, I have a vehicle id which is always supposed to be alphanumeric of length at least 3 to 20 if vehicle id exists. But it should exist to register a vehicle is our business policy right which happens to be a business rule. Also while registering a vehicle, the need of foreign key (organizationId and deviceId) checks for their entity existences for registration also happens to be business rule.

These are the thoughts that are confusing me. Am I right on those thoughts guys?

1

While "vehicleId must exist" may be also a (quite non-specific) business rule, in this case it's mainly a validation rule. Unless there are cases where you would create and assign a new id for a vehicle, the business rule is implied (you need to have an id for the entity if you intend to work with it).

Would you consider "user must exist if you want to change its password" a business rule? I think not.

If other parts of your system were able to create and assign vehicleIds, the business rule would be "vehicles must have vehicleId, unless they're being created", which would result in two validation rules in separate parts of the system.

  • Thanks.. But if we vision a traditional process of vehicle registration without any computer system, a registrar gives us a registration form in which our business policy would be client must include their vehicle id in form in order to further process their vehicle registration right... Or am I wrong in understanding the term policy? – Mani Rai Nov 6 '17 at 10:10
  • Then it's clearly a validation rule. If the vehicleId doesn't exist (or is wrong), then you can't even start with your business rules. It's a precondition. – Kayaman Nov 6 '17 at 10:34
  • I think I am convinced with not even starting business rules in above use case. Thanks. I think the above use case is just a data recording system which supports business. – Mani Rai Nov 6 '17 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.