Hi I was watching a video on the "strategy pattern" and I understand his explanation on paper but I have no idea how it would look in code because I have never worked with interfaces before and his example relies heavily on the use of interfaces.
Here is a screen shot of the UML diagram as a reference:
The goal was to have different implementations of the quack() method. SimpleQuack and NoQuack
How would this look in Java code? Lets say that the City Duck class implements SimpleQuack where as Wild Duck implements NoQuack.
And why is it beneficial to use an interface to achieve this instead of defining the behavior in the inherited class like one would normally do.
Aucun commentaire:
Enregistrer un commentaire