An object-oriented approach is recommended. At a minimum, when designing the code, each component should have one or more classes that encapsulates the desired functionality. There are many ways to design software. Here are a few techniques, but by no means an exhaustive list:
- Design it with simple concrete classes which provides the advantages of simple design, fast coding, easy to understand, and easy maintenance.
- Design with inheritance one or more layers down. Break functionality down with subclasses that use polymorphic calls. The advantage of this approach is that if properly designed, it can make the code easier to understand and maintain for larger projects. However, some studies have shown that going down more than 3 levels of inheritance is counterproductive.
- Design it with a concrete class that incorporates algorithms. The advantage to this approach is that less code usually needs to be written and a very elegant solution can sometimes be found. Variations of algorithms are data driven design and pre-calculating all of the possible outputs of a long-running algorithm, writing them out to a file, and reading them into an array or container in memory at the start of the program. The advantage of this approach is performance. The drawbacks are it is harder to understand, maintain, and code.