Note that there are some explanatory texts on larger screens.

plurals
  1. POImproving class structure in PHP instead of using multiple inheritance
    text
    copied!<p>I have a design problem where my classes are set up in such a way:</p> <pre><code>abstract class Advertiser abstract class AdvertiserCampaign | | | | class AdvUno extends Advertiser class AdvUnoCampaign extends AdvertiserCampaign class AdvDos extends Advertiser class AdvDosCampaign extends AdvertiserCampaign class AdvTre extends Advertiser class AdvTreCampaign extends AdvertiserCampaign </code></pre> <p>The problem is that <code>AdvUno</code> and <code>AdvUnoCampaign</code> both need a special authentication method that's not necessary for the others. Right now I've placed it in <code>AdvUno</code>, but again, it'll be needed by <code>AdvUnoCampaign</code> (and a bunch of other classes that are set up in this way).</p> <ul> <li>I can't make <code>AdvUnoCampaign</code> extend <code>AdvUno</code> since there's no multiple inheritance in PHP, but also because it's just generally not a good, clean design practice.</li> <li>If I make <code>AdvertiserCampaign</code> extend <code>Advertiser</code>, then all of the extending classes below (<code>AdvUnoCampaign</code>, <code>AdvDosCampaign</code>, etc) must implement a bunch of abstract methods that are of no concern to them, and which are already implemented in each of the <code>Advertiser</code> classes.</li> </ul> <p>In short, what's the best design practice in this sort of situation? I'd rather not just copy and paste the code into all of the <code>AdvOne</code> classes. Any help or advice would be appreciated. Thanks!</p>
 

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