vendredi 12 mai 2017

Domain Model that has no methods?

I am looking at some code from a Business Layer, which looks like this:

Public Class Member
        Inherits BusinessObject

        Public Sub New()
            ' establish business rules

            AddRule(New ValidateId("MemberId"))

            AddRule(New ValidateRequired("Email"))
            AddRule(New ValidateLength("Email", 1, 100))
            AddRule(New ValidateEmail("Email"))

            AddRule(New ValidateRequired("CompanyName"))
            AddRule(New ValidateLength("CompanyName", 1, 40))

            AddRule(New ValidateRequired("City"))
            AddRule(New ValidateLength("City", 1, 15))

            AddRule(New ValidateRequired("Country"))
            AddRule(New ValidateLength("Country", 1, 15))
        End Sub

        Public Property MemberId() As Integer

        Public Property Email() As String
        Public Property CompanyName() As String
        Public Property City() As String
        Public Property Country() As String
        Public Property NumOrders() As Integer
        Public Property LastOrderDate() As Date
    End Class

All the Business Objects look like the above i.e. there are no methods. There are then BusinessRule classes, which look like this:

Public MustInherit Class BusinessRule
        Public Property [Property]() As String
        Public Property [Error]() As String

        Public Sub New(ByVal [property] As String)
            Me.Property = [property]
            [Error] = [property] & " is not valid"
        End Sub

        Public Sub New(ByVal [property] As String, ByVal [error] As String)
            Me.New([property])
            Me.Error = [error]
        End Sub

        ' validation method. To be implemented in derived classes

        Public MustOverride Function Validate(ByVal businessObject As BusinessObject) As Boolean

        ' gets value for given business object's property using reflection

        Protected Function GetPropertyValue(ByVal businessObject As BusinessObject) As Object
            ' note: reflection is relatively slow
            Return businessObject.GetType().GetProperty([Property]).GetValue(businessObject, Nothing)
        End Function
    End Class
End Namespace

Is this an anemic model or a domain model? It looks anemic to me because state and behaviour appear to be separated. However, it was described online as a domain model.

Aucun commentaire:

Enregistrer un commentaire