learn java
learn java

Reputation: 51

Need help on Java design pattern

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.

Upvotes: 2

Views: 153

Answers (4)

Ravindra babu
Ravindra babu

Reputation: 38910

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?

Upvotes: 0

Rahul Thachilath
Rahul Thachilath

Reputation: 363

For this you can use the following patterns

Abstract Factory

Proxy Factory

Strategy

also consider this following diagram.enter image description here

Upvotes: 0

Razib
Razib

Reputation: 11163

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

}

Upvotes: 0

baza92
baza92

Reputation: 344

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).

Upvotes: 4

Related Questions