以下のコードをご覧ください。
'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 のすべての関数はパブリックです。これはカプセル化の規則に違反していませんか? これを回避する方法はありますか?コードの再利用とカプセル化の間に妥協点があるようです。