Re: How to make a class an alias of another one?
- From: Lew <noone@xxxxxxxxxxxxx>
- Date: Sat, 30 Aug 2008 13:44:37 -0400
Mark Space wrote:
public abstract class ClassA {
// your methods here
public static ClassA getInstance() {
return new Temporary()
}
}
class Temporary extends ClassA {
private String temp;
// implement ClassA methods
}
Now you can declare everything as ClassA and switch implementations when you need easily. Note the lack of "public" on Temporary. It should be in the same package as ClassA.
This gives the appearance of an antipattern: one should not hardcode subclasses into their parent classes.
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.
--
Lew
.
- 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?
- Prev by Date: Re: Concurrent, persistent background process for a J2EE container
- Next by Date: Re: Inner classes
- 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
|