Results 1 to 6 of 6

Thread: what exactly are "factories"?

  1. #1

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    Question what exactly are "factories"?

    a couple of times while just looking up stuff in the JavaDocs i came across various classes named something FACTORY, what exactly is the concept of the factory, like a stream isn't a class but a concept so i'm wondering if ne1 knows the dilly-yo behind "factories"
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    kinda hard to explain, but here goes...

    they're pretty much just ready made classes that are used to access a specific interface, so u don't have to worry about doing it yourself.
    e.g the BorderFactory is made up of static classes that return a Border (interface) object, which u can then use to (suprise suprise) set the border of a GUI component





    B

  3. #3

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    i think i'm getting it.... anyone else?
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    I think axion_sa pretty much summed
    it up. I don't know the exact definition
    but they seem to give you a handle to
    a specific class or interface.
    Code:
    Toolkit tk =  tk.getDefaultTookKit();
    Image image = tk.getImage();

  5. #5
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Good question. Didn't know the answer, but I'd seen reference to them so I did a little searching. Found this in usenet:

    A factory class is a class that contains a method that returns objects of another class. You use that method instead of the constructor to create the new objects. This can be useful if you have a situation where you need to choose one of several classes based on some parameter. A constructor can't do that.
    cudabean

  6. #6

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    so kinda like server sockets(i think that what they're called...) where they listen for a connection and then return a connected socket instead of using a constructor?
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

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