Is this convenience function ok?

Discussion in 'Java' started by EdwardH, Oct 1, 2005.

  1. EdwardH

    EdwardH Guest

    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?
    EdwardH, Oct 1, 2005
    #1
    1. Advertising

  2. EdwardH

    Dave Glasser Guest

    EdwardH <edwardh@N:O:S:p: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/papers/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
    Dave Glasser, Oct 2, 2005
    #2
    1. Advertising

  3. EdwardH

    EdwardH Guest

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

    Law of Demeter applied.

    Thanks for the info.
    EdwardH, Oct 2, 2005
    #3
  4. EdwardH

    Wibble Guest

    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.
    Wibble, Oct 2, 2005
    #4
  5. EdwardH

    Roedy Green Guest

    On Sat, 01 Oct 2005 22:59:02 GMT, EdwardH
    <edwardh@N:O:S:p: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.
    Roedy Green, Oct 2, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond DeCampo

    JavaBeans convenience methods

    Raymond DeCampo, Feb 25, 2006, in forum: Java
    Replies:
    0
    Views:
    327
    Raymond DeCampo
    Feb 25, 2006
  2. Josef Pfleger

    TimeSpan Convenience

    Josef Pfleger, Dec 3, 2006, in forum: Java
    Replies:
    14
    Views:
    791
    Mark Thornton
    Dec 23, 2006
  3. KU
    Replies:
    0
    Views:
    290
  4. KU
    Replies:
    0
    Views:
    225
  5. KU
    Replies:
    0
    Views:
    252
Loading...

Share This Page