views:

36

answers:

1

In my current project, there are lots of Factory Methods,

so when the program begin it has:

Init()
{
  RegisterFactory(A1);
  RegisterFactory(A2);
    ...
  //hundreds of Register.
    ...
}

Is there any other way to do this? It looks not reasonable.

+3  A: 

Consider using some dependency injection framework:

  • Java: Google Guice, Spring, more
  • .Net: Spring.NET, more

They usually externalize the burden of registering factories manually and do much more stuff.

Boris Pavlović