Faiser
Unregistered
|
|
right, a strongly typed getter method will reveal implementation; that's clear.
What is now contentable is whether a loosely typed language, or a loosely typed implementation of a strongly type language, will comprise (literally embrace) this pattern more effectively. I think it is the case that it does. That is to say, a loosely typed implementation is the context in which this pattern should be used to adhere to OO design. It then stands to follow that this pattern is not being widely misued per se, but that it is beign widely used in the improper context.
For example, in java, getThing():int, reveals its return type. Also in java, getThing():Object, does not. Naturally the argument is that the caller of getThing():Object will have to cast the return object, which will be true most of the type. Hence the problem - java is too strongly typed to comprise (again, literally embrace) a true 00 pattern. And so the final analogy I'll make is that using this pattern is kind of like speaking French in Dover: it'll get one somewhere most of the time, but occasionally it'll also get one thrown in the channel.
out
|
Anonymous
Unregistered
|
|
What you said answered my question also. You said it much better than I did. This was my post originally:
While I can see how decoupling is important and maintaining code flexibility is central to OO design concept. But I don't know if pushing decoupling of return variables is possible (not using accessors). If that's the case why not just use "Object" for everything? Don't pass int, long, boolean, just pass Object and build in the smarts for the consumer method to figure out what type of data it should cast to. I wish the author would have provided some concerete code example in this article like his last one. Instead, I feel a lot of it is just argumentative.
|
Allen Holub
Unregistered
|
|
On the other hand, typing does have value. I prefer compile-time errors over runtime errors. As you say, the cast is not good. Consequently, I wouldn't go as far as you have and have the method return Object; rather, I'd have it return a reference to some public interface.
-Allen
|
|