Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 958484

Pages: 1
Faiser
Unregistered




Loosely Typed getters surely are not evil
      #1557 - 09/09/03 02:35 AM

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


Post Extras: Print Post   Remind Me!   Notify Moderator  
Anonymous
Unregistered




Re: Loosely Typed getters surely are not evil [Re: Faiser]
      #1562 - 09/09/03 03:14 AM

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.



Post Extras: Print Post   Remind Me!   Notify Moderator  
Allen Holub
Unregistered




Re: Loosely Typed getters surely are not evil [Re: Faiser]
      #1869 - 09/12/03 03:49 PM

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


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 7899

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5