lexil asked: How many classes do you have in MineCraft?
Our Java lecturer is encouraging us to make a squintillion different classes which seems somewhat wasteful to me. (I guess I'm too used to Entities in Source and Lua's version of objects, both of which have a relatively high cost when created)
Could you give a rundown of the various classes you use?

The game has about 300 classes at the moment. Making many classes for the sake of it is wasteful, I only add new classes or interfaces when it’s needed by the code.

Now, if you’ll pardon my tangent, here are my thoughts on reasons for splitting code up into classes:

* Encapsulation. You can hide internal workings of units of code. This makes sure your code is easy to modify and gives you the ability to replace bits if needed.

* Code re-use. If you end up calculating, say, PI a lot in several different places, it would probably be a good idea to make a PiCalculator class.

* Polymorphism. This is the only reason to ever subclass a class. If you want to use some other class, having an instance of that class in your class is probably better than extending the class. Polymorphism, when used correctly, is a wonderful way of making your project easy to expand.

* Readability. Assuming you name things correctly, it’s a lot easier to find stuff when it’s properly split up into understandable classes.

Please note that this only applies to Java. In C++, you can do three of these without using classes by just managing your files carefully.

posted 13 years ago