I want to customize the behavior of an object before creating the object. I think maybe add some hooks in the constructor of the objects and make a change there will be a choice. Is there a way to do this in .net? Thank you very much in advance!
EDIT:
Here is an example:
Suppose we have a Kid class that uses the Perform method to get credit in the class.
public class Kid
{
public void Perform() { ... }
}
And the school gives lectures:
public class School
{
public void Chemistry() {
Kid tom = new Kid();
tom.Perform();
}
public void Biology() {
Kid tom = new Kid(); tom.Perform();
Kid jerry = new Kid(); jerry.Perform();
}
}
We want every child to do the same, and I do not want:
- Modify the Kid class because it is created from a third-party tool and is widely used elsewhere.
- Use inheritance.
source
share