Tech Off Post

Single Post Permalink

View Thread: Class Design
  • User profile image
    Sven Groot

    You should, whenever at all possible, not use Friend fields. The point of OO design is that all code dealing with the data should be in the class that contains the data. Try something like this:

    Alarm.vb:

    Public Class Alarm
    Private mAlarmMessage As String

    Public Sub New(ByVal alarmMessage As String)
    mAlarmMessage = alarmMessage
    End Sub

    Public ReadOnly Property AlarmMessage() As String
    Get
    Return mAlarmMessage
    End Get
    End Property
    End Class


    FMA3.vb
    Public Class FMA3
    Private mAlarm As Alarm

    Public Sub New()
    mAlarm = New Alarm("This is the alarm message")
    End Sub

    Public ReadOnly Property Alarm() As Alarm
    Get
    Return mAlarm
    End Get
    End Property
    End Class