Skip to content

General Tips

Valk edited this page Aug 12, 2023 · 4 revisions

Decoupling Code

If a function has too many parameters consider creating a class to contain those parameters.

A class should only handle things related to itself and any of its dependencies but should never manage its dependents (unless you're following the component pattern). For this look into using the observer pattern.

Try to avoid creating a class that acts as a dumping ground for all sorts of public static data that's not related to each other. Instead try to keep the appropriate data related to the appropriate classes. This is not always clear on how to do.

If a function has more than 20 lines of code, then that function may be too long. Consider splitting that function up into smaller functions.

If all classes share similar functionality consider making all those classes extend from a abstract class.

Don't over engineer code. I'm looking at you reflection.

Common Mistakes

Clone this wiki locally