vendredi 30 mars 2018

How to name factory that has multiple creation methods?

I have the factory with multiple creation methods in.

interface IProductFactory
{
     IProduct CreateX();
     IProduct CreateY(A a, B b);
     IProduct CreateZ(A a, C c);
     IProduct CreateAutoUpdatableProduct(
                  // Func<string, IProduct> is C# friendly type
                  // From abstract view it is
                  // single method that returns the product
                  // or interafcse with this single method
                  Func<string, IProduct> productFactory,
                  IEnumerator<string> configProvider)
}

In this level everything looks fine, but I have name conflict in implementation level.

class ProductFactory : IProductFactory
{
     ...
     IProduct CreateAutoUpdatableProduct(
                      Func<string, IProduct> productFactory,
                      IEnumerator<string> configProvider)
    {
         return new AutoUpdatableProduct(
                        productFactory,
                        configProvider,
                        this);
    }

    class AutoUpdatableProduct : IProduct
    {
        AutoUpdatableProduct(Func<string, IProduct> productFactory,
                             IEnumerator<string> configProvider,
                             IProductFactory productFactory)
        {
              // two parameters with name productFactory above
        }
    }
}

As you can see in code excuse, I have two parameters with the same name in the constructor of AutoUpdatableProduct. Obviously, there is necessary to rename one of them. And here I am stumbled upon the question: What is product factory in my case? Func or IProductFactory? Based on the classical factory pattern i think that true factory is Func. How to rename my interface IProductFactory? IProductCreationService?

Aucun commentaire:

Enregistrer un commentaire