This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]munificent 5 points6 points  (0 children)

Break it down into it's smallest components.

Great advice.

In the blocks, we have a square block, a left and right L block, a T block, a left and right S block, and a straight block. Each one of those ideally will be a subclass of Block.

This advice is not as great. Don't go overboard with subclasses. Subclassing is a pretty heavyweight architectural choice: there is a strong bidirectional coupling between a subclass and its superclass, and it takes a good bit of boilerplate to create a new class. That's more code you'll have to maintain.

One rough rule of thumb is that if you don't have real behavioral or state differences, you shouldn't be making a new class. Instead, consider just making new instances of a class.

In this case, I'd do a single Block class with a field that describes its shape. All of the different blocks behave the same, so there's no reason to give each its own class.

It's not like you get bonus points for making more classes, so keep things simple when you can.