mercredi 15 mars 2017

How to select implement by a parameter?In Java

i am trying to make a restful api for logistics query. it accept two params: shipping_id and tracking_number, and it will call a third-party api to get the result and do something with it.there are tens of third-party apis provided by different companies, and which to call depends on the value of shipping_id.

my solution is like this: there will be a superclass 'LogisticsQueryController' and many subclasses 'ALogisticsQueryController','BLogisticsQueryController'...extends 'LogisticsQueryController'.

and keep a map ('shipping_id'=>'class_dir'). with shipping_id given, i can get a class_dir by shipping_id, and then new an instance by reflect.

but i heard reflect in java could be inefficient, so what is the better solution?





Aucun commentaire:

Enregistrer un commentaire