title: Make sure that functions are called
body: <p>Im working on a project where we're creating many objects throughout the code base. </p>
  
  <p>For some objects thus we decided to use factories to control the process of creating the objects and all their dependencies. This is an example of what we are trying to do:</p>
  
  <pre><code>class CreateBranchFactory implements CreateBranchInterface {
  
      private $branch;
  
      public function __construct() {
          $this-&gt;branch = new Branch();
          $this-&gt;branch-&gt;scenario = 'create';
      }
  
      public function createBranch($branchForm) {
          $this-&gt;branch-&gt;attributes = $branchForm-&gt;attributes;
  
          //Example of all the things that I need to do after creating my object
          $this-&gt;setOfficialNameAndPrinterName($branchForm-&gt;official_name, $branchForm-&gt;printer_name, $branchForm-&gt;name);
          $this-&gt;createDependencies1();
          $this-&gt;someOtherFunction();
  
          return $this-&gt;branch;
      }
  
      public function setOfficialNameAndPrinterName($offName, $printerName, $branchName) {
          $this-&gt;branch-&gt;official_name = $offName ?? $branchName;
          $this-&gt;branch-&gt;printer_name = $printerName ?? $branchName;
          $this-&gt;branch-&gt;save();
      }
  
      public function createDependencies1() {
  
      }
  </code></pre>
  
  <p>And to have a proper contract I created an interface for this. This interface specifies the functions that should be defined </p>
  
  <pre><code>interface CreateBranchInterface {
  
      public function setOfficialNameAndPrinterName(String $offName, String $printerName, String $branchName);
  
      public function createDependencies1();
  }
  </code></pre>
  
  <p>My problem though, is that the contract is specifying all the functions that <strong>should be defined</strong>, but isnt controlling which functions <strong>should get called</strong>. Is there any design pattern that I can use, that makes sure that those functions get called?? </p>