I need to extend a class (in C++, but this question is language-agnostic I think), with functionality that can be implemented in two different ways:
- by simply adding the logic to the class itself
- by adding observer logic to the class and putting the logic in an observer, outside the class
There are advantages and disadvantages in both alternatives:
- since the code might be used for other classes as well, it seems more logical to add the logic in an observer. Future classes then only need to support observers.
- on the other hand, the impact of observers in calculation-intensive code is hard to foresee. New observers added later in the code, might have a negative impact in the calculation-intensive code.
Has anyone clear rules on when to add new functionality within the class, as opposed to putting it in an observer outside the class?