子類別具備提供資料結構的變體與多型行為等優點,但隨著時間演變,它可能已失去其變異性(Difference)。
移除它,轉為超類別欄位才能有效降低程式碼複雜度。

Remove Subclass

# Before
class Animal:
    pass

class Dog(Animal):
    def bark(self):
        print("Bark!")

class Cat(Animal):
    def meow(self):
        print("Meow!")

# After
class Animal:
    def __init__(self, animal_type):
        self.animal_type = animal_type

    def make_sound(self):
        if self.animal_type == "dog":
            print("Bark!")
        elif self.animal_type == "cat":
            print("Meow!")