Let me try.
No, we have no problem with encapsulation. You define a class that is responsible for Execute . Executer knows nothing about what is actually being executed. He only knows that he has to do DoSomething . What DoSomething does is indicated in the class responsible for doing something.
As I said, it is very similar to what you would do with Thread . You define a method that should be executed in another thread. Therefore, the class has a Thread and determines which method should be run in this thread. Thread still knows nothing about the class in which it plays a role.
Relations are class => Thread. Not the other way around.
In your example, the relationship NeedToBeExecuted => Executer . And not vice versa.
The concept may be complicated for your mind, but you are not doing anything wrong.
source share