Results 1 to 5 of 5

Thread: Singleton and factory?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Singleton and factory?

    Hi!

    I was wondering, if I develop an ASP.NET application (or vb.net C/S), can anyone point me to a page, or give a quick example how I can benefit from using the factory and singleton patterns? I already use the MVC pattern for the overall structure. Are they applicable here in this scenario?

    Its a standard database-driven application using 3-tire layering

    kind regards
    Henrik

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Not sure what 3-tire layering is , but the desing patterns that you mention are separate from your 3 tier MVC architecture. They wouldn't have an effect, because they are implemented in your business tier. Singleton would let you only create one instance of a particular class (which is usefull if you want all objects to use the one instance) and Factory abstracts the creation of objects by taking in a request and then determining what object should be created and sending it back. Both are very useful, you just need to decide if they will benefit your scenario.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    but when is it useful to use the factory pattern? I think I use it when I enable data access to my pages.. I have a static class wich accepts a database name as parameter and return a connection object (sql)

    I guess that is due to the factory pattern??

    /Henrik

  4. #4
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Yes, that is a type of factory pattern. All your code doesn't have to know which connection object it should use, it just passes the parameter to your static class and gets the correct one back to use. You could also implement it as a class that all your page requests call, and then the page is returned through that class.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    So I see...

    Another question on a slightly different matter. As I strife towards designing good programs, I often try to use polymorphism as often as I can. And one way to implement polymorphism is to make use of interfaces.

    For example, I have a method within a class that is called PrintResults (asp.net) which takes a datareader INTERFACE as in parameter, and then spit out the results with Response.writes...

    I also have a method which is called GetResults, which fetch information from a database (with factory patter for dbconn) and store it in a datareader. I then return the INTERFACE of this datareader.


    Is this the correct way to implement polymorphism? When should I work with interfaces instead of ordinary objects?

    kind regards
    Henrik

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width