Strategy or adapter template?

I want to create several classes of each virtual server provider, for example:

  • Digital ocean
  • Linode
  • Amazon aws

Each provider has its own PHP class (through the composer) to use their API, I want to use their class library, but I want me to use the same method for each provider. For example, turning off VPS:

  • Linode API: powerOff()
  • Digital Ocean API Method: haltServer()

Instead of using powerOff()and haltServer()- I want to use the method shutdown()for any classes of providers that I will create. Should I use a strategy template or adapter template?

+4
source share
3 answers

Should I use a strategy template or adapter template?

This is a classic mistake that everyone makes when developing an application (including me). Ideally, you should not look at the list of available design templates and choose the one that best suits your problem. Instead, you should come up with a starting class, and then try to determine the template that best describes your design. This protects you from over-designing i.e. Creating unnecessary components that you would otherwise not need. Over time, you will soon have a dictionary of design templates that you used, and not an application that tries to use a specific design template.

, , , /. , .

, "" , shutdown, connect, retry .. , AWSProvider LinodeProvider shutdown, connect retry. , API . , powerOff shutdown LinodeProvider.

, , , Aadpter. , , - , . , Factory , ; , , . , .

, , , , .

+8

: Adapter,
Strategy , algortihm.

p.s. Command .

+1

Strategy Adaptor. , .

, . , shutdown, , .

0

Source: https://habr.com/ru/post/1666315/


All Articles