0

I am making a program for studying chess openings, traps and maybe other related things. It has a class MoveSequence, which basically is an ordered list of objects from a class ChessPosition. I also have a class ChessOpening which has a sequence of moves and a name, an ECO-code (chess opening classification system) and probably some more stuff.

Should I implement ChessOpening as a subclass of MoveSequence, or should it just contain a MoveSequence object? The same question would apply for a class ChessTrap.

Don't think it matter so much what I choose in this simple problem. But I want to learn this stuff, so I was wondering if there is some principles, or rules of thumb, one should consider when making decision like this.

1 Answers1

0

My 0.02$ worth:

If a possible subclass does not share basically all of the properties and methods of its superclass, I start to wonder.

Overriding methods to change behavior, or adding new properties and methods is normal. But when you hit that awkwardness when some of the superclass properties/methods are not applicable to the subclass, it gets creepy. (What do you do then, just ignore the invalid/inappropriate parts? Hope no one ever calls them? Stub them out and raise an error if they are used?)

If xxx is not really a yyy, maybe xxx and yyy are both zzz's. (Or if they just share common behaviors, maybe create a module to include, which is a standard Ruby/Rails practice.)

A real Computer Scientist may have a more concise and definitive answer...

Tom Wilson
  • 797
  • 9
  • 26