开发者

how to port an application that uses delegates to Java and the Android system

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 And开发者_JAVA百科roid 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜