学习OOP概念问题 [英] Learning OOP conceptual question

查看:66
本文介绍了学习OOP概念问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在尝试掌握现实世界物体的使用以及如何使用商业场景来概念化它们。


我以下是一个大纲,我正试图想出一个类结构:\


顶级对象:

公司

员工


在公司我有:

公司减记

CompanyAccruals

CompanyTaxes


在员工的帮助下我有:

员工扣除

员工薪酬

员工薪资

现在我的问题是我应该如何根据这些信息设置我的课程

以上?

我原本以为公司是基类并且

公司扣除,应计和税收继承了公司类别,但我不是

确定是要走的路。我的另一个想法就是将

扣除应计和税收信息作为

公司下的可选属性,以便属于公司的员工可以继承

公司级。


您如何建议我设置我的班级结构?


公司将成为一个集合公司对象

公司扣除,CompanyAccruals和CompanyTaxes包含元数据

适用于分配这些物品的所有员工


有相似之处,但它们不同,足以保证我相信单独的物品。它们将包含不同的计算方法

和不同的属性,在不久之后下降到表面之下。


据说雇员确实有employeeDeductions其中

将与CompanyDeductions相关联。员工扣减将有b / b
率,百分比,税前等。


我在下面起草了一个快速模型......


从对象中引用其他对象是不好的做法吗?

非常感谢你的帮助!

Ron


模块模块1


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" ;,公司制服)


Company2.AddAccrual(Sick,Sick)


Company2.AddAccrual( 假期,假期)


Company1.Print(" Deductions")


Company2.Print(" Accruals")

Console.ReadLine()


Company1.SetDeductionRate(" 401k",23.45)< br $>

Company1.Print(" Deductions")

End Sub


结束模块


公共类公司


私有_CompanyID为字符串


私有_CompanyName为字符串


私有_FEIN为字符串


私有_CompanyDeductions为新Hashtable


私有_CompanyAccruals为新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


获取


返回_CompanyID


结束获取


设置(ByVal值为Str ing)


_CompanyID = value


结束集


结束财产


Public Property CompanyName()As String


获取


返回_CompanyName


结束获取


设置(ByVal值为字符串)


_CompanyName = value


结束集


结束物业


公共财产FEIN()为字符串


获取


返回_FEIN


结束获取


设置(ByVal值为字符串)


_FEIN =价值


结束套装


结束物业


公用Sub AddDeduction(BYVAL DeductionID作为字符串,BYVAL DeductionName作为

字符串)


尺寸光盘作为CompanyDeduction =新CompanyDeduction(DeductionID,

扣除名称)


_CompanyDeductions.Add(DeductionID,cd)

结束子


Public Sub AddAccrual(ByVal Ac crualID As String,ByVal AccrualName As

String)


Dim ca As CompanyAccrual = New CompanyAccrual(AccrualID,AccrualName)


_CompanyAccruals.Add(AccrualID,CA)


结束子


公用Sub SetDeductionRate(BYVAL DeductionID作为字符串,BYVAL率

双倍)


Dim cd作为CompanyDeduction


cd = _CompanyDeductions(DeductionID)

>
cd.Rate =价格


结束子


公共子打印(ByVal类型为字符串)


Console.WriteLine(vbCrLf)


Dim al As New Hashtable


Dim i As Integer


Console.WriteLine(" CompanyId:" &安培; _CompanyID& "公司名称:" &

_公司名称)


选择案例类型


案例扣除


al = _CompanyDeductions


案例应计


al = _CompanyAccruals


结束选择


如果al.Count 0那么


Console.WriteLine(类型&" ID"& vbTab& ;键入&" Name"& vbTab&""")

Console.WriteLine(" -------------- -------------------------")


Dim myEnumerator作为IDictionaryEnumerator = al.GetEnumerator()


myEnumerator.MoveNext()


Console.WriteLine(" {0}:{1}",myEnumerator.Value( 0))


结束时


否则


Console.WriteLine(" No" ;&"&存在于这家公司)


结束如果


结束子


结束班


NotInheritable Class CompanyDeduction


私有_ID为字符串


私有_Name字符串


私有_Rate As Double


Public Sub New(ByVal ID As String,ByVal Name as String)


_ID = ID


_Name =姓名


结束子


公共财产ID()为字符串


获取


返回_ID


结束获取


Set(ByVal价值为字符串)


_ID =价值


结束集


结束物业

公共财产名称()为字符串


获取


返回_Name


结束获取


设置(ByVal值为字符串)


_Name = value


结束套装


结束物业


公共物业费率()双倍


获取


返回_Rate


结束获取


Set( ByVal值为双倍)


_Rate = value


结束集


结束财产


结束班级


NotInheritable Class CompanyAccrual


私人_ID字符串

Private _Name As String


Private _Rate As Double


Public Sub New(ByVal ID As String,ByVal Name as String )


_ID = ID


_Name =姓名


结束子


公共财产ID()为字符串


获取


返回_ID


结束获取


设置(ByVal值为字符串)


_ID = value


结束集


结束财产


公共财产名称()为字符串


获取


返回_Name


结束获取


设置(ByVal值为字符串)


_Name = value


结束集


结束物业

公共房产价格()双人房


获取


返回_Rate
< br $>
结束获取


套装(ByVal值为双倍)


_Rate = value

结束套件


结束物业


结束班级

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

推荐答案

我不确定我理解商业惯例。你在做什么

会计/财务?


我想到了两种方法。第一种是使用一个界面来实现所需的功能,并让界面显示扣减,

Accurals和Taxes。


或者,您还可以获得扣除课程,准确课程和

课程,然后:

Class Company

公共扣除作为新扣减

公共准确为新的准确性

公共税作为新税

结束类
为员工重复。


假设Deductions是一个带有.Add方法的集合类,那么



Dim c as New Company

c.Deductions.Add(New Deduction(" 401K"," 401K Program")


Chris

RSH写道:
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:

我仍​​然试图掌握现实世界对象的使用以及如何将
概念化它们使用商业场景。


我在下面的内容是我正在努力尝试的大纲图

一个班级结构:\


顶级对象:

公司

员工


在公司我有:

公司减记

公司承诺

CompanyTaxes


在员工下我有:

员工扣除

员工薪资

员工税额


现在我的问题是我应该如何基于这些信息来设置我的课程

以上?

我最初想的是让公司成为基础类并拥有

CompanyDeductions,Accruals和Taxes继承了公司类,但我不是

确定是要走的路。我的另一个想法就是将

扣除应计和税收信息作为

公司下的可选属性,以便属于公司的员工可以继承

公司级。


您如何建议我设置我的班级结构?


公司将成为一个集合公司对象

公司扣除,CompanyAccruals和CompanyTaxes包含元数据

适用于分配这些物品的所有员工


有相似之处,但它们不同,足以保证我相信单独的物品。它们将包含不同的计算方法

和不同的属性,在不久之后下降到表面之下。


据说雇员确实有employeeDeductions其中

将与CompanyDeductions相关联。员工扣减将有b / b
率,百分比,税前等。


我在下面起草了一个快速模型......


从对象中引用其他对象是不好的做法吗?

非常感谢你的帮助!

Ron


模块模块1


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(QUOT; 401K","公司的401K方案")


Company1.AddDeduction(QUOT;统一" ;,公司制服)


Company2.AddAccrual(Sick,Sick)


Company2.AddAccrual( 假期,假期)


Company1.Print(" Deductions")

Company2.Pr int(Accruals)


Console.ReadLine()


Company1.SetDeductionRate(" 401k",23.45)


Company1.Print(" Deductions")

End Sub


结束模块


公共类公司


私有_CompanyID为字符串


私有_CompanyName为字符串


私有_FEIN为字符串


私有_CompanyDeductions为新Hashtable


私有_CompanyAccruals为新Hashtable

Public Sub New(ByVal CompanyID As String,ByVal CompanyName As String,ByVal

FEIN As String)


_CompanyID = CompanyID


_公司名称=公司名


_FEIN = FEIN


结束子


Public Property CompanyID()As String


获取


返回_CompanyID


结束获取


设置(ByVal值为字符串)


_CompanyID =值


结束集


结束财产


公共财产CompanyName()As String


获取


返回_公司名称


结束获取


设置(ByVal值为字符串)


_CompanyName = value


结束集


结束财产


公共财产FEIN()为字符串


获取


返回_FEIN


结束获取


设置(ByVal值为字符串)


_FEIN = value


结束集


结束财产


Public Sub AddDeduction(ByVal DeductionID As String,ByVal DeductionName As

String)


Dim cd As CompanyDeduction = New CompanyDeduction(DeductionID,

DeductionName)


_CompanyDeductions.Add(DeductionID,CD)


结束子


公用Sub AddAccrual(BYVAL AccrualID作为字符串,BYVAL AccrualName作为<无线电通信/>
Strin g)


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作为CompanyDeduction


cd = _CompanyDeductions(DeductionID)


cd.Rate = Rate
< br $>
End Sub


公共子打印(ByVal类型为字符串)


Console.WriteLine(vbCrLf)


Dim al As New Hashtable


Dim i As Integer


Console.WriteLine(" CompanyId :" &安培; _CompanyID& "公司名称:" &

_公司名称)


选择案例类型


案例扣除


al = _CompanyDeductions


案例应计


al = _CompanyAccruals


结束选择


如果al.Count 0那么


Console.WriteLine(类型&" ID"& vbTab& ;键入&" Name"& vbTab&""")

Console.WriteLine(" -------------- -------------------------")


Dim myEnumerator作为IDictionaryEnumerator = al.GetEnumerator()


myEnumerator.MoveNext()


Console.WriteLine(" {0}:{1}",myEnumerator.Value( 0))


结束时


否则


Console.WriteLine(" No" ;&"&存在于这家公司)


结束如果


结束子


结束班


NotInheritabl e Class CompanyDeduction


私有_ID为字符串


私有_Name字符串


私有_Rate As Double


Public Sub New(ByVal ID As String,ByVal Name as String)


_ID = ID


_Name =姓名


结束子


公共财产ID()为字符串


获取


返回_ID


结束获取


设置(ByVal值为字符串)


_ID =价值


结束套件


结束物业

公共财产名称()为字符串


获取


返回_Name


结束获取


设置(ByVal值为字符串)


_Name = value


结束设置


结束物业


公共物业费率()双倍


获取


返回_Rate


结束获取


设定(ByVal值为双倍)


_Rate =价值


结束集


结束财产


结束班



NotInheritable Class CompanyAccrual


私有_ID为字符串


私有_Name为字符串


私有_Rate As Double


Public Sub New(ByVal ID As String,ByVal Name as String)


_ID = ID


_Name =姓名


结束子


公共财产ID()为字符串


获取


返回_ID


结束获取


套装(ByVal值为字符串)


_ID =价值


套装


结束财产


公共财产名称()为字符串


获取


返回_Name


结束获取


设置(ByVal值为字符串)


_Name = value


结束套票


结束物业


公共物业费率()双倍


G et b / b
返回_Rate


结束获取


设置(ByVal值为Double)


_Rate = value


结束套件


结束物业


结束类
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,


创建经典数据类只是OO的一部分,什么不是

直接OOP。


由于这些经典数据类在

dotNet中大多无用,我我会更多地关注使用完整的OOP实现类来自AdoNet的与b实现数据库相关的



只是我的想法,


Cor

" RSH" < wa ************* @ yahoo.comschreef在bericht

新闻:eG ************* @ 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...

>我仍在尝试掌握现实世界物体的使用以及如何使用a b $ b概念化它们商业场景。


我在下面的内容是一个大纲,我正试图想出一个类结构:\
< br $>
顶级对象:

公司

员工


在公司我有:

公司减免

公司资深

公司税收


在员工的帮助下我有:

员工减免

EmployeeAccruals

EmployeeTaxes


现在我的问题是如何基于该信息设置我的课程

以上?

我最初考虑过将公司作为基础类并且具有

公司扣除,应计和税收继承公司类别,但我是

不是

确定这是最佳选择。我的另一个想法就是将

扣除应计和税收信息作为

公司下的可选属性,以便属于公司的员工可以继承

公司级。


您如何建议我设置我的班级结构?


公司将成为一个集合公司对象

公司扣减,CompanyAccruals和CompanyTaxes包含元数据



适用于所有分配这些项目的员工


有相似之处,但它们不同,足以保证单独使用我相信的
物品。它们将包含不同的计算方法

和不同的属性,在不久之后下降到表面之下。


据说雇员确实有employeeDeductions其中

将与CompanyDeductions相关联。员工扣减将有b / b
率,百分比,税前等。


我在下面起草了一个快速模型......


从对象中引用其他对象是不好的做法吗?

非常感谢你的帮助!

Ron


模块模块1


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(QUOT;统一","公司制服")


Company2.AddAccrual(QUOT;病态","病态")


Company2.AddAccrual(" Vacation"," Vacation")


Company1.Print(" Deductions")


Company2.Print(" Accruals")

Console.ReadLine()


Company1.SetDeductionRate(" 401k",23.45)< br $>

Company1.Print(" Deductions")

End Sub


结束模块


公共类公司


私有_CompanyID为字符串


私有_CompanyName为字符串


私有_FEIN为字符串


私有_CompanyDeductions为新Hashtable


私有_CompanyAccruals为新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


获取


返回_CompanyID


结束获取


设置(ByVal值为字符串)


_CompanyID = value


结束集


结束财产


公共财产CompanyName()As String


获取


返回_公司名称


结束获取


设置(ByVal值为字符串)


_CompanyName = value


结束集


结束财产


公共财产FEIN()为字符串


获取


返回_FEIN


结束获取


设定(ByVal值为字符串)


_FEIN = value


结束集


结束财产


Public Sub AddDeduction(ByVal DeductionID As String,ByVal DeductionName

As String)


Dim cd As CompanyDeduction = New CompanyDeduction(DeductionID,

DeductionName)


_CompanyDeductions.Add(DeductionID,CD)


结束子


公用Sub AddAccrual(BYVAL AccrualID作为字符串,BYVAL AccrualName作为

String)


Dim ca As CompanyAccrual = New CompanyAccrual(AccrualID,AccrualName)


_CompanyAccruals.Add(AccrualID,ca)


结束子


Public Sub SetDeductionRate(ByVal DeductionID As String,ByVal Rate As

Double)


Dim cd作为CompanyDeduction


cd = _CompanyDeductions(DeductionID)


cd.Rate = Rate


结束子


公共子打印(ByVal类型为字符串)


Console.WriteLine( vbCrLf)


Dim al As New Hashtable


Dim i As Integer


Console.WriteLine (QUOT; CompanyId:" &安培; _CompanyID& "公司名称:" &

_公司名称)


选择案例类型


案例扣除


al = _CompanyDeductions


案例应计


al = _CompanyAccruals


结束选择


如果al.Count 0那么


Console.WriteLine(类型&" ID"& vbTab& ;键入&" Name"& vbTab&""")

Console.WriteLine(" -------------- -------------------------")


Dim myEnumerator作为IDictionaryEnumerator = al.GetEnumerator()


myEnumerator.MoveNext()


Console.WriteLine(" {0}:{1}",myEnumerator.Value( 0))


结束时


否则


Console.WriteLine(" No" ;&"&存在于这家公司)


结束如果


结束子


结束班


NotInheritabl e Class CompanyDeduction


私有_ID为字符串


私有_Name字符串


私有_Rate As Double


Public Sub New(ByVal ID As String,ByVal Name as String)


_ID = ID


_Name =姓名


结束子


公共财产ID()为字符串


获取


返回_ID


结束获取


设置(ByVal值为字符串)


_ID =价值


结束套件


结束物业

公共财产名称()为字符串


获取


返回_Name


结束获取


设置(ByVal值为字符串)


_Name = value


结束设置


结束物业


公共物业费率()双倍


获取


返回_Rate


结束获取


设定(ByVal值为双倍)


_Rate =价值


结束集


结束财产


结束班



NotInheritable Class CompanyAccrual


私有_ID为字符串


私有_Name为字符串


私有_Rate As Double


Public Sub New(ByVal ID As String,ByVal Name as String)


_ID = ID


_Name =姓名


结束子


公共财产ID()为字符串


获取


返回_ID


结束获取


套装(ByVal值为字符串)


_ID =价值


套装


结束财产


公共财产名称()为字符串


获取


返回_Name


结束获取


设置(ByVal值为字符串)


_Name = value


结束套票


结束物业


公共物业费率()双倍


G et b / b
返回_Rate


结束获取


设置(ByVal值为Double)


_Rate = value


结束套件


结束物业


结束班

>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






我正在努力使用接口。我对你把

拿出来的那个选项很感兴趣。你有可能做一个快速的代码示例,说明我可能会如何设置它吗?


我的业务实践是这个exersize的工资单...但是我或多或少只是试图学习适用于我自己的班级结构的OOP校长。


感谢您的见解!

ron

< ch ************ @ gmail.comwrote in message

news:11 ***** *****************@m73g2000cwd.googlegr oups.com ...

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...

我我不确定我理解商业惯例。你在做什么

会计/财务?


我想到了两种方法。第一种是使用一个界面来实现所需的功能,并让界面显示扣减,

Accurals和Taxes。


或者,您还可以拥有扣除课程,准确课程,以及

课程,然后:


班级公司

公共扣除作为新扣减

公共准确作为新的准确人

公共税作为新税

结束班级


为员工重复。


假设Deductions是一个带.Add方法的集合类,那么




Dim c as New Company

c.Deductions.Add(New Deduction(" 401K"," 401K Program")


克里斯


RSH写道:
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:

>我仍在努力掌握使用现实世界的对象以及如何使用业务场景概念化它们。

我在下面的内容是一个outli我正在努力想要找出一个班级结构:\

顶级对象:
公司
员工

在公司下我有:
公司扣除
公司人员
公司税务

在员工下我有:
员工减员
员工薪酬
员工税务

现在我的问题是我应该如何基于上面的
信息来设置我的课程?
我原本想过让公司成为基础课程并拥有
公司扣除,应计和税收继承了公司类别,但我不确定是否可行。我的另一个想法就是将
扣减应计和税务信息作为
公司下的可选属性,以便属于公司的员工可以继承
公司类。

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.SetDeduct ionRate("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)

_C ompanyName = 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

E nd 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 _Ra te 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 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



这篇关于学习OOP概念问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆