Skip to main content
1 of 3
Helena
  • 827
  • 7
  • 11

Like dave points out in the comments, I believe you question is too abstract to be answered. I took the liberty turn it into a concrete (but still simplified) example.

class Pet {...} // accessors inside
class Cat extends Pet {...} // accessors inside
class Hamster extends Foo {...} // accessors inside

class PetFeeder {
    void feedPet(Pet pet) {
        if(pet instanceof Cat) {
            this.feedChicken(pet);
        }
        if(pet instanceof Hamster) {
            this.feedCarrots(pet);
        }
        throw;
    }
    void feedChicken(Pet) { ... }
    void feedCarrots(Pet) { ... }
}

So what is the problem with this code? It is tightly coupled; whenever you want to add a new type of pet you also have to adjust PetFeeder, even for tiny changes like changing the name of Cat

Helena
  • 827
  • 7
  • 11