【发布时间】:2010-01-15 20:35:39
【问题描述】:
将项目 X 的子集合存储在项目 X 的父集合中以缓存在父集合上执行的“过滤器查询”是否是一种好习惯? (它们不会一起使用(如颜色和类型)。) 或者只循环集合并在临时集合中返回正确的实体也可以吗?
Class ItemCollection : Inherits Collection(Of Item)
Private _types as New List(Of ItemCollection) //Cache
Function FilterByType(type) As ItemCollection
If Not _types.KeyExists(type) Then
_types.Add(type, New ItemCollection())
For Each i in Me
If i.Type = type Then _types(type).Add(i)
Next
End If
Return _types(type)
End Function
//Same for FilterByColor(color)
End Class
Class Item
Public Color = "Blue"
Public [Type] = "One"
End Class
【问题讨论】:
标签: .net vb.net collections