用于在应用程序中搜索对象的设计模式 [英] Design Pattern For Searching Objects in Application

查看:106
本文介绍了用于在应用程序中搜索对象的设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要一些关于设计模式的帮助。我正在创建一个在不同类型的应用程序,存储在单独表中数据库中的对象。
例如:
我有5种对象A,B,C,D,E
,我在数据库中有5个不同的表来存储每个对象。

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 .

现在,我想在我的应用程序中实现搜索功能。这意味着用户将会给出一个名称和多个对象类型。对于每个对象类型,我需要为给定的名称搜索单独的表。
任何人都可以提出用于这种场景的设计模式?
我打算写jpa查询从表中获取数据

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

推荐答案

不要试图强制每个问题适应众所周知的设计模式,这可能看起来像一个案例,使用 访客模式

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.

如果没有层次结构,它会减少到for循环。

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

让您的数据访问对象(DAO)实现返回主键(PK)的搜索界面:

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

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

通过查询类型和PK收集结果。
实现可以与名称,备注,描述等进行比较。您可能需要向界面添加另一种方法,该方法返回查询项目的文本表示。

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.

这篇关于用于在应用程序中搜索对象的设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆