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. Design and Architecture
  4. Desgin pattern...

Desgin pattern...

Scheduled Pinned Locked Moved Design and Architecture
designregexarchitecturequestion
16 Posts 5 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.
  • 1 Offline
    1 Offline
    1 21 Gigawatts
    wrote on last edited by
    #1

    Good morning!! What's the design pattern whereby you have to go through a certain class to get an instance of another? E.G, I have a class called Devices, and classes Valve, PID, ControlVlv and Pump. I don't want to be able to instantiate Valve, Pump etc without going through Devices (which will return a collection of said classes). But I want to be able to use said classes throughout the app. Does that make sense? I'm sure I've done it before.... Thanks, :-D

    L 1 Reply Last reply
    0
    • 1 1 21 Gigawatts

      Good morning!! What's the design pattern whereby you have to go through a certain class to get an instance of another? E.G, I have a class called Devices, and classes Valve, PID, ControlVlv and Pump. I don't want to be able to instantiate Valve, Pump etc without going through Devices (which will return a collection of said classes). But I want to be able to use said classes throughout the app. Does that make sense? I'm sure I've done it before.... Thanks, :-D

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, sounds like a Factory to me. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Voting for dummies? No thanks. X|


      1 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, sounds like a Factory to me. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        1 Offline
        1 Offline
        1 21 Gigawatts
        wrote on last edited by
        #3

        Ye :) ah I thought that, just can't seem to find the right one!

        P 1 Reply Last reply
        0
        • 1 1 21 Gigawatts

          Ye :) ah I thought that, just can't seem to find the right one!

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

          You've got the right surname to be talking about patterns. ;) Sounds like you need to consider using something like the Abstract Factory pattern.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          L 1 Reply Last reply
          0
          • P Pete OHanlon

            You've got the right surname to be talking about patterns. ;) Sounds like you need to consider using something like the Abstract Factory pattern.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            This one has puzzled me before. Valves, pumps, and the like sound very concrete, yet they want to call it an abstract factory? :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Voting for dummies? No thanks. X|


            P L 2 Replies Last reply
            0
            • L Luc Pattyn

              This one has puzzled me before. Valves, pumps, and the like sound very concrete, yet they want to call it an abstract factory? :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              Voting for dummies? No thanks. X|


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

              I know. It's a really crappy name. Really really crappy.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              L D 2 Replies Last reply
              0
              • L Luc Pattyn

                This one has puzzled me before. Valves, pumps, and the like sound very concrete, yet they want to call it an abstract factory? :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Voting for dummies? No thanks. X|


                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                Luc Pattyn wrote:

                yet they want to call it an abstract factory?

                What are you guys talking about? Isn't the pattern supposed to use the implementation of an abstract class for the factory and the user derives from it implementing the concrete factories? Or am I not remembering the pattern correctly?

                led mike

                P 1 Reply Last reply
                0
                • P Pete OHanlon

                  I know. It's a really crappy name. Really really crappy.

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #8

                  I'm confused[^]

                  led mike

                  1 Reply Last reply
                  0
                  • L led mike

                    Luc Pattyn wrote:

                    yet they want to call it an abstract factory?

                    What are you guys talking about? Isn't the pattern supposed to use the implementation of an abstract class for the factory and the user derives from it implementing the concrete factories? Or am I not remembering the pattern correctly?

                    led mike

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

                    You are remembering it correctly. It's just a name that I have a problem with just because it sounds like you can directly instantiate abstract classes. I'm not sure what they should call it, but I've had staff being confused about this when they complain about their code not working because it's abstract.

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    L 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      You are remembering it correctly. It's just a name that I have a problem with just because it sounds like you can directly instantiate abstract classes. I'm not sure what they should call it, but I've had staff being confused about this when they complain about their code not working because it's abstract.

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      L Offline
                      L Offline
                      led mike
                      wrote on last edited by
                      #10

                      Pete O'Hanlon wrote:

                      but I've had staff being confused about this when they complain about their code not working because it's abstract.

                      Sorry to hear that. On the bright side at least you work with people that use the word "Abstract"! That's more than I can say! :((

                      led mike

                      P 1 Reply Last reply
                      0
                      • L led mike

                        Pete O'Hanlon wrote:

                        but I've had staff being confused about this when they complain about their code not working because it's abstract.

                        Sorry to hear that. On the bright side at least you work with people that use the word "Abstract"! That's more than I can say! :((

                        led mike

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

                        led mike wrote:

                        at least you work with people that use the word "Abstract"! That's more than I can say!

                        Ouch. X|

                        Deja View - the feeling that you've seen this post before.

                        My blog | My articles

                        L 1 Reply Last reply
                        0
                        • P Pete OHanlon

                          led mike wrote:

                          at least you work with people that use the word "Abstract"! That's more than I can say!

                          Ouch. X|

                          Deja View - the feeling that you've seen this post before.

                          My blog | My articles

                          L Offline
                          L Offline
                          led mike
                          wrote on last edited by
                          #12

                          Dude, it looks like you are being stalked by a 2.0 voter? Even I don't have a stalker! :laugh::laugh:

                          led mike

                          P 1 Reply Last reply
                          0
                          • L led mike

                            Dude, it looks like you are being stalked by a 2.0 voter? Even I don't have a stalker! :laugh::laugh:

                            led mike

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

                            led mike wrote:

                            Dude, it looks like you are being stalked by a 2.0 voter? Even I don't have a stalker!

                            Damn. I'm not even worthy of a Univoter. :laugh:

                            Deja View - the feeling that you've seen this post before.

                            My blog | My articles

                            D 1 Reply Last reply
                            0
                            • P Pete OHanlon

                              I know. It's a really crappy name. Really really crappy.

                              Deja View - the feeling that you've seen this post before.

                              My blog | My articles

                              D Offline
                              D Offline
                              dojohansen
                              wrote on last edited by
                              #14

                              Nooooo. It is a good name, though just as good and maybe better would be static factory. The factory itself is usually a class with only static methods, so it should be static (or abstract, though static is perhaps the more academically pleasing choice since it's not intended as a base class for concrete factories but rather just a bunch of static members relating to the same thing). So even though the products of the factory are concrete, the factory itself isn't. Pump p = Factory.CreatePump(...); not Factory f = new Factory(); Pump p = f.CreatePump(...); Normalement.

                              P 1 Reply Last reply
                              0
                              • P Pete OHanlon

                                led mike wrote:

                                Dude, it looks like you are being stalked by a 2.0 voter? Even I don't have a stalker!

                                Damn. I'm not even worthy of a Univoter. :laugh:

                                Deja View - the feeling that you've seen this post before.

                                My blog | My articles

                                D Offline
                                D Offline
                                dojohansen
                                wrote on last edited by
                                #15

                                I often accidentally vote 2.... when a little spaced out it is far too easy to think, as you arrive at the last message, that those numbers represent pages. So I try to navigate to page 2, and get "thank you for voting"..! I must apologize to any victims (none today tho). :D

                                1 Reply Last reply
                                0
                                • D dojohansen

                                  Nooooo. It is a good name, though just as good and maybe better would be static factory. The factory itself is usually a class with only static methods, so it should be static (or abstract, though static is perhaps the more academically pleasing choice since it's not intended as a base class for concrete factories but rather just a bunch of static members relating to the same thing). So even though the products of the factory are concrete, the factory itself isn't. Pump p = Factory.CreatePump(...); not Factory f = new Factory(); Pump p = f.CreatePump(...); Normalement.

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

                                  This[^] message explains my problem with the name. I prefer the static name you suggest though - it sounds better.

                                  Deja View - the feeling that you've seen this post before.

                                  My blog | My articles

                                  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