views:

53

answers:

2

I have an application written in Delphi and ported to C# that makes extensive use of delegates (which allows me to add new modules easily). I think it would make a great Android phone app, but Java does not do delegates natively. I've seen a couple of examples of Java codes that tries to do delegates using reflection, but that does not seem efficient for a small device application.

Any suggestions about how I would go about porting my app without extensive re-architecture?

+2  A: 

Without knowing more details I can't suggest an exact porting method to fit your situation.

That being said, I would look at changing your delegates to event listeners. Event listeners are quick to create, offer a common calling signature with the flexibility of being easily implemented with differeing functionality. Also, they are very easy to move around dynamically. Changing the target method is a simple matter of replacing the listener. Calling the method is simply calling the event.

Interfaces are another option but are a lot heavier and less flexible on the mobile platform.

Hopefully this is what you were looking for.

CodeFusionMobile
A: 

Java uses EventListeners instead of delegates. This is also called the observer pattern: http://en.wikipedia.org/wiki/Observer_pattern

Eloff