patternMinor
Model-View-Presenter
Viewed 0 times
presentermodelview
Problem
I work on a .NET application that very loosely follows an n-tier kind of architecture (the business objects (not logic) and data access are split out). We are now looking to start refactoring the code into an MVP architecture. Based on some previous work done by someone else, I just refactored a screen into what I hope is MVP.
The form code:
```
Imports System.Windows.Forms
Imports ExceptionLibrary.UIExceptionCatcher
Imports BusinessEntity.OE
Imports OurClient.MainModule.Constants
_
Partial Public Class AutoService
Inherits UILibrary.CustomViewControl
Implements IAutoService
Private _objAutoServiceBE As New AutoServiceBE
Private _isEditMode As Boolean
Private _intCurrentUserId As Integer
Private _intNewAddedAutoServiceId As Integer
Private _intAutoServiceID As Integer
Public Event Close(ByVal sender As Object, ByVal e As EventArgs) Implements IAutoService.Close
Public Event Save(ByVal sender As Object, ByVal e As EventArgs) Implements IAutoService.Save
Public Event FormLoad(ByVal e As EventArgs) Implements IAutoService.ViewLoad
Public Property AutoService As BusinessEntity.OE.AutoServiceBE Implements IAutoService.AutoService
Get
Return _objAutoServiceBE
End Get
Set(value As BusinessEntity.OE.AutoServiceBE)
_objAutoServiceBE = value
End Set
End Property
Public Property AutoServiceCode As String Implements IAutoService.AutoServiceCode
Get
Return txtCode.Text
End Get
Set(value As String)
txtCode.Text = value
End Set
End Property
Public Property AutoServiceName As String Implements IAutoService.AutoServiceName
Get
Return txtName.Text
End Get
Set(value As String)
txtName.Text = value
End Set
End Property
Public Property AutoServiceID() As Integer Implements IAutoService.AutoServiceID
Get
Return _intAutoService
The form code:
```
Imports System.Windows.Forms
Imports ExceptionLibrary.UIExceptionCatcher
Imports BusinessEntity.OE
Imports OurClient.MainModule.Constants
_
Partial Public Class AutoService
Inherits UILibrary.CustomViewControl
Implements IAutoService
Private _objAutoServiceBE As New AutoServiceBE
Private _isEditMode As Boolean
Private _intCurrentUserId As Integer
Private _intNewAddedAutoServiceId As Integer
Private _intAutoServiceID As Integer
Public Event Close(ByVal sender As Object, ByVal e As EventArgs) Implements IAutoService.Close
Public Event Save(ByVal sender As Object, ByVal e As EventArgs) Implements IAutoService.Save
Public Event FormLoad(ByVal e As EventArgs) Implements IAutoService.ViewLoad
Public Property AutoService As BusinessEntity.OE.AutoServiceBE Implements IAutoService.AutoService
Get
Return _objAutoServiceBE
End Get
Set(value As BusinessEntity.OE.AutoServiceBE)
_objAutoServiceBE = value
End Set
End Property
Public Property AutoServiceCode As String Implements IAutoService.AutoServiceCode
Get
Return txtCode.Text
End Get
Set(value As String)
txtCode.Text = value
End Set
End Property
Public Property AutoServiceName As String Implements IAutoService.AutoServiceName
Get
Return txtName.Text
End Get
Set(value As String)
txtName.Text = value
End Set
End Property
Public Property AutoServiceID() As Integer Implements IAutoService.AutoServiceID
Get
Return _intAutoService
Solution
Public ReadOnly Property PvcValidateRequiredFields As Boolean Implements IAutoService.PvcValidateRequiredFields
Get
Return ValidateRequiredFields()
End Get
End PropertyI looked through the code and this looked really odd to me, so I went looking for the method
ValidateRequiredFields() and could not find it in the code that you have provided. instead of creating a property that returns that value of a method/function you should just allow the method/function to be called. That method should return a boolean (true/false) value. Are the required fields there or not? that should be available to the caller.
Why did you leave this code out of the question? I don't know.
This doesn't seem to be the complete code set
Code Snippets
Public ReadOnly Property PvcValidateRequiredFields As Boolean Implements IAutoService.PvcValidateRequiredFields
Get
Return ValidateRequiredFields()
End Get
End PropertyContext
StackExchange Code Review Q#86876, answer score: 4
Revisions (0)
No revisions yet.