请看下面的代码:
'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
DataLogicLayer.Person 中的所有函数都是公共的。这不违反封装规则吗?有没有解决的办法?代码重用和封装之间似乎存在折衷。