Reputation: 1506
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
Upvotes: 3
Views: 3039
Reputation: 68942
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.
Upvotes: 1