the use of patterns - singleton, factory RRS feed

  • Question

  • User-2132746437 posted

    When Building a web application how many use the Singleton or Factory patterns when developing the app? What are the pros and cons using them for a web application?


    I'm asking due to I'm looking at an asp.net web app that has 6 layers in the application and is using a mix of the singleton and factory patterns and to me, it looks like a tad bit of overkill for a web app that is just reading data from a database with some business rules in the app.

    Thursday, February 14, 2013 10:43 AM


  • User1109032460 posted

    Firstly, Singleton is one of the most mis-used patterns. I'm always sceptical when I see Singleton being used, and require some convincing that it is actually appropriate. In an IoC world, singleton-ness can often be achieved by using an appropriate lifetime manager with the container.

    When you say "Factory pattern" what do you mean?

    There is no Factory pattern, per se. There is Abstract Factory and Factory Method, and the commonly used, but not GoF pattern, "Simple Factory".

    Both Abstract Factory and Factory Method have their place - just look at the implementation of ADO.NET Managed Providers - and Simple Factory is extremely common. So I would expect to see these cropping up quite regularly.

    After all, new is a horror keyword when it comes to building loosely-coupled applications, so some form of factory mechanism is often required in order to minimise its use.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 15, 2013 5:38 AM