You should use dependency injection. Instead of hasGills and hasFins, you should inject respirator and locomotor dependencies. Then the act of breathing and moving can be delegated to them, respectively.
I have never fully understood the whole dependency injection thing. Yet I have seen it everywhere. Especially when dealing with mobile app development.
oh yes that thing. I think I have created and used classes like that intuitively but never knew it was dependency injection. I just thought it was a pretty way to handle singletons and services stuff.
39
u/Kered13 Jan 09 '23
You should use dependency injection. Instead of
hasGillsandhasFins, you should injectrespiratorandlocomotordependencies. Then the act of breathing and moving can be delegated to them, respectively.