2

Can you suggest some good design pattern for below scenario:

We have multiple vendors, called Company A, B and C. Each company has their own business logic.

learn java
  • 51
  • 1
  • 5
  • "I would like to write some wrapper kind of class, that should decide which company to invoke, override all generic methods and do all operation." Why do you want to do that? This seems to throw away everything you described above it. Anyway, sounds like it might be a Proxy pattern. – Daniel Kaplan Apr 13 '15 at 20:53

4 Answers4

4

Smells like Strategy Pattern to me: link

Inside interface define method(s) which will be performed by concrete vendors. Concrete vendor have to implement interface and add own implementation of method (strategy).

baza92
  • 344
  • 1
  • 10
0

You may use an interface, CompanyTemplate which will contains all the common methods that should be implemented by company A, B and C -

public interface CompanyTemplate{

   public someCommonMethod();

}  

After that A can inplement CompanyTemplate -

public class A implements `CompanyTemplate` {

  public void someCommonMethod(){
     //implementation code
  }  

  //Other methods special only for company for A

}
mbdavis
  • 3,861
  • 2
  • 22
  • 42
Razib
  • 10,965
  • 11
  • 53
  • 80
0

For this you can use the following patterns

Abstract Factory

Proxy Factory

Strategy

also consider this following diagram.enter image description here

Rahul Thachilath
  • 363
  • 3
  • 16
0

If your business logic is related to creation of different objects for different vendors, you can use Factory Method / Factory_ patterns.

If your business logic is related to change behaviour of system for different vendors, you can use Strategy_pattern

Refer to related SE questions for more details about these patterns:

Real World Example of the Strategy Pattern

What is the basic difference between the Factory and Abstract Factory Patterns?

What is the difference between Factory and Strategy patterns?

Community
  • 1
  • 1
Ravindra babu
  • 37,698
  • 11
  • 250
  • 211