What is the design pattern for invoking different implementations according to different parameter types?

for example:

  1. A system connects three distribution platforms, namely platform A, platform B and platform C
  2. for upper-level business, you only need to take your own order (this part of the attribute is fixed) object as a parameter, as well as the platform to be delivered, such as platform A, to call the API
  3. .
  4. platform D may be added in the future. Which design pattern can be flexibly extended without modifying the interface?
  5. what you can think of now is that, according to this type, different platforms are called, and a lot of
    if (type==A_CODE) {
    / / call platform A"s ordering interface}
    else if (type==B_CODE) {
    / / call platform B"s ordering interface
    } else if (type==C_CODE) {
    / / call platform C"s ordering interface
    }

in this way, if you want to refactoring, is there a suitable design pattern?

Jan.08,2022

responsibility chain. For the new platform, you only need to add an implementation. Cooperate with spi Maze


like eliminating if..else.. Just use a Map < Type,Impl > to map different implementation classes, and add a key by extending one type. Is it a strategic model?


Policy mode is the most appropriate.

Policy pattern definition
Policy pattern (Strategy Pattern), encapsulates various algorithms into concrete classes as subclasses of an abstract policy class, making them interchangeable. The client can decide which algorithm to use.

To put it simply, the

policy pattern is to choose different implementations of the same interface according to different parameters.

you can refer to this article Java Design pattern (XII) Strategy pattern

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be2089-3030d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be2089-3030d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?