Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Is this convenience function ok?

Reply
Thread Tools

Is this convenience function ok?

 
 
EdwardH
Guest
Posts: n/a
 
      10-01-2005
class Status has a member class called Transferstatus.

class TransferStatus has the method
setData(filename, filesize, direction)

Normally one would call
Status.getTransferStatus().setData(filename, filesize, direction)

Q: What are y'all's opinions on making a convenience function in Status
that calls setData? Status.set(filename, filesize, direction).


It's much shorter to use Status.set, but are there any disadvantages? Am
I making Status too smart?
 
Reply With Quote
 
 
 
 
Dave Glasser
Guest
Posts: n/a
 
      10-01-2005
EdwardH <edwardh@N:O:S:A:M:edward.dyndns.org> wrote on Sat, 01 Oct
2005 22:59:02 GMT in comp.lang.java.programmer:

>class Status has a member class called Transferstatus.
>
>class TransferStatus has the method
>setData(filename, filesize, direction)
>
>Normally one would call
>Status.getTransferStatus().setData(filename, filesize, direction)
>
>Q: What are y'all's opinions on making a convenience function in Status
>that calls setData? Status.set(filename, filesize, direction).


That's the preferred way to do it, according to the Law of Demeter:

http://pragmaticprogrammer.com/ppllc...s/1998_05.html
(Scroll toward the bottom)

http://www.ccs.neu.edu/home/lieber/LoD.html


--
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

If you're a musician, check out RPitch Relative Pitch
Ear Training Software.

http://rpitch.sourceforge.net
 
Reply With Quote
 
 
 
 
EdwardH
Guest
Posts: n/a
 
      10-02-2005
> That's the preferred way to do it, according to the Law of Demeter:

Law of Demeter applied.

Thanks for the info.
 
Reply With Quote
 
Wibble
Guest
Posts: n/a
 
      10-02-2005
EdwardH wrote:
> class Status has a member class called Transferstatus.
>
> class TransferStatus has the method
> setData(filename, filesize, direction)
>
> Normally one would call
> Status.getTransferStatus().setData(filename, filesize, direction)
>
> Q: What are y'all's opinions on making a convenience function in Status
> that calls setData? Status.set(filename, filesize, direction).
>
>
> It's much shorter to use Status.set, but are there any disadvantages? Am
> I making Status too smart?

I'm generally opposed to convenience functions. They seem like a good
idea, but often become an obfuscation layer. Like you said, Status
becomes too smart. When you change TransferStatus, Status has to also
change. Consumers may use either signature, so it becomes less clear;
choice is evil. If you're writing tests, you should now write tests
for both interfaces. I like writing unit tests since the pain of
writing a test has often caused me to delete features that are not
required.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      10-02-2005
On Sat, 01 Oct 2005 22:59:02 GMT, EdwardH
<edwardh@N:O:S:A:M:edward.dyndns.org> wrote or quoted :

>It's much shorter to use Status.set, but are there any disadvantages? Am
>I making Status too smart?


It is legit in that what you propose doing has a design pattern name
-- Facade. The advantages are:

1. it is easier for your clients. They don't have to remember the
clumsy, and(what feels to them like an), arbitrary, syntax.

2. It gives you flexibility to redesign your innards,
add/delete/rename classes, move functionality around.

One place Sun should have used a Facade was for JComponent.add.
instead of JComponent.getContentPane().add(). The did add it in 1.5.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Desktop 3: Convenience vs. Privacy Silverstrand Front Page News 0 02-25-2006 10:17 PM
No exam! Obtain MCSE at home with 100% convenience Marlin Munrow MCSE 7 02-23-2004 07:08 PM
Obtain Certifications at home with 100% convenience. ipassmcse MCSE 0 02-21-2004 04:19 AM
Obtain your IT certifications at home with 100% convenience. ipassmcse MCSE 0 02-20-2004 08:14 AM
Obtain your IT certification at home with 100% convenience. ipassmcse Microsoft Certification 0 02-20-2004 08:08 AM



Advertisments