Using Dependency Injection in Java EE 5.0
Subject:   One class != one object
Date:   2007-05-01 10:06:33
From:   docbillnet
Come on. The whole flaw with annotations is they assume each Object only has a single use. Presumably the reason why they are variables, and not constants in that they can take on different values.

For example, consider if I had the following class:

class DisplayMessage {
Message message;
Message setMessage(Message message) {
this.message = message;
Message getMessage() { return message; }
void displayMessage() {
... something complicated ...

Now perhaps I have many other classes that need DisplayMessage objects injected. Some with different Message values?

In Spring this is pretty easy. I just assign one resource name for each message object I will need, in inject the appropriate message.

For example:
<bean id="displayMessage1" class="Message">
<property name="message" ref="message1"/>
<bean id="displayMessage2" class="Message">
<property name="message" ref="message2"/>
<bean id="displayMessage3" class="Message">
<property name="message" ref="message3"/>

However, with annotations the message is contained within the class itself as an annotation. If you want to actually have different object which only vary by what value is ejected into them, you actually have to make separate classes. How stupid is that?

A commonly used class might be replicated hundreds of times, just so different values can be injected.

1 to 1 of 1
  1. One class != one object
    2007-05-01 10:12:33  docbillnet [View]

1 to 1 of 1