Generic Base Classes
Generic base classes contain reusable logic for PeopleCode classes; you write them to be self-contained, fully implemented, and capable of being instantiated directly. This differs from abstract base classes, which are not instantiated directly and need subclasses that override methods to provide specialized logic.
Some examples of classes that are good candidates for creating generic base classes are:
-
Service classes, which typically extend a class that provides infrastructure services, such as configurable application logging.
-
Data classes, which typically extend a class that enables you to plug in adapters to support sorting their instances with custom sort algorithms.
Even when a class does not seem generic because it only has a couple of subclasses, you can still define it in your design as a generic base class rather than cloning common code across different classes. The main reason is maintainability: it's easier to maintain a single class than trying to keep track of the same code scattered across your database.