收集/业务对象澄清

时间:2017-01-29 13:05:20

标签: .net vb.net

我刚刚在该论坛上阅读了几个主题,并决定直接询问专家关于我在其下面的内容是否更像是收集类Variation,或者更像是业务对象。它是正确的还是我应该从类变体直接移动到类Variation。

我的课名为:

 Class Variation
Implements IComparable(Of Variation)
           #Region "Properties"
        Property Name As String
        Property Position As SByte
#End Region

#Region "Constructors"
        Sub New()
            MyBase.New(New VariationDAL)
        End Sub
        Sub New(pId As Integer)
            MyBase.New(New VariationDAL)
            Id = pId
        End Sub
        Sub New(pName As String)
            MyBase.New(New VariationDAL)
            Name = pName
        End Sub

Public Function CompareTo(pother As Variation) As Integer Implements IComparable(Of Variation).CompareTo    
            Return String.Compare(Me.Position, pother.Position)
        End Function
        Public Function FindPredicate(ByVal pvariation As Variation) As Predicate(Of Variation)
            Return Function(pvariation2 As Variation) pvariation.Id = pvariation2.Id
        End Function
        Public Function FindPredicateByUserId(ByVal pvariation As String) As Predicate(Of Variation)
            Return Function(pvariation2 As Variation) pvariation = pvariation2.Id
        End Function

    End Class

然后我使用下面的类来存储上面类的集合:

Public Class Variations
        Implements IDisposable

        Public Collection As List(Of Variation)

        Sub New()
            Collection = New List(Of Variation)
        End Sub

        Public Function AddToCollection(ByVal variation As Variation) As Boolean
            If variation.Position <> 100 And variation.Name = "23333" Then
                Collection.Add(variation)
            End If
            Return True
        End Function

        Public Sub RemoveFromCollection(index As Integer)
            If Not IsNothing(Collection.Item(index)) Then
                Collection.RemoveAt(index)
            End If
        End Sub

        Public Sub SortByPosition()
            Collection.Sort()
        End Sub

        Public Sub RemoveFromCollectionX(ByVal variation As Variation)
            For Each item In Collection
                If item.Name = variation.Name And item.Position = variation.Position Then
                    Collection.Remove(item)
                    Exit For
                End If
            Next
        End Sub

        Private Sub ReorderCollection()
            '...
        End Sub

'other methods related to collection manipulation

End Class

0 个答案:

没有答案