我正在尝试遵循这篇文章的回答者的建议:DataAccess 项目中类的命名约定是什么?(jdk)。
请看下面的代码:
'Form1.vb
Imports WindowsApplication1.BusinessLogicLayerShared
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim IPerson As IPerson
IPerson = New BusinessLogicLayer.Person()
Dim name As String = IPerson.getName()
End Sub
End Class
'Person.vb
Imports WindowsApplication1.BusinessLogicLayerShared
Namespace BusinessLogicLayer
Public Class Person
Implements IPerson
Private IPerson As DataLogicLayerShared.IPerson
Public Function getName() As String Implements IPerson.getName
IPerson = New DataLogicLayer.Person
getName = IPerson.getName
End Function
End Class
End Namespace
Namespace BusinessLogicLayerShared
Public Interface IPerson
Function getName() As String
End Interface
End Namespace
'Person.vb
Imports WindowsApplication1.DataLogicLayerShared
Namespace DataLogicLayer
Public Class Person
Implements IPerson
Public Function getName() As String Implements IPerson.getName
'Connect to database and get name
Return "Ian"
End Function
Public Function getAge() Implements IPerson.getAge
End Function
End Class
End Namespace
Namespace DataLogicLayerShared
Public Interface IPerson
Function getName() As String
Function getAge()
End Interface
End Namespace
客户端(表单)调用业务逻辑层,业务逻辑层调用数据逻辑层。名称(字符串)从数据逻辑层传递到业务逻辑层并返回给客户端。
我不喜欢在引用接口时必须指定名称空间,例如 Private IPerson As DataLogicLayerShared.IPerson。我应该在参考中指定命名空间还是可以修改我采用的模式以避免这种情况?