void PureBreedDog_speak(PureBreedDog *self)
Direct, non-polymorphic speak implementation for PureBreedDog.
void makeSpeak(Animal *a)
Dynamic Dispatch via manual function-pointer vtable.
void interfaceCatSpeak(ISpeaker *self)
speak() implementation for InterfaceCat.
void InterfaceCat_init(InterfaceCat *c)
Initializes an InterfaceCat instance.
void directSpeak(PureBreedDog *explicitDog)
Scenario A: Monomorphic target - direct call, no vtable indirection.
void InterfaceDog_init(InterfaceDog *d)
Initializes an InterfaceDog instance.
void dogSpeak(Animal *self)
speak() implementation for Dog.
void DogWithDefault_init(DogWithDefault *d)
Initializes a DogWithDefault instance.
void dogWithDefaultSpeak(AbstractAnimal *self)
speak() implementation for DogWithDefault.
void Animal_sleep(AbstractAnimal *aa)
A concrete default function shared by all "subclasses".
void Dog_init(Dog *d)
Initializes a Dog instance, wiring its vtable pointer to dogSpeak.
void makeSleep(AbstractAnimal *aa)
Dynamic Dispatch using abstract parent pointer.
void catSpeak(Animal *self)
speak() implementation for Cat.
void makeSpeakInterface(ISpeaker *s)
Contractual Dispatch via manual function-pointer lookup.
void Cat_init(Cat *c)
Initializes a Cat instance, wiring its vtable pointer to catSpeak.
int main()
Entry point exercising all four polymorphism scenarios.
void interfaceDogSpeak(ISpeaker *self)
speak() implementation for InterfaceDog.
Abstract base "class" combining shared state and an abstract speak function pointer.
void(* speak)(struct AbstractAnimal *)
Base "class" simulated as a struct holding a speak function pointer.
void(* speak)(struct Animal *)
"Subclass" of Animal that meows.
"Subclass" of Animal that barks.
Concrete AbstractAnimal "subclass" that implements speak().
Interface contract simulated as a struct holding only a function pointer.
void(* speak)(struct ISpeaker *)
ISpeaker implementation that meows.
ISpeaker implementation that barks.
The sole concrete "speaker" type; no vtable is needed.