This is my problem: I have a Class A that is used (instantiated) several times within a Class B.
I need to change the behaviour of the Class A, mainly the constructor, and then I derived it with Class C. Class C: Class A
I would like that Class B using in its methods Class C instead of Class A, avoiding to override all the methods that used it. Is it this possible?
Many thanks
I was not clear, therefore let me try to explain better with code.
Public Class A
{
`// Simple constructor
public A(params[])
{
// things here
}
}
Public Class C : A
{
// Constructor doing different thing then base
public C(params[]): base(params[])
{
// do different things here
}
}
Public class B
{
public B(params[])
{ }
public method_A(params[])
{
A _temp = new A(params[]);
// do things here with A
}
}
I use B in my program, but I would like that for one istance of B it uses A and for another instance of B it uses C instead of A.
Something like:
Main()
{
B _instance1 = new B();
B _instance2 = new B();
// use instance 1
_instance1.method_A(...);
// use instance 2
_instance2.method_A(...); // do something here for using C instead of A in the method
}