Title: cannot map CMP attributes of Interface types?

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:

  • List list = new ArrayList();
  • Set set = new HashSet();
  • Map map = new TreeMap();
  • Enumeration en = new StringTokenizer(“dummy string”);
  • Collection c = new SortedSet();

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-----
From: Dimitar Stavrakov [mailto:[EMAIL PROTECTED]
Sent:
Tuesday, July 01, 2003 1:58 PM
To: May Charles N; [EMAIL PROTECTED]
Subject: RE: cannot map CMP attributes of Interface types?

 

I'm kind of curious of what would be the benefit of declaring them as interfaces?

 

DISCLAIMER:
The information contained in this e-mail may be confidential and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorized. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator.

Reply via email to