Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design Pattern For Searching Objects in Application

needed some help regarding design patterns. I am creating an app which has different types on Objects stored in databases in separate table. For eg : I have 5 kinds of objects A, B , C , D ,E and i have 5 different tables in database to store each objects .

Now , i want to implement search feature in my application . That means user will be giving a name and multiple object type. For each object type i need to search separate tables for the given names . Can any one suggest which design pattern to use for such scenario ? I am planning to write jpa queries to fetch data from tables

like image 862
Alok Avatar asked Nov 30 '25 02:11

Alok


1 Answers

Don't try to force each problem to fit into a well known design pattern this it might look like a case to use the Visitor Pattern.

If you don't have hierarchical structures it reduces to a for loop.

Let your data access objects (DAO) implement a search interface which returns the primary keys (PK):

public interface ISearch {
    public int search( String text );
}

Collect the results by queried type and PK. The implementations could compare to names,remarks, description and so on. You might want to add another method to the interface which returns a text representation of a queried item.

like image 121
stacker Avatar answered Dec 02 '25 14:12

stacker