reflection - Using a user defined method in an Android Library Java -


i implementing library used many different types of media players. need use getposition method vary each individual user's video player.

currently accomplish have made library abstract class user has extend , override getposition method whatever object/method use position of media player.

i trying make class not have abstract , define getposition method library without having extend abstract class (i.e.) don't want library class abstract.

i have looked using reflection, struggling because not know class name/method name/parameters until runtime , want position of specific instance of media player object can current position.

what's practice java/android programming paradigm?

is reflection way go? , if see sample code specific instance (unknown class name/method name/parameters used imported library etc...)

or there better way accomplish this/is making class abstract way go in java?

again prefer if user did not have extend class , call sort of setgetposition() method on object.

edit: put: want able use unknown class's getposition method in library, don't want entire class abstract

that's interfaces for--to enforce api obligations.

classes implementing positionable (or whatever) can (a) referenced positionable, , (b) handle calls positionable's methods, getposition.

consider list interface: class implements list must have bunch of specific methods, don't need subclass. they may subclass, don't have be.

in general, "plugin" systems allow arbitrary implementations of specific functionality, , functionality specified using interface. interfaces 1 of basic mechanisms java provides forcing classes adhere spec.

plugins may use reflection, there's additional overhead, additional complexity, , allows undesirable runtime behavior precisely because there's no compiler enforcement interfaces.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -