Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You may use Factory Pattern. Basket, Billing and Delivery objects should be created by the 3rd-party service API wrapper class:</p> <pre><code>$svc = new The3rdPartyServiceApiWrapper(); $svc-&gt;init(); // connect, get session etc. if ($svc-&gt;fail()) die("halp! error here!"); $basket = $svc-&gt;createBasket(); $baskSumm = $basket-&gt;getBasketSummary(); $billing = $svc-&gt;createBilling(); $billSumm = $billing-&gt;getBillingSummary(); $delivery = $svc-&gt;createDelivery(); $delSumm = $delivery-&gt;getDeliverySummary(); </code></pre> <p>The best way to connect Basket, Billing and Delivery class with the API is storing a reference to the API class, then they can call any method of it, not just getSession().</p> <p>Another advantage is, that if you have an identified entity, e.g. a User, then the wrapper class can grant you, that there will be no double objects in the scene.</p> <p>If the main program creates the users, there should be different objects with the same user, which is wrong:</p> <pre><code>$user1 = new User("fred12"); $user2 = new User("fred12"); </code></pre> <p>VS if the API wrapper creates them, the wrapper class should keep a "cache" of users, and return with the same User object for the same request:</p> <pre><code>$user1 = $svc-&gt;createUser("fred12"); $user2 = $svc-&gt;createUser("fred12"); // $user2 will be the same object </code></pre> <p>(Maybe it's not a best example, if a program creates twice the same User, it means that the program has major design faulty.)</p> <p><strong>UPDATE:</strong> explanation of svc class</p> <p>The The3rdPartyServiceApiWrapper should look like this:</p> <pre><code> function getSessionId() { return $this-&gt;sessionId; // initialized by constructor } // getSessionId() function createBasket() { $basket = new Basket($this); return $basket; } // createBasket() </code></pre> <p>The Basket:</p> <pre><code> function Basket($s) { // constructor of Basket class $this-&gt;svc = $s; //... the rest part of constructor } // Basket() constructor function doSomethingUseful() { // if you wanna use the session: $sess = $this-&gt;svc-&gt;getSessionId(); echo("doing useful with session $session"); // you may access other api functions, I don't know what functions they provide $this-&gt;svc-&gt;closeSession(); } // doSomethingUseful() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload