Re: Delegates...?
Gav wrote:
I am trying to write an application using the "Presenter First"
methodology that I use when coding in C# but am a bit unsure how to
get round the fact that Java does not have delegates.
In C# I would create a Model class which has the actual application
functions in it, a view class which is a dumb GUI and then have a
presenter class which binds the two together. The presenters
constructor takes references to the model and view then calls
methods
in the model and view classes to point a delegate to the method in
the presenter. So basically the presenter knows about the model and
view but the model and view simply fire events which call methods in
the presenter.
In general, one uses inner classes (often anonymous inner classes) in
Java to implement callbacks that would be implemented via delegates in
C#. I won't even try to explain here how that's done, but you might
look up those terms in your favorite Java reference.
.
Relevant Pages
- Re: Cant derive from class with private constructor?
... > A bit of thread drift, but I'm curious as to why you loath ... it's an impoverished API compared to Java. ... C# itself doesn't have anonymous inner classes, ... classes non static members, delegates are ugly, properties are ugly. ... (comp.lang.java.programmer) - Re: A question related to type casting
... Inner classes work just fine in practice. ... I prefer delegates and anonymous methods. ... Variable capturing is, IMHO, much more expressive and useful, and delegates are WAY more concise and expressive than single-method interfaces implemented by anonymous classes. ... Delegates also encapsulate in a language-supported way the concept of a invocation list, which is really useful for implementing events and event-like things, something that has to be done explicitly in Java. ... (comp.lang.java.programmer) - Re: Delegates...?
... My point about the GUI is that Swing seems to provide already most of what the OP is asking for. ... There's no reason to build the presenter and delegates from scratch. ... When someone says "I don't know enough Java to even pass an object which hold a method" I think it helps to give them a steer in the right direction. ... I'm ducking the question of my first example because it was really just an example of delegates in Java. ... (comp.lang.java.programmer) - Re: Is Ruby On Rails, Delphis lost cousing?
... The closest analogue in Java is anonymous classes, ... Delegates as a first-class ... language feature alone makes me happier using it. ... Java Mustang does have some of this same functionality. ... (borland.public.delphi.non-technical) - Re: delegates equivalent
... > Whta is the simplest way to have something like multicast delegates ... > A Java interpretation for: ... where DisplayClass and PrintClass are ... (comp.lang.java.programmer) |
|