class FlyBehaviour {
fly = () => {
// abstract
};
}
class QuackBehaviour {
quack = () => {
// abstract
};
}
class FlyWings extends FlyBehaviour {
fly = () => {
return <p>I can Fly</p>;
};
}
class NoFly extends FlyBehaviour {
fly = () => {
return <p>I cannot Fly</p>;
};
}
class QuackSound extends QuackBehaviour {
quack = () => {
console.log("Quacking");
return <p>Quack Quack</p>;
};
}
class Duck extends React.Component {
constructor(props) {
super(props);
QuackBehaviour q; // creating a reference to class QuackBehaviour
FlyBehaviour f ;
}
// some methods that use q and f references
}
This code is just to ask whether can we create references to classes and use them to call their respective methods. Can we do that in React js. If we can, what is the way to do that and if we can't...then why though ?