Delegates?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    Delegates?

    The delegates white paper say they are not neccessary. I buy most of the arguments there. However it's possible to implement them in java (That article could have been improved by using generics in the code).
    The questions I have are:
    1.) Does using delegates imply that the design is not fully object oriented?
    2.) Which is more object oriented? Inner classes + Reflection vs Delegates
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by r035198x
    The delegates white paper say they are not neccessary. I buy most of the arguments there. However it's possible to implement them in java (That article could have been improved by using generics in the code).
    The questions I have are:
    1.) Does using delegates imply that the design is not fully object oriented?
    2.) Which is more object oriented? Inner classes + Reflection vs Delegates
    None of the two buy you much over the other. A Microsoft 'delegate' simply
    wraps an anonymous class thing around a method. It may allow for closures
    (I have to look into that in a little more detail), but I suspect that it doesn't.
    I might be wrong though.

    At the least I find the name 'delegate' confusing; I'd call it a 'mimicker' or something.

    kind regards,

    Jos

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by JosAH
      None of the two buy you much over the other. A Microsoft 'delegate' simply
      wraps an anonymous class thing around a method. It may allow for closures
      (I have to look into that in a little more detail), but I suspect that it doesn't.
      I might be wrong though.

      At the least I find the name 'delegate' confusing; I'd call it a 'mimicker' or something.

      kind regards,

      Jos
      That's another thing about them. The name throws a bit of a cloud. I'd have thought in pure delegation, an object forwards both a request and itself to another object (as in the state pattern).

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by r035198x
        That's another thing about them. The name throws a bit of a cloud. I'd have thought in pure delegation, an object forwards both a request and itself to another object (as in the state pattern).
        The construct is more like a C/C++ function pointer and as we all know simple
        interfaces and small (anonymous) class objects can do the same thing.

        If I would've been Microsoft (god forbid!) I'd gone the whole nine yards and
        implemented closures instead.

        kind regards,

        Jos

        Comment

        • odefta
          New Member
          • Jul 2007
          • 18

          #5
          You can't use delegates in java!
          The java events mechanism is different from C# for example.
          I C# you declare a delegate, an event that use the delegate, a method that implements the code of event and so on...

          In java you declare an event like...

          import java.util.Event Listener;
          public interface WizardListener extends EventListener
          {
          public abstract void nextSelected(Wi zardEvent e);
          public abstract void backSelected(Wi zardEvent e);
          public abstract void cancelSelected( WizardEvent e);
          public abstract void finishSelected( WizardEvent e);
          }

          Then implement this..and so on..

          For details you can read:

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by odefta
            You can't use delegates in java!
            ....
            You can implement them if you want. Read my first post again.

            Comment

            Working...