R
RSH
I am still trying to grasp the use of real world Objects and how to
conceptualize them using a business scenerio.
What I have below is an outline that I am wrestling with trying to figure
out a class structure:\
Top level Objects:
Companies
Employees
Under Companies I have:
CompanyDeductions
CompanyAccruals
CompanyTaxes
Under Employees I have:
EmployeeDeductions
EmployeeAccruals
EmployeeTaxes
Now my question is how should I setup my classes based on that information
above?
I originally thought about making Company the base Class and Have the
CompanyDeductions,Accruals and Taxes inherit the Company Class, but I'm not
sure thats the way to go. My other thought then became just having The
Deductions Accruals and Tax information as optional properties under the
company so that the Employees, which belong to companies could inherit the
company class.
How would you suggest I go about setting up my class structure?
Companies would be a collection of Company objects
Company Deductions, CompanyAccruals and CompanyTaxes contain meta data that
apply to all employees who are assigned these items
There are similarities but they are different enough to warrant seperate
objects I believe. They would contain different methods for calculations
and different properties shortly after dropping below the surface.
With that being said the Employees indeed have employeeDeductions which
would tie to the CompanyDeductions. The employee Deductions would have
rate, percent, pretax etc.
I drafted up a quick model below...
Is this a bad practice to reference other objects from within an object?
Thanks so much for your help!
Ron
Module Module1
Sub Main()
Dim Company1 As New Company("00000001", "Rons Test Co.", "12-3456789")
Dim Company2 As New Company("00000002", "Bills House of Bugs", "98-3456789")
Company1.AddDeduction("401k", "Company 401k Program")
Company1.AddDeduction("Uniform", "Company Uniforms")
Company2.AddAccrual("Sick", "Sick")
Company2.AddAccrual("Vacation", "Vacation")
Company1.Print("Deductions")
Company2.Print("Accruals")
Console.ReadLine()
Company1.SetDeductionRate("401k", 23.45)
Company1.Print("Deductions")
End Sub
End Module
Public Class Company
Private _CompanyID As String
Private _CompanyName As String
Private _FEIN As String
Private _CompanyDeductions As New Hashtable
Private _CompanyAccruals As New Hashtable
Public Sub New(ByVal CompanyID As String, ByVal CompanyName As String, ByVal
FEIN As String)
_CompanyID = CompanyID
_CompanyName = CompanyName
_FEIN = FEIN
End Sub
Public Property CompanyID() As String
Get
Return _CompanyID
End Get
Set(ByVal value As String)
_CompanyID = value
End Set
End Property
Public Property CompanyName() As String
Get
Return _CompanyName
End Get
Set(ByVal value As String)
_CompanyName = value
End Set
End Property
Public Property FEIN() As String
Get
Return _FEIN
End Get
Set(ByVal value As String)
_FEIN = value
End Set
End Property
Public Sub AddDeduction(ByVal DeductionID As String, ByVal DeductionName As
String)
Dim cd As CompanyDeduction = New CompanyDeduction(DeductionID,
DeductionName)
_CompanyDeductions.Add(DeductionID, cd)
End Sub
Public Sub AddAccrual(ByVal AccrualID As String, ByVal AccrualName As
String)
Dim ca As CompanyAccrual = New CompanyAccrual(AccrualID, AccrualName)
_CompanyAccruals.Add(AccrualID, ca)
End Sub
Public Sub SetDeductionRate(ByVal DeductionID As String, ByVal Rate As
Double)
Dim cd As CompanyDeduction
cd = _CompanyDeductions(DeductionID)
cd.Rate = Rate
End Sub
Public Sub Print(ByVal type As String)
Console.WriteLine(vbCrLf)
Dim al As New Hashtable
Dim i As Integer
Console.WriteLine("CompanyId:" & _CompanyID & " CompanyName:" &
_CompanyName)
Select Case Type
Case "Deductions"
al = _CompanyDeductions
Case "Accruals"
al = _CompanyAccruals
End Select
If al.Count > 0 Then
Console.WriteLine(type & " ID" & vbTab & type & " Name" & vbTab & " Rate")
Console.WriteLine("---------------------------------------")
Dim myEnumerator As IDictionaryEnumerator = al.GetEnumerator()
While myEnumerator.MoveNext()
Console.WriteLine("{0} : {1}", myEnumerator.Value(0))
End While
Else
Console.WriteLine("No " & Type & " exist for this company")
End If
End Sub
End Class
NotInheritable Class CompanyDeduction
Private _ID As String
Private _Name As String
Private _Rate As Double
Public Sub New(ByVal ID As String, ByVal Name As String)
_ID = ID
_Name = Name
End Sub
Public Property ID() As String
Get
Return _ID
End Get
Set(ByVal value As String)
_ID = value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property Rate() As Double
Get
Return _Rate
End Get
Set(ByVal value As Double)
_Rate = value
End Set
End Property
End Class
NotInheritable Class CompanyAccrual
Private _ID As String
Private _Name As String
Private _Rate As Double
Public Sub New(ByVal ID As String, ByVal Name As String)
_ID = ID
_Name = Name
End Sub
Public Property ID() As String
Get
Return _ID
End Get
Set(ByVal value As String)
_ID = value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property Rate() As Double
Get
Return _Rate
End Get
Set(ByVal value As Double)
_Rate = value
End Set
End Property
End Class
conceptualize them using a business scenerio.
What I have below is an outline that I am wrestling with trying to figure
out a class structure:\
Top level Objects:
Companies
Employees
Under Companies I have:
CompanyDeductions
CompanyAccruals
CompanyTaxes
Under Employees I have:
EmployeeDeductions
EmployeeAccruals
EmployeeTaxes
Now my question is how should I setup my classes based on that information
above?
I originally thought about making Company the base Class and Have the
CompanyDeductions,Accruals and Taxes inherit the Company Class, but I'm not
sure thats the way to go. My other thought then became just having The
Deductions Accruals and Tax information as optional properties under the
company so that the Employees, which belong to companies could inherit the
company class.
How would you suggest I go about setting up my class structure?
Companies would be a collection of Company objects
Company Deductions, CompanyAccruals and CompanyTaxes contain meta data that
apply to all employees who are assigned these items
There are similarities but they are different enough to warrant seperate
objects I believe. They would contain different methods for calculations
and different properties shortly after dropping below the surface.
With that being said the Employees indeed have employeeDeductions which
would tie to the CompanyDeductions. The employee Deductions would have
rate, percent, pretax etc.
I drafted up a quick model below...
Is this a bad practice to reference other objects from within an object?
Thanks so much for your help!
Ron
Module Module1
Sub Main()
Dim Company1 As New Company("00000001", "Rons Test Co.", "12-3456789")
Dim Company2 As New Company("00000002", "Bills House of Bugs", "98-3456789")
Company1.AddDeduction("401k", "Company 401k Program")
Company1.AddDeduction("Uniform", "Company Uniforms")
Company2.AddAccrual("Sick", "Sick")
Company2.AddAccrual("Vacation", "Vacation")
Company1.Print("Deductions")
Company2.Print("Accruals")
Console.ReadLine()
Company1.SetDeductionRate("401k", 23.45)
Company1.Print("Deductions")
End Sub
End Module
Public Class Company
Private _CompanyID As String
Private _CompanyName As String
Private _FEIN As String
Private _CompanyDeductions As New Hashtable
Private _CompanyAccruals As New Hashtable
Public Sub New(ByVal CompanyID As String, ByVal CompanyName As String, ByVal
FEIN As String)
_CompanyID = CompanyID
_CompanyName = CompanyName
_FEIN = FEIN
End Sub
Public Property CompanyID() As String
Get
Return _CompanyID
End Get
Set(ByVal value As String)
_CompanyID = value
End Set
End Property
Public Property CompanyName() As String
Get
Return _CompanyName
End Get
Set(ByVal value As String)
_CompanyName = value
End Set
End Property
Public Property FEIN() As String
Get
Return _FEIN
End Get
Set(ByVal value As String)
_FEIN = value
End Set
End Property
Public Sub AddDeduction(ByVal DeductionID As String, ByVal DeductionName As
String)
Dim cd As CompanyDeduction = New CompanyDeduction(DeductionID,
DeductionName)
_CompanyDeductions.Add(DeductionID, cd)
End Sub
Public Sub AddAccrual(ByVal AccrualID As String, ByVal AccrualName As
String)
Dim ca As CompanyAccrual = New CompanyAccrual(AccrualID, AccrualName)
_CompanyAccruals.Add(AccrualID, ca)
End Sub
Public Sub SetDeductionRate(ByVal DeductionID As String, ByVal Rate As
Double)
Dim cd As CompanyDeduction
cd = _CompanyDeductions(DeductionID)
cd.Rate = Rate
End Sub
Public Sub Print(ByVal type As String)
Console.WriteLine(vbCrLf)
Dim al As New Hashtable
Dim i As Integer
Console.WriteLine("CompanyId:" & _CompanyID & " CompanyName:" &
_CompanyName)
Select Case Type
Case "Deductions"
al = _CompanyDeductions
Case "Accruals"
al = _CompanyAccruals
End Select
If al.Count > 0 Then
Console.WriteLine(type & " ID" & vbTab & type & " Name" & vbTab & " Rate")
Console.WriteLine("---------------------------------------")
Dim myEnumerator As IDictionaryEnumerator = al.GetEnumerator()
While myEnumerator.MoveNext()
Console.WriteLine("{0} : {1}", myEnumerator.Value(0))
End While
Else
Console.WriteLine("No " & Type & " exist for this company")
End If
End Sub
End Class
NotInheritable Class CompanyDeduction
Private _ID As String
Private _Name As String
Private _Rate As Double
Public Sub New(ByVal ID As String, ByVal Name As String)
_ID = ID
_Name = Name
End Sub
Public Property ID() As String
Get
Return _ID
End Get
Set(ByVal value As String)
_ID = value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property Rate() As Double
Get
Return _Rate
End Get
Set(ByVal value As Double)
_Rate = value
End Set
End Property
End Class
NotInheritable Class CompanyAccrual
Private _ID As String
Private _Name As String
Private _Rate As Double
Public Sub New(ByVal ID As String, ByVal Name As String)
_ID = ID
_Name = Name
End Sub
Public Property ID() As String
Get
Return _ID
End Get
Set(ByVal value As String)
_ID = value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Public Property Rate() As Double
Get
Return _Rate
End Get
Set(ByVal value As Double)
_Rate = value
End Set
End Property
End Class