Re: How to make a class an alias of another one?
- From: Lew <noone@xxxxxxxxxxxxx>
- Date: Sat, 30 Aug 2008 16:36:27 -0400
Mark Space wrote:
Lew wrote:Hence the part where I said, "gives the appearance of".
This gives the appearance of an antipattern: one should not hardcode subclasses into their parent classes.
Given the simplicity of the request, I didn't see the need to make a third class whose function was just a factory for ClassA and subclasses. Gold plating -- needlessly complex design -- is an anti-pattern too. If refactoring is required later, well, refactor. It happens.
I thought your example was a good laboratory for the types of pragmatic choices one makes knowing the consequences of those choices. Of course, that makes it important to be aware of the consquences.
What safety there is in this use lies in that 'Temporary' is package-private. This isn't completely safe, in that other subclasses of 'A' can do Bad Things.
Isn't this a danger for all non-final classes? Any class can subclass another non-final class, do bad things, break contracts, throw spurious RuntimeExceptions, etc. Given that ClassA must be public and extensible, I don't see a way around this.
I suppose that just making ClassA concrete and final would be ok, but if one is planning on making changes later, it seems like having a defined interface would be handy. I originally had ClassA as an interface, then decided it needed a simple factory method. Hence, abstract.
More excellent thinking to take consequences into account.
You beautifully illustrate how careful compromises actually are better than seeking the One Right Way.
--
Lew
.
- Follow-Ups:
- Re: How to make a class an alias of another one?
- From: Mark Space
- Re: How to make a class an alias of another one?
- References:
- Re: How to make a class an alias of another one?
- From: Mark Space
- Re: How to make a class an alias of another one?
- From: Lew
- Re: How to make a class an alias of another one?
- Prev by Date: Re: Inner classes
- Next by Date: Euclidean TSP and Java
- Previous by thread: Re: How to make a class an alias of another one?
- Next by thread: Re: How to make a class an alias of another one?
- Index(es):
Relevant Pages
|