Common Business Rules Validations


EJB design: Common Business Rules Validations

  1. Common Business Rules Validations (4 messages)

    We have an EJB application with both local/remote views.

    There are some common business rules validations used across EJB components in the application. I was thinking on lines, if these common validation methods could be seperated out into a POJO (probably implemented as singleton) which could be called from various EJB(s).

    Is the approach correct? Any better alternatives/patterns?

    The purpose is to have common validations at once place (class) in the EJB tier.

    Threaded Messages (4)

  2. Common Business Rules Validations[ Go to top ]

    That's not a bad approach, provided that your POJO singleton does not use any instance variables.

    For that matter, you may find that you can make many of your simple validations (max, min, maxlength, minlength) static methods.
  3. Try using the jakarta validator framework. Struts uses it too. In this way you can
    obtain a flexible validation because you can exeternalize your validation rules in configuration files. I suppose that this validation service will be heavily used
    so I suggest you make it a session bean. Maybe a session bean sounds to heavy because you don't need all the enterprise services (transactions, security, distribution, etc), you just need the object pooling. Making it a singleton implies that you have to aware of the threading and distribution issues imposed by the application server.
    Best regards, Mircea
  4. I had initially posted this message.

    Actually, by validations, I meant business rules on domain objects, the business rule is inside EJB components. For e.g. isAccountExists(), isBalanceAvailable(), hasMatchingEmployees() etc ...

    These validations are commonly required in across the components (session beans). So the question was, could the common validations be centralized into some class accessible from various session beans. The common validation class might need to lookup session beans for business rules validations.
  5. The answer is still yes. Just be careful about how you do the lookups. If your Java Objects are singletons, do not use any instance variables. Restrict yourself to local variables within your validation methods, and you should be OK.