mercredi 26 juillet 2023

Should abstract superclass contain protected non-abstract methods which are to be used by some and not all subclasses

I have an abstract class as below -:

public class AbstractClass{
   
    private String getA(){
       return "A";
    }
    
    protected String getB(){
        return getA().concat("-B");
    }

}

Now, all subclasses will use getB() method. That is why I have made it as protected. But not all subclasses will use getA() method. Only a subset will use it. So, should I still make it protected or keep it private?

Aucun commentaire:

Enregistrer un commentaire