[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to define behaviour of Parent Class?

Posted on 2014-08-24
2
Medium Priority
?
125 Views
Last Modified: 2014-08-25
Hi Experts,

Here is an outline of my code:

Public Class clsLicence

    Public Property strProgramNameAndMajorVersion() As String
	
End Class

Public Class clsLicenceSentinel

	Inherits clsLicence
	
    Public Property strProgramNameAndMajorVersion() As String
        Get
		'....
		End Get
        Set(ByVal Value As String)
		'....
        End Set
    End Property
	
End Class

Public Class clsLicenceSoftwareKey

	Inherits clsLicence
	
    Public Property strProgramNameAndMajorVersion() As String
        Get
		'....
		End Get
        Set(ByVal Value As String)
		'....
        End Set
    End Property
	
End Class

Open in new window


So I have 2 Child classes, clsLicenceSentinel and clsLicenceSoftwareKey, with Parent Class, clsLicence.

How do I define Property strProgramNameAndMajorVersion()  so that the appropriate definition in the Child class is used?

Regards,
Leigh
0
Comment
Question by:LeighWardle
2 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 2000 total points
ID: 40282590
In the parent class (its correct term a base class) you declare the property as overridable.

In the inherited classes you can then add the properties with the overrides clause.

Public Class clsLicence

    Public overridable Property strProgramNameAndMajorVersion() As String
	        Get
		'....
		End Get
        Set(ByVal Value As String)
		'....
        End Set

End Class

Public Class clsLicenceSentinel

	Inherits clsLicence
	
    Public overrides Property strProgramNameAndMajorVersion() As String
        Get
		'....
		End Get
        Set(ByVal Value As String)
		'....
        End Set
    End Property
	
End Class

Public Class clsLicenceSoftwareKey

	Inherits clsLicence
	
    Public overrides Property strProgramNameAndMajorVersion() As String
        Get
		'....
		End Get
        Set(ByVal Value As String)
		'....
        End Set
    End Property
	
End Class

Open in new window


Also, if the value doesn't change from the base class to the inherited class then you don't need the code in the inherited class and the value from the base class will be used.
0
 
LVL 1

Author Closing Comment

by:LeighWardle
ID: 40282689
Thanks, ChloesDad.
Just what  I needed.
Cheers, Leigh
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question