O
ozgwei
Responding to Peter, the OP.
I think Country is better implemented as an enum class, or inheriting
org.apache.commons.lang.enums.Enum for JDK 1.4 or prior.
If defined as an Interface, how can you prevent multiple
implementations of this interface and still evaluate
InternetDomainCountryImplementation.getCountry("uk").equals(ConventionalCountryImplementation.getCountry("The
United Kingdom") to true?
I know it's still possible but that will take a lot of effort and
achieve little.
Generally speaking, value classes, especially those that depends little
on other non-immutable classes should be defined as classes. Country is
a good candidate. If the instances can be enumerated, you should define
it as an enum class.
interface Country {...}
class CountryImpl implements Country {...}
I think Country is better implemented as an enum class, or inheriting
org.apache.commons.lang.enums.Enum for JDK 1.4 or prior.
If defined as an Interface, how can you prevent multiple
implementations of this interface and still evaluate
InternetDomainCountryImplementation.getCountry("uk").equals(ConventionalCountryImplementation.getCountry("The
United Kingdom") to true?
I know it's still possible but that will take a lot of effort and
achieve little.
Generally speaking, value classes, especially those that depends little
on other non-immutable classes should be defined as classes. Country is
a good candidate. If the instances can be enumerated, you should define
it as an enum class.