mardi 4 juillet 2017

Best practice to implement classes if every object behaves differently in Java

Let's take a real-world example.

Suppose, I have three Dogs, but one dog can differ from the other.
The first dog likes barking and eating, the second dog likes playing and chasing cats and the third dog likes running and jogging (consider these actions as methods).

How do I implement this in Java? What I have to use, what is the best practice? Abstract classes, interfaces or both of them?

Aucun commentaire:

Enregistrer un commentaire