Hi all,
I want to customize a object's behavior before the object is created. I think maybe add some hooks in the object constructor and do the change there would be a choice. Is there any way to do so in .net? Thanks a lot in advance!
EDIT:
Here is a example:
Assume we have a class Kid which use Perform method to get credit in the class.
public class Kid
{
public void Perform() { ... }
}
And the School conduct to lectures:
public class School
{
public void Chemistry() {
// The school have a good chemistry teacher, so every kid study well
// Kid.Perform() is modified to reflect that
Kid tom = new Kid();
tom.Perform();
}
public void Biology() {
//This class is boring, everyone will nap in 5~10 min
// Kid.Perform() use a random number to simulate how
//long this kid can hold it.
Kid tom = new Kid(); tom.Perform();
Kid jerry = new Kid(); jerry.Perform();
}
}
We want every kid perform in the same way and I do not want:
- Change class Kid because it is generated from a 3rd party tool and widely used somewhere else.
- Use inheritance.