How to name different components in adapter pattern?

by donquixote   Last Updated December 03, 2017 20:05 PM

(example code in PHP, but this can apply to more languages)

I have a scenario with an adapter pattern, where I have classes, interfaces and objects with different roles, like so:

  1. An original object implementing CatInterface.
  2. A class that implements DogInterface, which wraps a CatInterface object.
  3. An instance of that class, wrapping the $cat object.
  4. A service object, that wraps cat objects into new adapter instances.

My question: In this scenario, which component is the "adapter"?

E.g. the service object might look like this:

class CatDogAdapter {
  function adapt(CatInterface $cat) : DogInterface {
    return new DogFromCat($cat);
  }
}

$adapter = new CatDogAdapter();
$cat = new Cat;
$dog = $adapter->adapt($cat);

In this example, I used the term "adapter" in the name of the service object / class. But is this the common way that the name is used? Or should I rather use the term "adapter" for the "DogFromCat" class, and name the service e.g. "AdapterFinder" or "AdapterFactory"?

Ideal would be literature or examples that point to a common practice in naming these components.

Maybe such a consensus does not exist, and it is all the wild west - in this case the question goes nowhere, and I have to decide for myself.

I am tagging this as PHP and Java, because I think the question would apply to both languages.



Related Questions






Naming a view class

Updated June 14, 2017 19:05 PM