VB.NET 4에서 종속 형식을 사용할 수 있는지 또는 기본 클래스의 생성자 매개 변수를 기반으로 상속 된 개체를 구성 할 수 있는지 궁금합니다. 예를 들어,VB.NET의 종속 형식
Class BaseClass
Sub New(type as String)
If type = "One" then
Me = New Child1 'Assignment to Me is syntax error, but it explains the concept...
Else
Me = New OtherChild
End If
End Sub
End Class
Class Child1
Inherits BaseClass
...
Class OtherChild
Inherits BaseClass
..
..
Sub Main()
Dim c1 As New BaseClass("One")
Dim c2 As New BaseClass("Two")
OverloadedMethod(c1) 'Outputs One
OverloadedMethod(c2) 'Outputs Two
End Sub
Sub OverloadedMethod(C as Class1)
Console.Write("One")
End Sub
Sub OverloadedMethod(C as OtherClass)
Console.Write("Two")
End Sub
EDIT : 종속 유형에 대한 설명, (. 예컨대 스칼라 값)
Dependent types 어떤 파라미터에 기초하여 구성되는 유형이다. 이것은 일부 (주로 기능적) 프로그래밍 언어 (예 : 하스켈)에서 잘 알려진 개념입니다. 예를 들어, 의존적 유형을 지원 가상의 필수 언어로, 하나는 쓸 수 있습니다 :
Matrix(3,10) A; //A is a 10x10x10 3D Matrix
Matrix(2,3) B; //B is a 3x3 2D Matrix
그리고
A(0,0,0) = 10;
B(0,0) = -2;
B(1,1,0) = 5; // Type Error