I have an abstract class with some methods,including an abstract method(Execute()).This method is overridden in child class.Now, an event is raised(somewhere in application),and for this event there is a handler in base class.And,in this handler,I call Execute.
Now, the method of chilobject is executed.I am bit confused,how this works under the hood?
I have an abstract class with some methods,including an abstract method(Execute()).This method is overridden
Share
One way to think of this is in terms of message passing; the call of
Execute()inside an instance method means that the “message”Executeis sent to the current object (i.e.this). Since the current object is an instance of the child class, it treats the received message “Execute()” as is defined for all instances of that class, regardless of where the command to send that message is written.(If your question was how it’s technically implemented, then I’m sorry for the simplistic answer. In very general terms the class of the object is stored with the rest of its data and this is used to look up the appropriate method to call, i.e. how to react to a certain message to that object.)