VB.NET 繼承 OverLoading

1 篇文章 / 0 new
author
VB.NET 繼承 OverLoading
父類別
Namespace Domain.IT
    'public Modifier修飾詞-可見度
    '編譯產生父類別為System.Object
    Public Class Employee
        '類別層級變數(Data Field)
        Private _id As String
        Private _name As String
        '實現封裝特性(private 私用 -可見度限這一個類別內)
        '改成protected 物件封裝性 子類別不封裝
        Protected _salary As Decimal
        Private _birthDate As DateTime
        Private _sex As String
        ' 編譯產生預設建構子 空參數

 
        '屬性存取(程序)
        Public Property Salary() As Decimal
            Get
                Return _salary
            End Get
            Set(ByVal value As Decimal)
                If (value > 0) Then
                    _salary = value
                End If
            End Set
        End Property
 
        Public Property Id() As String
            Get
                Return Me._id
            End Get
            Set(ByVal value As String)
                Me._id = value
 
            End Set
        End Property
 
        Public Property Name() As String
            Get
                Return Me._name
            End Get
            Set(ByVal value As String)
                Me._name = value
            End Set
        End Property
 
        Public Property BirthDate() As DateTime
            Get
                Return Me._birthDate
            End Get
            Set(ByVal value As DateTime)
                If (value <= System.DateTime.Now) Then
                    Me._birthDate = value
                End If
            End Set
        End Property
 
        Public Property Sex() As String
            Get
                Return Me._sex
            End Get
            Set(ByVal value As String)
                Me._sex = value
            End Set
        End Property
 
 
        '薪資計算的功能Method
        '定結構 非關細部操作
        Public Overloads Function calSalary() As Decimal
            Return Me._salary
        End Function
    End Class
End Namespace
子類別
'指定繼承來源(Parent Class) 非關命名空間
Imports mod06.Domain.IT
Public Class Sales
    Inherits Employee '單一繼承(父親只能一個)
    'Data Field
    '業績
    Private _qa As Decimal
    Private _bon As Decimal '獎金

    '屬性
    ''' <summary>
    ''' 設定或者取得業績
    ''' </summary>
    ''' <value>業績金額</value>
    ''' <returns>業績金額</returns>
    ''' <remarks></remarks>
    Public Property Qa() As Decimal
        Get
            Return Me._qa
        End Get
        Set(ByVal value As Decimal)
            If (value > 0) Then
                Me._qa = value
            End If
        End Set
    End Property
    '唯讀屬性
    Public ReadOnly Property Bon() As Decimal
        Get
            Return Me._bon
        End Get
    End Property
    'Method商業規則Business Rules 獎金計算部分
    Public Sub calBon(ByVal act As Decimal)
        If (act >= Me._qa) Then
            Me._bon = act * 0.05
        End If
    End Sub
    '同時計算獎金與薪資
    Public Overloads Sub calSalary(ByVal act As Decimal)
        If (act >= Me._qa) Then
            Me._bon = act * 0.05
            '底薪_salary加回獎金
            _salary += Me._bon
        End If
 
    End Sub
End Class

from
http://www.dotblogs.com.tw/timothy/archive/
關鍵字: 
Free Web Hosting