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 12 1276
I"m not sure I understand the business practice. Are you doing
accounting/finance?
Two approaches came to mind. The first is to use a interface to
implement required features, and have the interface expose Deductions,
Accurals, and Taxes.
Or, you could also have a Deduction(s) Class, Accural(s) Class, and
Tax(es) Class, then :
Class Company
Public Deductions as New Deductions
Public Accurals as New Accurals
Public Taxes as New Taxes
End Class
Repeat for employees.
Assuming that Deductions is a collection class with a .Add method, then
:
Dim c as New Company
c.Deductions.Add (New Deduction("401K", "401K Program")
Chris
RSH wrote:
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
RSH,
Creating classic data classes is only a partial thing of OO, what is not
direct OOP.
And because of the fact that those classic dataclasses are mostly useless in
dotNet, I would take more an eye on using the full OOP implementing classes
from AdoNet which are related to SQL implementing databases.
Just my thought,
Cor
"RSH" <wa*************@yahoo.comschreef in bericht
news:eG*************@TK2MSFTNGP04.phx.gbl...
>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
I am struggling with interfaces. I am intrigued by that option that you put
out. Would it be possible for you to do a quick code sample of how I might
set that up?
My business practice is payroll in this exersize...but I am more or less
just trying to learn OOP principals that apply to my own class structures.
Thanks for the insight!
ron
<ch************@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
I"m not sure I understand the business practice. Are you doing
accounting/finance?
Two approaches came to mind. The first is to use a interface to
implement required features, and have the interface expose Deductions,
Accurals, and Taxes.
Or, you could also have a Deduction(s) Class, Accural(s) Class, and
Tax(es) Class, then :
Class Company
Public Deductions as New Deductions
Public Accurals as New Accurals
Public Taxes as New Taxes
End Class
Repeat for employees.
Assuming that Deductions is a collection class with a .Add method, then
:
Dim c as New Company
c.Deductions.Add (New Deduction("401K", "401K Program")
Chris
RSH wrote:
>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
Cor,
Is there an article or series of articles that you would reccomend to alter
my thinking on the subject?
I will definitely admit I am new to OOP principals and while I have been
programming heavily with databases for a number of years it is a very
difficult thing to unleash the datacentric tendencies that I have. I
suppose the fact that pretty much every tutorial I see relates objects to
real world objects (dogs, cats, animals etc.) that I am taking it too
literally by implementing objects at face value.
I would love for you to elaborate a bit more as this sort of conceptual
discussions is very enlightening.
Thanks!
Ron
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
RSH,
Creating classic data classes is only a partial thing of OO, what is not
direct OOP.
And because of the fact that those classic dataclasses are mostly useless
in dotNet, I would take more an eye on using the full OOP implementing
classes from AdoNet which are related to SQL implementing databases.
Just my thought,
Cor
"RSH" <wa*************@yahoo.comschreef in bericht
news:eG*************@TK2MSFTNGP04.phx.gbl...
>>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
If you want to understand how the business object logic
works with OO, I recommend "Understanding Objects in VB"
by Deborah Kurata. She has a VB2005 version coming out in
January or February. It really gave me the understanding
I needed to build an application by starting with the
classes and then doing the UI, etc.
She has a VB6 version of the book -- there are some for
sale on Amazon for 50 cents + shipping. This would certainly
give you the general idea, and be fairly painless. I would
definitely check out her book when it comes out early
next year.
Just an idea.
Robin S.
------------------------------------------------
"RSH" <wa*************@yahoo.comwrote in message
news:OE**************@TK2MSFTNGP04.phx.gbl...
Cor,
Is there an article or series of articles that you would reccomend to
alter my thinking on the subject?
I will definitely admit I am new to OOP principals and while I have been
programming heavily with databases for a number of years it is a very
difficult thing to unleash the datacentric tendencies that I have. I
suppose the fact that pretty much every tutorial I see relates objects to
real world objects (dogs, cats, animals etc.) that I am taking it too
literally by implementing objects at face value.
I would love for you to elaborate a bit more as this sort of conceptual
discussions is very enlightening.
Thanks!
Ron
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>RSH,
Creating classic data classes is only a partial thing of OO, what is not direct OOP.
And because of the fact that those classic dataclasses are mostly useless in dotNet, I would take more an eye on using the full OOP implementing classes from AdoNet which are related to SQL implementing databases.
Just my thought,
Cor "RSH" <wa*************@yahoo.comschreef in bericht news:eG*************@TK2MSFTNGP04.phx.gbl...
>>>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
RSH,
The OOP is based on creating objects from pre defined classes *every time*
you need to do something.
Those can be your own classes, but in dotNet mostly it are those given to
you by the framework.
That opposite to the modular model where you create a big program with in
fact everything all the time predefined in it.
Just start, try to avoid modules, static classes, structures and declare
things global and you will see that you are quickly busy with OOP
programming as you are using VB.Net.
VB.Net has not any thing in it, to prevent you doing this (beside the crazy
C# type warnings in the version 2005)..
For others, with this I don't say that you should forever not use those
things I wrote to avoid, it is just to learn the concepts of OOP.
Cor
"RSH" <wa*************@yahoo.comschreef in bericht
news:OE**************@TK2MSFTNGP04.phx.gbl...
Cor,
Is there an article or series of articles that you would reccomend to
alter my thinking on the subject?
I will definitely admit I am new to OOP principals and while I have been
programming heavily with databases for a number of years it is a very
difficult thing to unleash the datacentric tendencies that I have. I
suppose the fact that pretty much every tutorial I see relates objects to
real world objects (dogs, cats, animals etc.) that I am taking it too
literally by implementing objects at face value.
I would love for you to elaborate a bit more as this sort of conceptual
discussions is very enlightening.
Thanks!
Ron
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>RSH,
Creating classic data classes is only a partial thing of OO, what is not direct OOP.
And because of the fact that those classic dataclasses are mostly useless in dotNet, I would take more an eye on using the full OOP implementing classes from AdoNet which are related to SQL implementing databases.
Just my thought,
Cor "RSH" <wa*************@yahoo.comschreef in bericht news:eG*************@TK2MSFTNGP04.phx.gbl...
>>>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
It can be read in another way, therefore read that part of the text as
Try to avoid all things as modules, static classes, structures and declaring
things globaly
Cor
things
"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:up**************@TK2MSFTNGP04.phx.gbl...
RSH,
The OOP is based on creating objects from pre defined classes *every time*
you need to do something.
Those can be your own classes, but in dotNet mostly it are those given to
you by the framework.
That opposite to the modular model where you create a big program with in
fact everything all the time predefined in it.
Just start, try to avoid modules, static classes, structures and declare
things global and you will see that you are quickly busy with OOP
programming as you are using VB.Net.
VB.Net has not any thing in it, to prevent you doing this (beside the
crazy C# type warnings in the version 2005)..
For others, with this I don't say that you should forever not use those
things I wrote to avoid, it is just to learn the concepts of OOP.
Cor
"RSH" <wa*************@yahoo.comschreef in bericht
news:OE**************@TK2MSFTNGP04.phx.gbl...
>Cor,
Is there an article or series of articles that you would reccomend to alter my thinking on the subject?
I will definitely admit I am new to OOP principals and while I have been programming heavily with databases for a number of years it is a very difficult thing to unleash the datacentric tendencies that I have. I suppose the fact that pretty much every tutorial I see relates objects to real world objects (dogs, cats, animals etc.) that I am taking it too literally by implementing objects at face value.
I would love for you to elaborate a bit more as this sort of conceptual discussions is very enlightening.
Thanks! Ron
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
>>RSH,
Creating classic data classes is only a partial thing of OO, what is not direct OOP.
And because of the fact that those classic dataclasses are mostly useless in dotNet, I would take more an eye on using the full OOP implementing classes from AdoNet which are related to SQL implementing databases.
Just my thought,
Cor "RSH" <wa*************@yahoo.comschreef in bericht news:eG*************@TK2MSFTNGP04.phx.gbl... 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
doh,
Shared classes instead "static" classes.
Cor
"Cor Ligthert [MVP]" <no************@planet.nlschreef in bericht
news:up**************@TK2MSFTNGP04.phx.gbl...
RSH,
The OOP is based on creating objects from pre defined classes *every time*
you need to do something.
Those can be your own classes, but in dotNet mostly it are those given to
you by the framework.
That opposite to the modular model where you create a big program with in
fact everything all the time predefined in it.
Just start, try to avoid modules, static classes, structures and declare
things global and you will see that you are quickly busy with OOP
programming as you are using VB.Net.
VB.Net has not any thing in it, to prevent you doing this (beside the
crazy C# type warnings in the version 2005)..
For others, with this I don't say that you should forever not use those
things I wrote to avoid, it is just to learn the concepts of OOP.
Cor
"RSH" <wa*************@yahoo.comschreef in bericht
news:OE**************@TK2MSFTNGP04.phx.gbl...
>Cor,
Is there an article or series of articles that you would reccomend to alter my thinking on the subject?
I will definitely admit I am new to OOP principals and while I have been programming heavily with databases for a number of years it is a very difficult thing to unleash the datacentric tendencies that I have. I suppose the fact that pretty much every tutorial I see relates objects to real world objects (dogs, cats, animals etc.) that I am taking it too literally by implementing objects at face value.
I would love for you to elaborate a bit more as this sort of conceptual discussions is very enlightening.
Thanks! Ron
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
>>RSH,
Creating classic data classes is only a partial thing of OO, what is not direct OOP.
And because of the fact that those classic dataclasses are mostly useless in dotNet, I would take more an eye on using the full OOP implementing classes from AdoNet which are related to SQL implementing databases.
Just my thought,
Cor "RSH" <wa*************@yahoo.comschreef in bericht news:eG*************@TK2MSFTNGP04.phx.gbl... 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
Why is it best to avoid Modules and Structures? I just finished a
VB.NET class and those two components seemed to me to be very useful
and commonly used.
Thanks,
Daniel
On Nov 10, 12:07 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
doh,
Shared classes instead "static" classes.
Cor
"Cor Ligthert [MVP]" <notmyfirstn...@planet.nlschreef in berichtnews:up**************@TK2MSFTNGP04.phx.gbl. ..
RSH,
The OOP is based on creating objects from pre defined classes *every time*
you need to do something.
Those can be your own classes, but in dotNet mostly it are those given to
you by the framework.
That opposite to the modular model where you create a big program with in
fact everything all the time predefined in it.
Just start, try to avoid modules, static classes, structures and declare
things global and you will see that you are quickly busy with OOP
programming as you are using VB.Net.
VB.Net has not any thing in it, to prevent you doing this (beside the
crazy C# type warnings in the version 2005)..
For others, with this I don't say that you should forever not use those
things I wrote to avoid, it is just to learn the concepts of OOP.
Cor
"RSH" <way_beyond_o...@yahoo.comschreef in bericht
news:OE**************@TK2MSFTNGP04.phx.gbl...
Cor,
Is there an article or series of articles that you would reccomend to
alter my thinking on the subject?
I will definitely admit I am new to OOP principals and while I have been
programming heavily with databases for a number of years it is a very
difficult thing to unleash the datacentric tendencies that I have. I
suppose the fact that pretty much every tutorial I see relates objects to
real world objects (dogs, cats, animals etc.) that I am taking it too
literally by implementing objects at face value.
I would love for you to elaborate a bit more as this sort of conceptual
discussions is very enlightening.
Thanks!
Ron
"Cor Ligthert [MVP]" <notmyfirstn...@planet.nlwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl... RSH,
>Creating classic data classes is only a partial thing of OO, what is not direct OOP.
>And because of the fact that those classic dataclasses are mostly useless in dotNet, I would take more an eye on using the full OOP implementing classes from AdoNet which are related to SQL implementing databases.
>Just my thought,
>Cor "RSH" <way_beyond_o...@yahoo.comschreef in bericht news:eG*************@TK2MSFTNGP04.phx.gbl... 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
Daniel,
Read my message complete (the original one), I did not write what you said I
wrote.
Cor
"Daniel" <da**********@gmail.comschreef in bericht
news:11**********************@i42g2000cwa.googlegr oups.com...
>
Why is it best to avoid Modules and Structures? I just finished a
VB.NET class and those two components seemed to me to be very useful
and commonly used.
Thanks,
Daniel
On Nov 10, 12:07 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
>doh,
Shared classes instead "static" classes.
Cor
"Cor Ligthert [MVP]" <notmyfirstn...@planet.nlschreef in berichtnews:up**************@TK2MSFTNGP04.phx.gbl ...
RSH,
The OOP is based on creating objects from pre defined classes *every
time*
you need to do something.
Those can be your own classes, but in dotNet mostly it are those given
to
you by the framework.
That opposite to the modular model where you create a big program with
in
fact everything all the time predefined in it.
Just start, try to avoid modules, static classes, structures and
declare
things global and you will see that you are quickly busy with OOP
programming as you are using VB.Net.
VB.Net has not any thing in it, to prevent you doing this (beside the
crazy C# type warnings in the version 2005)..
For others, with this I don't say that you should forever not use those
things I wrote to avoid, it is just to learn the concepts of OOP.
Cor
"RSH" <way_beyond_o...@yahoo.comschreef in bericht news:OE**************@TK2MSFTNGP04.phx.gbl... Cor,
>Is there an article or series of articles that you would reccomend to alter my thinking on the subject?
>I will definitely admit I am new to OOP principals and while I have been programming heavily with databases for a number of years it is a very difficult thing to unleash the datacentric tendencies that I have. I suppose the fact that pretty much every tutorial I see relates objects to real world objects (dogs, cats, animals etc.) that I am taking it too literally by implementing objects at face value.
>I would love for you to elaborate a bit more as this sort of conceptual discussions is very enlightening.
>Thanks! Ron
>"Cor Ligthert [MVP]" <notmyfirstn...@planet.nlwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl.. . RSH,
>>Creating classic data classes is only a partial thing of OO, what is not direct OOP.
>>And because of the fact that those classic dataclasses are mostly useless in dotNet, I would take more an eye on using the full OOP implementing classes from AdoNet which are related to SQL implementing databases.
>>Just my thought,
>>Cor "RSH" <way_beyond_o...@yahoo.comschreef in bericht news:eG*************@TK2MSFTNGP04.phx.gbl... 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
Daniel,
Modules can "pollute" the "global" namespace. They allow you to use methods
& properties unqualified making it hard to know where those methods &
properties originate from.
Public Module UtilityModule
Public Function Create() As Something
End Function
End Module
When ever you use "Create" in an expression is not readily apparent where
the method came from...
Dim x As Something = Create()
Generally I use static/shared classes instead of Modules.
Public NotInheritable Class UtilityModule
Private Sub New()
End Sub
Public Shared Function Create() As Something
End Function
End Class
Now its readily apparent that Create is in the UtilityModule.
Dim x As Something = UtilityModule.Create()
There are cases where I prefer Modules over static/shared classes, where the
methods of said type are truly global; for example System.Math. Luckily you
can treat any class as a module by importing that class.
Imports System.Math
x = Sin(y) * Cos(z)
As opposed to:
x = Math.Sin(y) * Math.Cos(z)
Structures are used for defining Value Types where as Classes are used for
defining Reference Types. Each have their respective roles in .NET.
Generally I create reference types unless I know I need a value type. I know
I need a value type when I have a type that meets most or all of the
following criteria:
- Act like primitive types
- Have an instance size under 16 bytes
- Are immutable
- Value semantics are desirable http://msdn.microsoft.com/library/de...Guidelines.asp
--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Daniel" <da**********@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>
Why is it best to avoid Modules and Structures? I just finished a
VB.NET class and those two components seemed to me to be very useful
and commonly used.
Thanks,
Daniel
On Nov 10, 12:07 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
>doh,
Shared classes instead "static" classes.
Cor
"Cor Ligthert [MVP]" <notmyfirstn...@planet.nlschreef in berichtnews:up**************@TK2MSFTNGP04.phx.gbl ...
RSH,
The OOP is based on creating objects from pre defined classes *every
time*
you need to do something.
Those can be your own classes, but in dotNet mostly it are those given
to
you by the framework.
That opposite to the modular model where you create a big program with
in
fact everything all the time predefined in it.
Just start, try to avoid modules, static classes, structures and
declare
things global and you will see that you are quickly busy with OOP
programming as you are using VB.Net.
VB.Net has not any thing in it, to prevent you doing this (beside the
crazy C# type warnings in the version 2005)..
For others, with this I don't say that you should forever not use those
things I wrote to avoid, it is just to learn the concepts of OOP.
Cor
<<snip>>
Jay,
A little addition to your message from my point of view, because I like
currently a *good* written module.
Modules can "pollute" the "global" namespace. They allow you to use
methods & properties unqualified making it hard to know where those
methods & properties originate from.
But that is not necessary, if you write a module as a class, they look very
nice, I prefer since short a good written module above a static/shared
class.
A bad written module has all that as Jay decribes in my opinion.
Cor
>
Public Module UtilityModule
Public Function Create() As Something
End Function
End Module
When ever you use "Create" in an expression is not readily apparent where
the method came from...
Dim x As Something = Create()
Generally I use static/shared classes instead of Modules.
Public NotInheritable Class UtilityModule
Private Sub New()
End Sub
Public Shared Function Create() As Something
End Function
End Class
Now its readily apparent that Create is in the UtilityModule.
Dim x As Something = UtilityModule.Create()
There are cases where I prefer Modules over static/shared classes, where
the methods of said type are truly global; for example System.Math.
Luckily you can treat any class as a module by importing that class.
Imports System.Math
x = Sin(y) * Cos(z)
As opposed to:
x = Math.Sin(y) * Math.Cos(z)
Structures are used for defining Value Types where as Classes are used for
defining Reference Types. Each have their respective roles in .NET.
Generally I create reference types unless I know I need a value type. I
know I need a value type when I have a type that meets most or all of the
following criteria:
- Act like primitive types
- Have an instance size under 16 bytes
- Are immutable
- Value semantics are desirable
http://msdn.microsoft.com/library/de...Guidelines.asp
--
Hope this helps
Jay B. Harlow
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Daniel" <da**********@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>> Why is it best to avoid Modules and Structures? I just finished a VB.NET class and those two components seemed to me to be very useful and commonly used.
Thanks, Daniel
On Nov 10, 12:07 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl> wrote:
>>doh,
Shared classes instead "static" classes.
Cor
"Cor Ligthert [MVP]" <notmyfirstn...@planet.nlschreef in berichtnews:up**************@TK2MSFTNGP04.phx.gb l...
RSH,
The OOP is based on creating objects from pre defined classes *every time* you need to do something. Those can be your own classes, but in dotNet mostly it are those given to you by the framework.
That opposite to the modular model where you create a big program with in fact everything all the time predefined in it.
Just start, try to avoid modules, static classes, structures and declare things global and you will see that you are quickly busy with OOP programming as you are using VB.Net.
VB.Net has not any thing in it, to prevent you doing this (beside the crazy C# type warnings in the version 2005)..
For others, with this I don't say that you should forever not use those things I wrote to avoid, it is just to learn the concepts of OOP.
Cor
<<snip>>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mACKnIFE |
last post by:
Hi list!
I've just finished reading the nice book: "Data Modeling and
Relational Database Design Volume 1 - Student Guide", by Jan
Speelpenning, Patrice Daux and Jeff Gallus, published by Oracle...
|
by: Daniel Ladd |
last post by:
Hi,
I have a problem with a conceptual graph in c++.
I have a oist of structures like this:
typedef struct Conceptual
{ char* Name;//Rappresenta la parola da mettere nel grafo
Conceptual* Next;...
|
by: newsgroupie |
last post by:
Hi Newsgroupies,
I have a friend with 10 years MFC experience and who is now learning C#
and WebForms and who has run up against a conceptual problem.
I, erm I mean he, wants to know how to...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: M_Mann |
last post by:
Hello,
Pls excuse if you consider this off-topic. Conceptual artists seek
programmers here.
We are authors of "Exhibition of Living Managers" (MANAGEX,
www.managex.info) which is is global...
|
by: RSH |
last post by:
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...
|
by: John Salerno |
last post by:
Just something that crosses my mind every time I delve into "Learning
Python" each night. Does anyone see any value in learning Python when you
don't need to for school, work, or any other reason?...
|
by: AliRezaGoogle |
last post by:
Dear Members,
I have a problem in the concepts of Monit.Enter and Monitor.Exit
(Before everything I should say that I know how to solve this problem
by
using Monitor.Wait and I do not need a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |