"Jeffrey Spoon" wrote...
> ...please
>
[quoted text clipped - 3 lines]
>
> Company cotest = new CompanyDecorator(new Company("Jeff's Corp."));
> I managed to wrap an interface before and decorate all the classes that
> implemented it, but this Company class is giving me problems because the
> Company constructor accepts a String as a parameter (eg "Jeffs corp"),
It would surely be "easier" and "prettier" if Company at least had a public
accessor to "theName".
Nevertheless, as a decorator actually is a "wrapper", and not a true
"extension" of the original instance, the content of *that* string wouldn't
really matter. Actually *no* content of inherited members would matter.
That is, you don't actually *use* the superclass other than as an inherited
*type*, all "old" functionality is *delegated* to the wrapped instance.
For instance:
> public final void displayEmployees() {
> super.displayEmployees();
> //...
> }
should be:
public final void displayEmployees() {
theDecoratedCompany.displayEmployees();
//...
}
...So your "toString"-solution would work as anything else...
HTH.
// Bjorn A
Jeffrey Spoon - 26 Nov 2004 16:15 GMT
>It would surely be "easier" and "prettier" if Company at least had a public
>accessor to "theName".
[quoted text clipped - 5 lines]
>That is, you don't actually *use* the superclass other than as an inherited
>*type*, all "old" functionality is *delegated* to the wrapped instance.
Well I can't actually change Company as it is a class being tested. I
think the reason there is no accessor is to simplify the example (for
example there is no compareTo,hashCode or equals methods for the
Collection used either - which is not shown in the SEC)
>For instance:
>
[quoted text clipped - 11 lines]
>
>...So your "toString"-solution would work as anything else...
Doh! That's how I did it using the Interface. For some reason I decided
to change it in this case.
>HTH.
Yes it did, thanks very much.

Signature
Jeffrey Spoon