|
The general answer is to raise the level of abstraction, which enables more pattern-like programming and pluggable implementations. The specific answer is force of habit: I generally declare reference variables to be of the highest level of abstraction which will be needed. For instance:
The point being, if all the client code should be concerned with are the methods available to the interface, the underlying runtime time is not supposed to matter. If the client code starts doing a lot of downcasting, then the reference variable was not declared to be of specific-enough type.
For a slightly different example which does not use an interface, but rather an abstract class, consider java.util.Calendar. There is no problem with declaring a CMP EJB field to be of type Calendar, but what will perform the conversion from the jdbc Timestamp column to the EJB’s java.util.Calendar field? A custom converter is used (we implement one to ensure all dates are truncated to midnight and to ensure that the serialization is efficient).
I don’t believe that the question should be “What is the benefit of the behavior?” Rather, it should be “Why is the behavior explicitly disabled?” Rather than asking why it’s a good idea, can someone tell me why it’s a bad idea? Lack of overwhelming support that it’s a good idea does not imply that it’s a bad idea.
-----Original Message-----
I'm kind of curious of what would be the benefit of declaring them as interfaces? DISCLAIMER: |
Title: cannot map CMP attributes of Interface types?
- cannot map CMP attributes of Interface types? May Charles N
- Re: cannot map CMP attributes of Interface types? Dimitar Stavrakov
- May Charles N
