Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. in which scenario people use factory design patter

in which scenario people use factory design patter

Scheduled Pinned Locked Moved C#
questioncomdesignregexarchitecture
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tridip Bhattacharjee
    wrote on last edited by
    #1

    we know that in factory design patter we do not create object of any class directly rather create instance of a class by factory class. The client is an object that requires an instance of another object (the product) for some purpose. Rather than creating the product instance directly, the client delegates this responsibility to the factory. Once invoked, the factory creates a new instance of the product, passing it back to the client. Put simply, the client uses the factory to create an instance of the product. i read this article https://msdn.microsoft.com/en-us/library/ee817667.aspx?f=255&MSPPError=-2147217396 i am looking for a write up on factory design patter which show me when i need to create instance by factory because we can create instance directly but in factory design pattern instance create via factory. so what is the significance of factory design patter. so if anyone search google there is many article exist on factory design pattern but i do not find any article which tell me scenario when i will not create instance directly rather will create instance via factory. so please tell me few scenario with example code from where i can see when people would not prefer creating instance of any class directly rather will create instance via factory. thanks

    tbhattacharjee

    L 1 Reply Last reply
    0
    • T Tridip Bhattacharjee

      we know that in factory design patter we do not create object of any class directly rather create instance of a class by factory class. The client is an object that requires an instance of another object (the product) for some purpose. Rather than creating the product instance directly, the client delegates this responsibility to the factory. Once invoked, the factory creates a new instance of the product, passing it back to the client. Put simply, the client uses the factory to create an instance of the product. i read this article https://msdn.microsoft.com/en-us/library/ee817667.aspx?f=255&MSPPError=-2147217396 i am looking for a write up on factory design patter which show me when i need to create instance by factory because we can create instance directly but in factory design pattern instance create via factory. so what is the significance of factory design patter. so if anyone search google there is many article exist on factory design pattern but i do not find any article which tell me scenario when i will not create instance directly rather will create instance via factory. so please tell me few scenario with example code from where i can see when people would not prefer creating instance of any class directly rather will create instance via factory. thanks

      tbhattacharjee

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Tridip Bhattacharjee wrote:

      i am looking for a write up on factory design patter which show me when i need to create instance by factory because we can create instance directly but in factory design pattern instance create via factory. so what is the significance of factory design patter.

      A nice idea would be to create a factory if there are more than a single class than can be used to perform the action. Simple and usefull example can be found in the DbProviderFactory. Instead of programming against the SqlConnection and SqlCommand, you program against the interfaces IDbConnection and IDbCommand. Next, let the factory decide which actual class to create. That way the user can configure suddenly whether to use the SqlConnection, an OracleConnection, or something completely different. Another nice idea for factories is that they can also be combined with the Object Pool Pattern. See the TaskFactory for a nice example of that. It's similar to the strategy-pattern, with the difference that a factory is for creating objects.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      T 1 Reply Last reply
      0
      • L Lost User

        Tridip Bhattacharjee wrote:

        i am looking for a write up on factory design patter which show me when i need to create instance by factory because we can create instance directly but in factory design pattern instance create via factory. so what is the significance of factory design patter.

        A nice idea would be to create a factory if there are more than a single class than can be used to perform the action. Simple and usefull example can be found in the DbProviderFactory. Instead of programming against the SqlConnection and SqlCommand, you program against the interfaces IDbConnection and IDbCommand. Next, let the factory decide which actual class to create. That way the user can configure suddenly whether to use the SqlConnection, an OracleConnection, or something completely different. Another nice idea for factories is that they can also be combined with the Object Pool Pattern. See the TaskFactory for a nice example of that. It's similar to the strategy-pattern, with the difference that a factory is for creating objects.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        T Offline
        T Offline
        Tridip Bhattacharjee
        wrote on last edited by
        #3

        thanks for nice answer. can you please include a article link sir which show how i can use DbProviderFactory to connect sql server ,oracle, oldedb or use dsn to connect any db. thanks

        tbhattacharjee

        P L 3 Replies Last reply
        0
        • T Tridip Bhattacharjee

          thanks for nice answer. can you please include a article link sir which show how i can use DbProviderFactory to connect sql server ,oracle, oldedb or use dsn to connect any db. thanks

          tbhattacharjee

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          I assume Google is broken for you. Seriously, you have been posting on this site long enough to indicate that you are meant to be a professional programmer. Part of being a professional programmer is having the ability to do research for yourself.

          This space for rent

          1 Reply Last reply
          0
          • T Tridip Bhattacharjee

            thanks for nice answer. can you please include a article link sir which show how i can use DbProviderFactory to connect sql server ,oracle, oldedb or use dsn to connect any db. thanks

            tbhattacharjee

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Too bad ... You were doing so well up to this point. You seem to think noone has anything better to do than run down errands for you.

            "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

            1 Reply Last reply
            0
            • T Tridip Bhattacharjee

              thanks for nice answer. can you please include a article link sir which show how i can use DbProviderFactory to connect sql server ,oracle, oldedb or use dsn to connect any db. thanks

              tbhattacharjee

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              A simple example of using DbProviderFactory can be found here[^]. Since you already worked with databases I'm going to assume that you'll recognize most parts; note that we ask the Factory to create a connection for us, instead of creating one ourself. The factory can also create IDbCommands, but I prefer to use the factory-method that is provided in the IDbConnection-interface. Details on the class can be found on MSDN[^]. The factory does NOT make your code database vendor-independant - it just makes it easier to switch between those classes. Your C# code would no longer depend on a specific implementation, but chances are that you are using an SQL dialect that is specific to the database-server. Stick to SQL92 if you want to minimize the risc of incompatibilities.

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups