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.
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.
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
}
For this you can use the following patterns
also consider this following diagram.
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?