What design pattern should I use for specific multiple inheritance?

Let's say I have an interface called Squid.

And we have a bunch of different types of squids:

Here's everything a squid can be:


How would I go about create an instance of a squid? Should I go about creating 4 classes BasicAquaticSquid, BasicLandSquid, AdvancedAquaticSquid, AdvancedLandSquid like this:

I think that's called the Abstract Factory method? It seems very tedious though. Any better way of doing so?


You are viewing a single comment. View All
Answered by xxpertHacker [earned 5 cycles]
View Answer

@DynamicSquid The idea isn't restriction at all, more likely, it's explicitness.

Often times, in source code, when you see something weird, one of thee things are true:

  • You stopped and said, "what am I looking at?"
  • There is a comment explaining the apparent nonsense, explaining that it is not nonsense, but some weird technique.
  • You actually understood what you saw, because you've seen it before, or had actually done it before.

If you've ever seen a weird piece of code before, you should agree.

The first possibility is very likely, and it exists because languages let people do weird stuff. This possibility does not exist within Rust.

The second exists for the same reason as the first and is due to a lack of language-level support for whatever they did, or because they were lazy. What if you provide language-level support for this?

The third possibility is very unlikely and doesn't need to exist, because weird code practice shouldn't need to exist.