|
■No86313 (ユージ さん) に返信 > クラスBの実体はクラスA内の処理でのみ生成できるようにしたいのです。
こういう方法は如何でしょう。
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim a As ClassA = ClassA.Create() Dim b As ClassB = a.Child 'Do Anything End Sub End Class
Public NotInheritable Class ClassA Private Sub New() End Sub Public ReadOnly Property Child As ClassB Public Shared Function Create() As ClassA Dim owner As New ClassA() owner._Child = New ClassB(owner) Return owner End Function End Class
Public Class ClassB Public Sub New(owner As ClassA) If owner Is Nothing Then Throw New ArgumentNullException("owner") End If End Sub End Class
|