I have an 8-level hierarchy of classes in Java. This is useful so each abstract class implements methods that are common in the whole sub-branch of the tree. That's working fine.
However, after going back and forth with some design I realized some behavior is applied very discretionary to some leaf nodes only. There's no clear rule, that could follow the existing hierachy. I have identified these leaf classes and I wanted to understand what's the best way of implementing those, since the logic is EXACTLY the same one every time.
For example, in the simplified example below only the green leaf classes should implement the method.
If I create a separate interface with the abstract method declaration I could mark all those leaf classes to implement the method.
How can I place the logic in the new interface somehow? I don't want to copy the same code 80 times, in each affected tree class.