The Model


TODO: write about...
  • the View's life cycle

In MVP, the Model is concerned with representing the data that will be displayed through the View. There is usually a one-to-one correspondence between a Model and its View. The Model is not necessarily a distinct business entity or custom business object in the system. Rather, the Model is composed of only the object(s) that are of interest to the View.

As such, in a DotNetNuke MVP module, the Model is not the same thing as the module's Custom Business Objects. For example, if a particular View was responsible for displaying a list of users in a DotNetNuke portal, the corresponding Model would have a List(Of UserInfo) property, as in the following example.

VB.NET
Public Class ViewPortalUsersModel
    Private _PortalUsers As List(Of UserInfo)

    Public Property PortalUsers() As List(Of UserInfo)
        Get
            Return _PortalUsers
        End Get
        Set(ByVal value As List(Of UserInfo))
            _PortalUsers = value
        End Set
    End Property
End Class

C#
public class ViewPortalUsersModel
{
    private List<UserInfo> _PortalUsers;

    public List(Of UserInfo) PortalUsers()
    {
        get { return _PortalUsers; }
        set { _PortalUsers = value; }
    }
}

Similarly, if a View was to show the members of a team (again, using each person's UserInfo data) along with the team name and team leader, the corresponding Model might look something like this.

VB.NET
Public Class ViewTeamModel
    Private _TeamName As String
    Public Property TeamName() As String
        Get
            Return _TeamName
        End Get
        Set(ByVal value As String)
            _TeamName = value
        End Set
    End Property

    Private _Leader As UserInfo
    Public Property Leader() As UserInfo
        Get
            Return _Leader
        End Get
        Set(ByVal value As UserInfo)
            _Leader = value
        End Set
    End Property

    Private _TeamMembers As List(Of UserInfo)
    Public Property TeamMembers() As List(Of UserInfo)
        Get
            Return _TeamMembers
        End Get
        Set(ByVal value As List(Of UserInfo))
            _TeamMembers = value
        End Set
    End Property
End Class

C#
public class ViewTeamModel
{
    private List<UserInfo> _TeamName;
    public String TeamName()
    {
        get { return _TeamName; }
        set { _TeamName = value; }
    }

    private List<UserInfo> _Leader;
    public List(Of UserInfo) Leader()
    {
        get { return _Leader; }
        set { _Leader = value; }
    }

    private List<UserInfo> _TeamMembers;
    public List(Of UserInfo) TeamMembers()
    {
        get { return _TeamMembers; }
        set { _TeamMembers = value; }
    }
}

Last edited Jul 3, 2010 at 4:50 AM by dagilleland, version 2

Comments

No comments yet.