A design issue


General J2EE: A design issue

  1. A design issue (3 messages)

    Could you have a look on the following design, I think it is not good, but don't know how to improve it. We have one class name GeneralValidator, it used for validate length of fields. Its code looks like: public abstract class GenericValidator{ public abstract getLength() public validate(XXX xxx){ this.getLength. Do some operation based on length. } } The class has many subclassess. Each of them only have one line executable code, such as public getLength(){return 5}. The good point of this design is easy to have new validator. But it generate many simple classes. Any suggestion on how to improve it? Thanks.

    Threaded Messages (3)

  2. Re: A design issue[ Go to top ]

    It seems that OO isn't used right here )) Of course you shouldn't make 1000s of almost identical classes just to reflect non-behavioral distinction between them. The class you supplied should be a subclass of a more generic Validator interface (just public boolean validate(T param)), and should have a name, say, LengthValidator. Then, you should add a 'length' property. Finally, you should make a singleton farm (Factory) of few instances (each with its own length). You could easy wire this up (and maintain) using Spring. gl
  3. Re: A design issue[ Go to top ]

    Thanks for your kindly reply. Please permit me confirm whether I have understand your idea. You mean I can have more generic class named LengthValidator. Looks like the following code: public LengthValidator{ public int length; public validationResult validate(){ do some validation operation based on lenght. } } This class don't have those subclass to provide specific length. But there is a single factory for it. This factory has serveral instances. The code would looks like: public LenthValidatorFactory{ private LenthValidator aaaLengthValiator; private LenthValidator bbbLengthValiator; .... public getAAALenthvalidator(){ if(aaaLengthValiator==null){ /*according to some configuration or constant(where length is defined) create all validators. */ initlize() }else{ return aaaLenghtValidator } } public getBBBLengthValidator(){ ... } .... Is that right? I appreciate your help.
  4. Re: A design issue[ Go to top ]

    anybody can help on above issue? Thanks.