lundi 26 janvier 2015

How to selectively filter based on various paramters value

I work for an investment bank and we need to deal with Market and Instruments. So in my programming question I will be using those words to make the question more clear.


I have been trying to build an interface and its implementation of ReferenceData whose tasks are:



  • getAllInstruments()

  • getAllInstrumentsForAMarket(final String market)

  • getInstrumentsFromAllMarketOfAnISIN(final String isin)

  • getInstrumentFromAMarketAndISIN(final String market, final String isin)


Including above there will be other combination of parameters and will involve other parameters like instrument type (Bond, future etc.).


The above design will lead to make a parameter combination as and when new type of query parameter is taken into account in future which is I believe a bad design.


I followed up with Interpreter pattern as discussed by Joshua Kerievsky's Refactoring To Patterns but I am stuck with two problems:




  • How to deal with null values in the parameters, like somebody might be using method getInstrumentFromAMarketAndISIN(final String market, final String isin) and passing null value in market. It is to be considered as a valid query which should then be a case of getInstrumentsFromAllMarketOfAnISIN(final String isin) .




  • I do not want to have the client deal with if else checks of parameters and then call the methods, because these are utility methods and will be called from plenty of places, which will lead to null checks all over the client code everywhere. Instead the implementation of ReferenceData should be able to handle it.




Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire