lundi 7 décembre 2020

Do classes that set, get and calculate data follow the S in SOLID?

Supposing I live in a country where every car brand has a different tax rate, and I have a base class called Car

public class Car{
    public string CarType { get; set;}
    public int Year {get; set;}
    public abstract double calculateSalesTax();
}

Would it be OK to add an abstract method to calculate the sales tax? Or does that already breaks the SOLID principle? A usual guideline for S in SOLID is "If you have to use the word AND when describing your class, it's most likely breaking the principle". Here, the implementation of a method to calculate sales tax seems to be requiring that AND. This class sets the attributes of the car AND calculates its sales tax.

So If I implement the derived class

public class Volkswagen : Car{
    
    public override double calculateSalesTax(){
         //Something to calculate a VWs tax
    }
}

is it already breaking the S in SOLID?

Aucun commentaire:

Enregistrer un commentaire