实现动态数据导入器工具的良好设计模式是什么?

发布于 2024-07-10 05:39:34 字数 245 浏览 6 评论 0原文

我们计划构建一个动态数据导入工具。 基本上是在一端以指定格式(access、excel、csv)获取信息并将其上传到 Web 服务中。

情况是我们不知道导出字段名称,因此应用程序需要能够查看 wsdl 定义并映射到另一端的有效条目。

在导入部分我们可以定义了大部分字段,但通常有一些是自定义的。 我认为这没有问题。

我只是想知道是否有一种设计模式适合此类应用程序或有助于其开发。

We are planning to build a dynamic data import tool. Basically taking information on one end in a specified format (access, excel, csv) and upload it into an web service.

The situation is that we do not know the export field names, so the application will need to be able to see the wsdl definition and map to the valid entries in the other end.

In the import section we can define most of the fields, but usually they have a few that are custom. Which I see no problem with that.

I just wonder if there is a design pattern that will fit this type of application or help with the development of it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

霊感 2024-07-17 05:39:35

我不确定您的应用程序的复杂性在哪里,因此我将仅举一个示例来说明如何使用模式来导入不同格式的数据。 我创建了一个工厂,它将文件格式作为参数并返回特定文件格式的解析器。 然后我使用构建器模式。 解析器配备有构建器,解析器在解析文件以构造应用程序中所需的数据对象时调用该构建器。

// In this example file format describes a house (complex data object)
AbstractReader reader = factory.createReader("name of file format");
AbstractBuilder builder = new HouseBuilder(list_of_houses);
reader.import(text_stream, builder);

// now the list_of_houses should contain an extra house
// as defined in the text_stream

I am not sure where the complexity is in your application, so I will just give an example of how I have used patterns for importing data of different formats. I created a factory which takes file format as argument and returns a parser for particular file format. Then I use the builder pattern. The parser is provided with a builder which the parser calls as it is parsing the file to construct desired data objects in application.

// In this example file format describes a house (complex data object)
AbstractReader reader = factory.createReader("name of file format");
AbstractBuilder builder = new HouseBuilder(list_of_houses);
reader.import(text_stream, builder);

// now the list_of_houses should contain an extra house
// as defined in the text_stream
虫児飞 2024-07-17 05:39:35

我会说适配器模式,因为您正在将数据从文件“适应”到对象,就像 SqlDataDataAdapter 一样,它从 Sql 表到 DataTable 是否

对于每种文件类型/格式都有不同的适配器? 例如SqlDataAdptor,MySqlDataAdapter,它们处理相同的命令但不同的数据源,以获得相同的输出DataTable

适配器模式

HTH

Bones

I would say the Adaptor Pattern, as you are "adapting" the data from a file to an object, like the SqlDataDataAdapter does it from a Sql table to a DataTable

have a different Adaptor for each file type/format? example SqlDataAdptor, MySqlDataAdapter, they handle the same commands but different datasources, to achive the same output DataTable

Adaptor pattern

HTH

Bones

无戏配角 2024-07-17 05:39:35

Bridge 可能适合,因为您必须处理不同的文件格式。
和 Façade 来简化使用。 小心处理我的回复,我只是在学习设计模式:)

Probably Bridge could fit, since you have to deal with different file formats.
And Façade to simplify the usage. Handle my reply with care, I'm just learning design patterns :)

但可醉心 2024-07-17 05:39:35

您可能还需要抽象工厂和命令模式。

如果数据与输入格式不匹配,您可能需要以某种方式对其进行转换。
这就是命令模式的用武之地。因为格式是动态的,所以您需要根据输入生成命令。 这就是抽象工厂的用处。

You will probably also need Abstract Factory and Command patterns.

If the data doesn't match the input format you will probably need to transform it somehow.
That's where the command pattern come in. Because the formats are dynamic, you will need to base the commands you generate off of the input. That's where Abstract factory is useful.

紫南 2024-07-17 05:39:35

我们的情况是,我们需要从竞争对手的文件中导入参数化形状。 它们的屏幕和数据字段的布局相似但又足够不同,因此存在一个转换过程。 此外,我们有超过六个竞争对手,如果仅通过代码完成维护将是一场噩梦。 由于它们中的大多数使用表格来存储其形状的参数,因此我们编写了一个通用对象集合来将 X 转换为 Y。

在我的 CAD/CAM 应用程序中,文件导入是一个命令。 然而,转换魔法是由规则集通过以下步骤完成的。

  1. 将数据导入到表中。 字段名称也会根据格式被拉入。
  2. 我们将表传递给规则集。 我将在一分钟内解释规则集的结构。
  3. 规则集将数据转换为我们检索的一组新对象(或表),
  4. 并将结果传递给软件的其余部分。

规则集由一组规则组成。 一个规则可以包含另一个规则。 规则有一个要测试的条件和一个映射表。

映射表将传入字段与结果中的字段(或属性)进行映射。 可以有一个映射或多个映射。 映射不必涉及将输入值插入输出字段。 我们还有计算和字符串连接的语法。

此语法也用在条件中,并且可以合并多个文件,例如 ([INFIELD1] & "-" & [INFIELD2])="AB" 或 [DIM1] + [DIM2] > 10. 括号之间的任何内容都将替换为传入字段。

规则可以包含其他规则。 其工作方式是,为了使子规则映射应用它的条件以及它的父规则(或多个父规则)的条件,必须为真。 如果子规则的映射与父规则的映射冲突,则应用子规则映射。

如果同一级别上的两个规则的条件为 true 并且具有冲突的映射,则具有较高索引的规则(或者如果您正在查看树视图,则在列表中较低)将应用其映射。

嵌套规则相当于 AND,而同一级别的规则相当于 OR。

结果是一个映射表,该表应用于传入数据以将其转换为所需的输出。

在 UI 中显示是很友好的。 即显示规则层次结构的树视图和显示映射表和规则条件的侧面板。 同样重要的是,您可以创建自动化常见规则结构的向导。

Our situation is that we need to import parametric shapes from competitors files. The layout of their screen and data fields are similar but different enough so that there is a conversion process. In addition we have over a half dozen competitor and maintenance would be a nightmare if done through code only. Since most of them use tables to store their parameters for their shapes we wrote a general purpose collection of objects to convert X into Y.

In my CAD/CAM application the file import is a Command. However the conversion magic is done by a Ruleset via the following steps.

  1. Import the data into a table. The field names are pulled in as well depending on the format.
  2. We pass the table to a RuleSet. I will explain the structure the ruleset in a minute.
  3. The Ruleset transform the data into a new set of objects (or tables) which we retrieve
  4. We pass the result to the rest of the software.

A RuleSet is comprise of set of Rules. A Rule can contain another Rule. A rule has a CONDITION that it tests, and a MAP TABLE.

The MAP TABLE maps the incoming field with a field (or property) in the result. There are can be one mapping or a multitude. The mapping doesn't have to involve just poking the input value into a output field. We have a syntax for calculation and string concatenation as well.

This syntax is also used in the Condition and can incorporate multiple files like ([INFIELD1] & "-" & [INFIELD2])="A-B" or [DIM1] + [DIM2] > 10. Anything between the brackets is substituted with a incoming field.

Rules can contain other Rules. The way this works is that in order for a sub Rule mapping to apply both it's condition and those of it's parent (or parents) have to be true. If a subRule has a mapping that conflicts with a parent's mapping then the subRule Mapping applies.

If two Rules on the same level have condition that are true and have conflicting mapping then the rule with the higher index (or lower on the list if you are looking at tree view) will have it's mapping apply.

Nested Rules is equivalent to ANDs while rules on the same level are equivalent of ORs.

The result is a mapping table that is applied to the incoming data to transform it to the needed output.

It is amicable to be being displayed in a UI. Namely a Treeview showing the rules hierarchy and a side panel showing the mapping table and conditions of the rule. Just as importantly you can create wizards that automate common rule structures.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文