paulszefer / Ecosystem-Simulation

MIT License
0 stars 0 forks source link

Implementing higher level interfaces inhibits functionality #5

Open paulszefer opened 7 years ago

paulszefer commented 7 years ago

Hi Chris, I am continuing on the path of refactoring in order to program to interfaces, and I am at the point of refactoring the simulation to use a Habitat interface instead of a Pool. I have two problems with this:

  1. A habitat does not necessarily have water. By implementing the habitat, that means that I can no longer interact with my pool under the assumption that it has water. This breaks a few functionalities including our overcrowding implementation. How do you implement more abstract interfaces without losing your current functionality like this? Do you need to limit your application by deciding that it is an aquatic ecosystem simulator and that the highest level of habitat implemented will be an AquaticHabitat?

  2. Our original design consisted of Pools containing Guppies. As we abstract these concepts to Habitats and Creatures, how do we ensure that a LandCreature does not get added to a Habitat that completely consists of water or vice-versa?

chris-thompson commented 7 years ago

Great questions. Some quick thoughts. Can a Pool implement Habitat and also something that causes it to be treated as an aquatic environment? I can think of a few ways to prevent terrestrials from being added to an aquatic environment. A quick suggestion is to have some sort of interface for aquatics that is used as the type for the collection inside an aquatic environment (polymorphism...).