mardi 22 janvier 2019

Extracting "SuperClass" or "Interface" ? Is there a "rule of thumb"?

When identifying same code in different classes, how do we decide if we should extract it into an interface or into a superclass ? As Interfaces can't hold any Properties is it that simle to say ("rule of thumb"):

If there is a common property for both classes we extract it into a superclass otherwise into an interface ?

Situation 1: I have 2 seperate classes with 1 identical named method , say calculateCost(). -> Interface

Situation 2: I have 2 seperate classes with 1 identical named method , say calculateCost() and we have id as a String. -> SuperClass

How do we decide to do what ?

Aucun commentaire:

Enregistrer un commentaire