title: How to consume multiple services using same class
body: <p>I need a way to handle multiple different services with the same class. Let's say I have a local data base where my local posts are stored. Each time I save a post to this local database I need to post with those services as well. So they will need a adapter pattern for sure so that I can always use the same methods. That is clear but I am not sure how I could make the main class interchangable so that I can load the needed platform and service on the fly.</p>
  <p>The structure could be like:</p>
  <pre><code>App              App
   Adapters         Adapters
    ServiceA         ServiceB   
     Post.php         Post.php
     Category.php     Category.php
     ...              ...
  </code></pre>
  <p>By using the adapter pattern methods within <code>Post.php</code> will have adapted the same methods <code>sendPost()</code> and <code>deletePost()</code>.</p>
  <p>Now I will be able to send post for each platform using the same sendPost() method. I could do like this.</p>
  <pre><code>$post = Post::create($form_array);
  $services = Service::get();
  
  foreach ($services as $service){
      $class = '\\App\\Adapters\\'.$service-&gt;name.'\\Post';
      $service = new $class;
      $service-&gt;sendPost($post); 
  }
  </code></pre>
  <p>or</p>
  <pre><code>$post = Post::where('id', 44);
  $services = Service::get();
  
  foreach ($services as $service){
      $class = '\\App\\Adapters\\'.$service-&gt;name.'\\Post';
      $service = new $class;
      $service-&gt;deletePost($post-&gt;id); 
  }
  </code></pre>
  <p>Actually this aproach works but it doesn't seem (feel) to be the right way to go. Here for instance each time I need another service instead Post I would need to create another instance.</p>
  <pre><code>$class = '\\App\\Adapters\\'.$service-&gt;name.'\\Category';
  $service = new $class;
  $service-&gt;deletePost($post-&gt;id); 
  </code></pre>
  <p>I am looking more something like.</p>
  <pre><code>$service = new Service('ServiceA');
  $service-&gt;post-&gt;sendPost($post);
  $service-&gt;category-&gt;create($cat);
  </code></pre>
  <p>then I could</p>
  <pre><code>$post = Post::where('id', 44);
  $services = Service::get();
  
  foreach ($services as $service){
      $service = new Service($service-&gt;name)
      $service-&gt;post-&gt;deletePost($post-&gt;id); 
  }
  </code></pre>
  <p>I know this is not a very detailed representation but you get the idea. I want to consume multiple services and being able to implement it with my local system. So what is the right and best way to do this?</p>