Re: All those constructors...
From: Michael Klaus (Michael.Klaus_at_gmx.net)
Date: 02/02/05
- Next message: JGH: "Good java to jsp tutorial?"
- Previous message: Paul Chapman: "Re: All those constructors..."
- In reply to: Paul Chapman: "All those constructors..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 02 Feb 2005 23:42:51 +0100
Paul Chapman wrote:
> I have this fairly large class heirarchy, with all but the leaves
> abstract. One of the base class's fields is to be initialized with a value
> provided to a static factory method which selects the right subclass,
> *except* in one leaf case where it is replaced with something else.
I had a quite similar case and solved it (in my eyes fairly clean) by:
- providing a protected default constructor in the node class
- creating package visible setXXX() for the init parameters
- creating a public init() method which subclasses use for their constructor
code
- putting the factory into the same package with the node classes
The drawback is, you can not programatically ensure implementors use the
init() method instead of the constructor. This has to be done via
documentation. As I said: fairly clean ;o)
- Next message: JGH: "Good java to jsp tutorial?"
- Previous message: Paul Chapman: "Re: All those constructors..."
- In reply to: Paul Chapman: "All those constructors..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|