Working on a proprietary Bioinformatics software that manipulate domain objects, I have to enhance the API so that external parties can access (CRUD) data stored in the internal DB.
The data are grouped by type (such as molecule, oligo and enzyme) and within each, there can be subsets (molecule::protein, molecule::dna, etc) which are nest-able.
Since each data type has different attributes, we are using formatted query string (similar to widely-used entrez format) to specify the search criteria. Example of the code will be as follow:
IMoleculePersistenceService svc = PersistenceFactory::GetMoleculeService();
// IMoleculePersistenceService::search( <search-string>, <subset> );
IMolecule[] searchResult = svc.search( "Foo[Name] OR 128[Length]", "molecule::protein" );
My question is:
Assuming the users have corresponding domain knowledge to understand biology-related hierarchy. Will it be better to have the search function accept prototype
object instead of the formatted-string ?
IMoleculePersistenceService svc = PersistenceFactory::GetMoleculeService();
IMoleculeTemplate searchPrototype = svc.GetSearchPrototype();
searchPrototype.SetName( "Foo" );
searchPrototype.SetLength( 128 );
IMolecule[] searchResult = svc.search( searchPrototype, "molecule::protein" );
IMolecule[] searchResult2 = svc.search( svc.GetSearchPrototype( <parameters> ), "molecule::protein" );
Pros:
-easier to visualize/understand
-compatible with query-string if prototype
can be serialized into (formatted) string automatically.
Cons:
-not flexible as the criteria combination is fixed (either AND, OR).