G
Guest
Hi,
I'm x-training to .NET at the moment from Java. I have a question regarding
how to implement in .NET the following Java feature.
In Java interfaces it is possible to define static final fields (and assign
values to them) - these fields provide constants that can be exploited by all
classes implementing those interfaces.
Thus inheritance is used to provide static constants with wide (but
definable) scope.
In .NET i've found this is not directly possible ... (tho. feel free to
correct me on this)
Alternatives are just create a class with the constants (but then all
classes and client programmers can access them - maybe this is undesirable)
or create a class containing the constants - messy and can potentially run
into problems through mutiple inheritance (I want to extend X but would also
like to inherit the constants in Y)
I know .NET interfaces allow the signature of properties to be defined in
Interfaces, but assignation of a value to a Shared member in an interface
appears to be forbbiden.
I have found the above Java feature very useful, and would like to re-use
this approach if possible.
Thanks in advance for help.
I'm x-training to .NET at the moment from Java. I have a question regarding
how to implement in .NET the following Java feature.
In Java interfaces it is possible to define static final fields (and assign
values to them) - these fields provide constants that can be exploited by all
classes implementing those interfaces.
Thus inheritance is used to provide static constants with wide (but
definable) scope.
In .NET i've found this is not directly possible ... (tho. feel free to
correct me on this)
Alternatives are just create a class with the constants (but then all
classes and client programmers can access them - maybe this is undesirable)
or create a class containing the constants - messy and can potentially run
into problems through mutiple inheritance (I want to extend X but would also
like to inherit the constants in Y)
I know .NET interfaces allow the signature of properties to be defined in
Interfaces, but assignation of a value to a Shared member in an interface
appears to be forbbiden.
I have found the above Java feature very useful, and would like to re-use
this approach if possible.
Thanks in advance for help.