Java - How to design a method for search? -


i designing decorator class wraps news search engine, can ship class library used other teams.

the exposed interface of class java-styled one, takes lot of parameters, decorator assembles these parameters search text search engine.

my method following:

public list<news> search(list<string> keywords, list<string> categories, list<string> authors, list<location> locactions, list<localdate> dates, list<sortrule> sortrules, int offset, int limit); 

yes, know... method looks ridiculously long, error-probe , hard use clients.

so, how can design better api such search functionality?

you can try writing wrapper class applying rule filters , take new object of class in current class. way simple , cleaner.

for example,

rulefilters r = new rulefilters(); r.addfilters(type.keywords, keywords); r.addfilters(type.categories, categories); r.addfilters(type.authors, authors); 

here type enum holds details of different rule filters {categories, authors, keywords} etc.

finally in main class:

public list<news> search(rulefilters r) {     /* rule filters */  }; 

interface:

list<news> search(rulefilters r); 

note: public keyword not necessary in interfaces.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -