M
Mike Labosh
Code is easy. These are two OOP design issues that I am chewing on. Coming
from classic VB, I'm not great at OO design. I prefer to write mile long
spaghetti methods in a Temp module, and then refactor them.
Issue # 1
I have an Employee class that represents the state of an Employee record,
and an EmployeeListItem class that represents Employee stuff to be loaded
into a ListBox, e.g. EmployeeID, FirstName, LastName, ReadOnly FullName,
Overrides ToString().
In both classes, the ReadOnly FullName Property returns a concatenation of
the FirstName and LastName. Also, both classes have a FullNameOrder
property which is a type of the Enum below:
Public Enum FullNameOrdering
FirstLast = 1
LastFirst = 2
LastCommaFirst = 3
End Enum
This way, an application can "choose" how to configure an employee object to
return an already built full name built the desired way.
This enumeration will only be used in these two classes, but it is
definitely used by both of them.
The enumeration must be defined somewhere, and I can't decide whether I
should put the enumeration in the Employee class, EmployeeListItem class, or
in some other global place. I guess I'm asking for where is the correct,
most OO, most modular place to put it?
Issue # 2
Both Employee and EmployeeListItem share the code below. This annoys me.
It smells like this should be common functionality through inheritance, but
it does not make sense for either of the two classes to inherit from the
other. I am thinking that I should make a "Public MustInherit EmployeeBase"
class and put this stuff in there, and then derive Employee and
EmployeeListItem from EmployeeBase. Can someone validate me on that
thought?
Public Enum FullNameOrdering
FirstLast = 1
LastFirst = 2
LastCommaFirst = 3
End Enum
Private _fullNameOrder As FullNameOrdering _
= FullNameOrdering.FirstLast
Private _employeeID As Integer = 0
Private _lastName As String
Private _firstName As String
Public Sub New()
Public Sub New(ByVal employeeID As Integer, _
ByVal lastName As String, _
ByVal firstName As String)
Public Sub New(ByVal employeeID As Integer, _
ByVal lastName As String, _
ByVal firstName As String, _
ByVal fullNameOrder As FullNameOrdering)
Public Property FullNameOrder As FullNameOrdering
Public Property EmployeeID As Integer
Public Property LastName As String
Public Property FirstName As String
Public ReadOnly Property FullName As String
Public Overrides Function ToString() As String
--
Peace & happy computing,
Mike Labosh, MCSD
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei
from classic VB, I'm not great at OO design. I prefer to write mile long
spaghetti methods in a Temp module, and then refactor them.
Issue # 1
I have an Employee class that represents the state of an Employee record,
and an EmployeeListItem class that represents Employee stuff to be loaded
into a ListBox, e.g. EmployeeID, FirstName, LastName, ReadOnly FullName,
Overrides ToString().
In both classes, the ReadOnly FullName Property returns a concatenation of
the FirstName and LastName. Also, both classes have a FullNameOrder
property which is a type of the Enum below:
Public Enum FullNameOrdering
FirstLast = 1
LastFirst = 2
LastCommaFirst = 3
End Enum
This way, an application can "choose" how to configure an employee object to
return an already built full name built the desired way.
This enumeration will only be used in these two classes, but it is
definitely used by both of them.
The enumeration must be defined somewhere, and I can't decide whether I
should put the enumeration in the Employee class, EmployeeListItem class, or
in some other global place. I guess I'm asking for where is the correct,
most OO, most modular place to put it?
Issue # 2
Both Employee and EmployeeListItem share the code below. This annoys me.
It smells like this should be common functionality through inheritance, but
it does not make sense for either of the two classes to inherit from the
other. I am thinking that I should make a "Public MustInherit EmployeeBase"
class and put this stuff in there, and then derive Employee and
EmployeeListItem from EmployeeBase. Can someone validate me on that
thought?
Public Enum FullNameOrdering
FirstLast = 1
LastFirst = 2
LastCommaFirst = 3
End Enum
Private _fullNameOrder As FullNameOrdering _
= FullNameOrdering.FirstLast
Private _employeeID As Integer = 0
Private _lastName As String
Private _firstName As String
Public Sub New()
Public Sub New(ByVal employeeID As Integer, _
ByVal lastName As String, _
ByVal firstName As String)
Public Sub New(ByVal employeeID As Integer, _
ByVal lastName As String, _
ByVal firstName As String, _
ByVal fullNameOrder As FullNameOrdering)
Public Property FullNameOrder As FullNameOrdering
Public Property EmployeeID As Integer
Public Property LastName As String
Public Property FirstName As String
Public ReadOnly Property FullName As String
Public Overrides Function ToString() As String
--
Peace & happy computing,
Mike Labosh, MCSD
Owner, vbSensei.Com
"Escriba coda ergo sum." -- vbSensei