Howto "extend" enumerations [message #145472] |
Wed, 29 March 2006 09:06 |
Eclipse User |
|
|
|
Hi!
A couple of times lately I have found myself needing to "extend"
enumerations.
I know that this is not doable explicitly, but is there a "way around" such
as a nice pattern or likewise.
Example:
I have an interface A that defines an enumeration SomeEnumeration, i.e.
public interface A
{
public enum SomeEnum
{
SE1,
SE2,
SE3;
}
}
In implementing classes, e.g. B I would like to extend this enumeration so
that:
public class B implements A
{
public enum SomeEnumB extends SomeEnum
{
SE1 (1),
SE2 (2),
SE3 (3);
int value;
private SomeEnumB(int value) {this.value = value;}
public int getValue() {return this.value;}
}
}
But it does not work since I can't extend the enumeration SomeEnum.
As I mentioned I have many occasions where this would have come in very
handy.
I want the safety of an enumeration, but also the possibility to add
functionality.
For example imagine that SomeEnum had an abstract method
(SomeEnumImpl.process(DataSource ds)) than extending enumerations implement.
The implementation could e.g. depend on the underlying datasource or
similar.
I hope that someone is getting what I am getting at.
Regards,
Jimisola
|
|
|
Powered by
FUDForum. Page generated in 0.07358 seconds