java建立结构体_建立产品的动态结构

java建立结构体

I always liked product price comparison sites, however most of these sites only aggregate products from other shops thereby providing next to no additional value to their users. Examples of this include one-hit wonders such as Pricegrabber.com and Shopping.com.

我一直喜欢产品价格比较网站,但是大多数这些网站仅汇总其他商店的产品,因此几乎没有为用户提供任何附加价值。 这样的例子包括诸如Pricegrabber.comShopping.com之类的一击奇观。

On the other hand, sites like pricespy.co.uk provide more functionality like their own rating system for shops, product reviews. But their biggest advantage is the advanced search that can query products based on whichever product property the product category supports. They achieve this by documenting product specifications across hundreds of product categories and thousands of products on their site.

另一方面, pricespy.co.uk之类的网站提供了更多功能,例如他们自己的商店评分系统,产品评论。 但是它们的最大优势是可以根据产品类别支持的任何产品属性查询产品的高级搜索。 他们通过在其站点上记录数百种产品类别和数千种产品的产品规格来实现此目的。

I wasn’t satisfied with what was on offer. I wanted to build my own price/product comparison site, but how could I go about doing this?

我不满意所提供的东西。 我想建立自己的价格/产品比较网站,但是我该怎么做呢?

Image for post
This is a random product on the website, it lists multiple specifications.
这是网站上的随机产品,它列出了多个规格。

抢劫 (The heist)

First I had to collect a lot of data, which was no easy task. I am sure even PriceSpy realized this early on as in the early versions of the site they allowed users to edit products but since the latest UI update, this feature has been removed. They must now be doing all the documenting inhouse.

首先,我必须收集大量数据,这绝非易事。 我敢肯定,即使PriceSpy早在网站的早期版本中就意识到了这一点,他们允许用户编辑产品,但是自从最新的UI更新以来,此功能已被删除。 他们现在必须在内部进行所有文档记录。

Image for post
The old (classic) PriceSpy allowed users to edit the product specifications. It allowed me to peek “under” the hood of the implementation.
旧的(经典)PriceSpy允许用户编辑产品规格。 它使我可以“窥见”实施的幕后。

模板 (Template)

From their edit page, it’s apparent that they are using some sort of template structure that supports multiple fields. These fields can have multiple types: free text, selectable items, booleans, and so on. The fields belong to their own categories and can’t be moved, at least not by mere mortals such as myself.

从他们的编辑页面可以看出,他们正在使用某种支持多个字段的模板结构。 这些字段可以有多种类型:自由文本,可选项目,布尔值等等。 这些字段属于它们自己的类别,不能移动,至少不能像我这样的凡人那样移动。

From my understanding, this template gets applied to products and it defines what fields the product supports and in which categories the fields land. This is apparent as a hairdryer does not contain the same GPU Performance field as the console above and can’t be added either.

根据我的理解,此模板已应用于产品,并且定义了产品支持的字段以及字段所属的类别。 这很明显,因为吹风机不包含与上面的控制台相同的GPU性能字段,因此也不能添加。

要求 (Requirements)

Originally I started my product comparison site with hardcoded structures for products. As I only anticipated the need to support a small niche market that would only need at minimum three, and at most seven, different product types. But even just supporting three hardcoded product types ended up being a nightmare. The amount of code duplication was insane.

最初,我以产品的硬编码结构开始了我的产品比较站点。 正如我仅预期的那样,需要支持一个小的利基市场,该市场至少需要三个,最多七个不同的产品类型。 但是,即使仅支持三种硬编码产品类型也成为噩梦。 代码重复的数量是疯狂的。

This was no way forward. I had to try to make a better system. So I came up with a few rules that my new template system would have to work with after my failure of hardcoded product structures.

这是没有前进的路。 我不得不尝试建立一个更好的系统。 因此,我提出了一些规则这些规则在我的硬编码产品结构失败后必须与新模板系统一起使用。

  1. Abstract away all the data into the template that is common across the products.

    将所有数据提取到整个产品通用的模板中。
  2. All template data should be editable without breaking products on the page. This would mean that I could not use field/category names as keys in my database. As that would break the implementation if I would change their name

    所有模板数据应可编辑,而不会破坏页面上的产品。 这意味着我无法在数据库中使用字段/类别名称作为键。 因为如果我更改他们的名字,那将破坏实现
  3. Categories and fields should be movable inside the template, rearrangeable, re-namable, dynamic, again without breaking the products that use these templates.

    类别和字段应在模板内部可移动,可重新排列,可重命名,动态,而且又不会破坏使用这些模板的产品。
  4. Products should inherit the structure from the template.

    产品应从模板继承结构。
  5. Products should get the selectable field values from the template.

    产品应从模板获取可选字段值。
  6. Support for multiple field types.

    支持多种字段类型。

栏位类型 (Field types)

These are the following field types I came up with based on my sites requirements, from top:

这些是根据我的站点要求从头开始得出的以下字段类型:

StringField, UrlField, SingleItemField, MultiItemField.

StringField,UrlField,SingleItemField,MultiItemField。

Image for post

The first two are free text, and the last two would get their values from the template.

前两个是自由文本,后两个将从模板中获取其值。

In code:

在代码中:

Image for post
The TemplateFieldArrayValues and TemplateFields are kept in their own collection to be reusable across different templates.
TemplateFieldArrayValues和TemplateFields保留在自己的集合中,可以在不同的模板之间重用。

最后的结构 (Structure at last)

This would cover the fields but to have the data structured I had to add categories and the Template object itself to tie it all together.

这将覆盖所有字段,但要使数据结构化,我必须添加类别和Template对象本身才能将它们绑定在一起。

Image for post

The final template that matches all my requirements looks like this:

符合我所有要求的最终模板如下所示:

Image for post

产品 (The product)

As the template itself only contains the field types and selectable value types. The products need to contain actual raw values mapped to the references of the fields they belong to.

由于模板本身仅包含字段类型和可选值类型。 产品需要包含映射到其所属字段的引用的实际原始值。

An example product for that template looks like this:

该模板的示例产品如下所示:

Image for post

This product does not contain any structure, the structure is set by the template. The templateId is set in the template property.

本产品不包含任何结构,该结构由模板设置。 templateId在template属性中设置。

The values array can have raw values in any order as its the template that sets the structure of the final output.

values数组可以具有任何顺序的原始值,作为其设置最终输出结构的模板。

Each key refers to a field reference from the template.

每个键都引用模板中的字段引用。

The final output is produced by a method that combines the template and the product. It maps the raw values to the fields that they belong to.

最终输出是通过将模板和产品组合在一起的方法产生的。 它将原始值映射到它们所属的字段。

结果 (Result)

The template system ended up requiring just as much code as the initial three product structures hardcoded. But I have the peace of mind that I only have to maintain one piece of code for all product types and it allows for realtime changes on products. Any change in the template gets reflected on the products instantly. This setup also allows me to query easily based on product specifications.

模板系统最终需要与硬编码的最初三个产品结构一样多的代码。 但是我可以放心,我只需要为所有产品类型维护一段代码,它就可以实时更改产品。 模板中的任何更改都会立即反映在产品上。 此设置还使我可以轻松地根据产品规格进行查询。

The only drawback I found was that by not using the field/product names as keys I could not make fancy SEO friendly URLs as the shortIds are not SEO friendly.

我发现的唯一缺点是,由于没有使用字段/产品名称作为键,因此我无法创建精美的SEO友好URL,因为shortIds不适合SEO。

脚注 (Footnote)

I have reached out to multiple PriceSpy developers in hopes of getting more information about their setup. But I have not gotten any response.

我已经联系了多个PriceSpy开发人员,希望获得有关其设置的更多信息。 但是我没有得到任何回应。

Image for post

翻译自: https://codeburst.io/the-proper-way-of-documenting-products-daae3deb325d

java建立结构体

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值