Java: Accessing a interface function from a class which implements the interface -


background:

i have list of classes (comm objects), may or may not increase. implement same method in interface comms:

public int send(socket socket, byte[] message); 

i list of these comm classes specifying package name in method's packagename parameter (excluding package name internally in function , doing filtering names package comm):

public static class[] getclasses(string packagename); (modified bit link below) 

http://www.dzone.com/snippets/get-all-classes-within-package

then have several plugins configurable use 1 of comm objects base communication.

comm objects:


serial

client

server

etc.


plugins:


plugin1

plugin2

etc.


the manager class receive request sending control packet plugin, , manager queue requests , call send function each request on

question:

how access method send(socket socket, byte[] message); within manager or plugin itself? involves creating generic class object may call send, cast 1 of comm classes, depending on plugin configuration, string name of comm object.

the configuration of comm class used each plugin stored within database. converting string class object works well. need find way call send function resides in interface comm implemented comm classes. has generic. more comm classes may added.

give manager reference type comm interface , call send method.

when instantiate manager, inject implementation wish.

it sounds have virtual constructor/factory pattern down instantiating each type of comm implementation.

this common pattern dependency injection engines (e.g. spring, guice, etc.)


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -