[英]Storing/serializing list of objects
I oftem run into this case of what is the correct way to store a list of objects as a property in a class and how to properly serialize them into XML. 我碰到这种情况,这是将对象列表作为属性存储在类中的正确方法是什么,以及如何正确地将它们序列化为XML。
For instance, we have a TabGroup class which will contain zero or multiple Tabs. 例如,我们有一个TabGroup类,它将包含零个或多个Tab。
Is it better to a have a list of Tabs property or a list of references to Tabs? 拥有Tabs属性列表或Tabs引用列表是否更好? Provided that Tabs are identified by slugs which are unique.
假设标签由唯一的块标识。
List<Tab>
List<string>
In the end it comes down to 最后归结为
Most notable pro of 1: 最引人注目的职业玩家1:
Most notable con of 1: 最值得注意的缺点1:
Most notable pro of 2: 最著名的职业玩家2:
Most notable con of 2 (this is the main reason why I am writing this) 最引人注目的2(这是我写这篇文章的主要原因)
What do you suggest to tackle this problem? 您对解决这个问题有何建议? I will accept the answer that will cover a wide array of implications.
我将接受涵盖广泛含义的答案。 Please note that we are talking only about XML persistence here, obviously in SQL we have little room to experiment since Tabgroups and Tabs would normally be in separate tables anyway (with a one-many relationship between them).
请注意,这里我们仅谈论XML持久性,显然在SQL中,我们没有什么实验的余地,因为Tabgroups和Tabs通常无论如何都位于单独的表中(它们之间是一对多的关系)。
Unless you have some very compelling reason why complicating the data store is a good idea, you should typically go with keeping it simple. 除非您有非常令人信服的理由来简化数据存储是个好主意,否则通常应保持简单。 Secondly, having read the entire post twice, I do not really understand what your question is.
其次,阅读了整篇文章两次,我真的不明白您的问题是什么。
I'm not quite sure what your problem is, but if you are asking whether your design should return a List<Tab>
or List<string>
where each string represents a link to a tab, then I would argue for List<Tab>
. 我不太确定您的问题是什么,但是如果您要问设计是返回
List<Tab>
还是List<string>
,其中每个字符串代表指向选项卡的链接,那么我会建议使用List<Tab>
。 You can lazy load the entire structure except for the ID or whatever you were using for a link if loading is an issue. 您可以延迟加载整个结构,但要避免加载ID或链接所用的任何内容(ID除外)。 Generally it just makes things easier to get what you were looking for directly out of an object instead of having to get a list of links and load all of the links individually.
通常,它使从对象中直接获取所需内容变得更加容易,而不必获取链接列表并单独加载所有链接。
Without more information specific to the actual problem, I doubt anyone would be able to help you more than that other than to give some long winded pros/cons based on assumed circumstances. 如果没有更多有关实际问题的信息,我怀疑除了根据假定的情况给出一些长远的优点/缺点之外,任何人都可以为您提供更多帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.