1

I have developed a generic business service using spring framework. this service must be accessed from different channels i.e. web and mobile channels. each channel has its own business rules that must be added dynamically to generic service functionality. for example if web channel do some additional validation and then call generic service. if mobile channel call service A, then service B then generic service. My question is what's the best design pattern/way to implement such service mediation without using an ESB?

hkazemi
  • 708
  • 4
  • 21

1 Answers1

1

I think you are looking for decorator pattern where you can attach the additional responsibility at run time.What you can do is

Public Class GenricValidationService extends ValidationService{


 public void Validate(){
 // do stuff here
 }
}



Public Class WebChannelService  extends ValidationService{

  public WebChannelService  (ValidationService validationService){
   this.validationService= validationService;
   }

ValidationService validationService;

public void Validate(){
  genericValidationService.validate();
  // extra validation
 }
}

similarly

Public Class ServiceB extends ValidationService{

  public ServiceB (ValidationService validationService){
    this.validationService= validationService;
   }

  ValidationService validationService;

public void Validate(){
  validationService.validate();
  // extra validation
 }
}

see

Decorator Pattern for IO

Decorate Your Java Code

Community
  • 1
  • 1
M Sach
  • 33,416
  • 76
  • 221
  • 314
  • I want to add this type of functionality using a config file and be able to use existing services – hkazemi Jul 12 '14 at 10:23