overridding factories.

Discussion in 'Java' started by Roedy Green, Aug 24, 2003.

  1. Roedy Green

    Roedy Green Guest

    If you come from a Forth background or something similar, it is
    trivially easy to change even the most fundamental behaviours of the
    runtime. There is no safety net to prevent suicidal behaviours.

    Let's say you wanted to do something like add some extra fields to the
    File object. So long as File is not final, you can subclass it and
    create all the FilePlus objects you want.

    However, everywhere else File objects still get created without the
    extra fields. Every time you encounter one, you have to tediously
    convert it to a FilePlus. Would it not be nice if you could persuade
    the system to create FilePlus objects directly instead of File Objects
    when someone asked for a File object.

    That would be considered hideously dangerous and wicked. Ok, what if
    the authors of File had foreseen this eventuality, and made the
    constructor for File private and offered a factory method instead to
    produce the desired File objects.

    But that does not get you anywhere. You can't replace a static
    factory method, and no one but you would use an overridden one.

    You actually need a static factory method that fobs the work off on a
    static reference delegate factory object. There needs also to be a
    setFactory method to change the factory object, and off course a
    Factory Interface for the factory object to implement.

    Whew. I think that is what is happening inside the Java Security
    system with pluggable implementations.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Aug 24, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gane kol
    Replies:
    1
    Views:
    347
    Scott Allen
    Apr 15, 2005
  2. Kai Grossjohann

    JSP: Beans from factories?

    Kai Grossjohann, Dec 17, 2003, in forum: Java
    Replies:
    2
    Views:
    674
    Kai Grossjohann
    Dec 17, 2003
  3. Replies:
    1
    Views:
    430
    Oliver Wong
    Oct 2, 2006
  4. Trans
    Replies:
    4
    Views:
    124
    Trans
    Aug 8, 2005
  5. Andrew Stewart

    Overridding A Method Via A Mixin

    Andrew Stewart, Jan 15, 2008, in forum: Ruby
    Replies:
    15
    Views:
    221
    Andrew Stewart
    Jan 17, 2008
Loading...

Share This Page