lundi 13 avril 2020

factoryclass that Responsible for creating the classes that implemnts the same Interface but with different parameters in the constructor

I have this scenario for example:

public interface IBInterface
{
    void f1();
}

public interface IAInterface<T>
where T: IBInterface
{
    void f2();
}

public class point
{

}

public class B1: IAInterface<A1>
{
    private point _point;
    public B1(point point)
    {
        _point = point;

    }
    public void f2()
    {
        System.Console.WriteLine("B1-f2-A1");
    }
}

public class B2 : IAInterface<A2>
{
    private int _num;
    private string _str;
    private bool _flag;
    public B2(int num, string str, bool flag)
    {
        _num = num;
        _str = str;
        _flag = flag;

    }
    public void f2()
    {
        System.Console.WriteLine("B2-f2-A2");
    }
}
public class A1 : IBInterface
{ 
    public void f1()
    {
        System.Console.WriteLine("A1-f1");
    }
}


public class A2 : IBInterface
{
    public void f1()
    {
        System.Console.WriteLine(" A2-f1");
    }
}

Like class B1 and B2 I have more classes that implement interface IAInterface that T can be different types and Each has different parameters in the constructor. I want to create a factoryclass that Responsible for creating the classes that implement IAInterface and I wonder what is the best way to do this without writing constructor to each class that implement IAInterface

Aucun commentaire:

Enregistrer un commentaire