Organise method flow I have something like a shop. It is limited to a checkout page, which will send an email. Nothing big, but a nice thing to learn more OOP.

Almost every time I develop new classes I am wondering how to organize the flow of depending methods. Here is an example, a first draft of what I have:

&lt;?php

// Outside the class:
if (!empty($cms-&gt;request-&gt;post('add_to_cart'))) {
    $cart-&gt;addStrt();
}


OPTION A

// OPTION A: Build a "method chain" and move from one to the other, to the next …
Class Cart extends Shop {

    // This is the entry point and starts the "add process"
    public function addStart() {
        $this-&gt;checkQuantity(); // if qty is between min/max
        return false;
    }
    // Step 2
    public function checkQuantity() {
        if ($quantity &lt; $max &amp;&amp; $quantity &gt; $min) {
            $this-&gt;checkInStock(); // move on to the next step
        }
        return false;
    }
    // Step 3
    public function checkInStock() {
        if ($availabe &gt;= $qty_in_basket) {
            $this-&gt;addToCart(); // move on to the final step
        }
        return false;
    }
    // Step 4
    public function addToCart() {
        // Final step, all requirements ok
        $product_id = $this-&gt;request-&gt;post-&gt;product_id;
        $cart = $this-&gt;getCart();
        $product = $shop-&gt;getProduct($product_id);

        $cart-&gt;items-&gt;add($product);
        $added = $cart-&gt;save();

        return $added;
    }
}


OPTION B

// OPTION B: Have a single "add" method and check all requirements, sanitize, etc from a single method
Class Cart extends Shop {

    public function add() {
        $continue = $this-&gt;checkQuantity(); // if qty is between min/max
        if ($continue == false) return false;

        $continue = $this-&gt;checkInStock(); // if product still available
        if ($continue == false) return false;

        // Perhaps more checks, sanitize, etc.

        // Everythiing mus be ok, put item into cart
        $product_id = $this-&gt;request-&gt;post-&gt;product_id;
        $cart = $this-&gt;getCart();
        $product = $shop-&gt;getProduct($product_id);

        $cart-&gt;items-&gt;add($product);
        $added = $cart-&gt;save();

        return $added;
    }
}


I have read tutorials on some OOP patterns but can't seem to find which fits to my question. While Option B seems to be cleaner (to understand/extend) one thing I always read is never put multiple tasks into one method. Every method should only handle one specific task. But how/where do I control the flow?

Is this "Encapsulation" or "Decorator pattern" or "Dependency Injection"? I have no idea what I should google.
It's good to have single method to control flow as you have in B, but this method should be mostly calling other methods of your class (you also call there checkQuantity for example, which is also in A). That way add is still very flexible - you can override those methods (probably protected methods, not public), that it calls or as last resort override that method itself.

If you think B is more readable, imagine, there would be something like this-&gt;addToCart instead of this bit (and that extracted to separate method):

   $product_id = $this-&gt;request-&gt;post-&gt;product_id;
    $cart = $this-&gt;getCart();
    $product = $shop-&gt;getProduct($product_id);

    $cart-&gt;items-&gt;add($product);
    $added = $cart-&gt;save();


I'd google for "single responsibility principle".