Microsoft. NET's base class inheritance (2)
From the Visual Studio menu, click Project (project), and then click Add Class (add category).
In the class add the following code:
Property FirstName () As String
Property LastName () As String
Sub Print ()
Sub Talk ()
You will find that you define the attributes and methods of sub-processes and you are the definition of these attributes and processes the same way. The only difference is that you do not have any code to prepare for them. Now take a look at the definition of how to use this type of interface.
In the previous steps to create the class file to add the following code:
Public Class Employee
Private mstrFirstName As String
Private mstrLastName As String
Property FirstName () As String _
mstrFirstName = Value
Property LastName () As String _
mstrLastName = Value
Sub Print () Implements Person.Print
'Add some code here
Sub Talk () Implements Person.Talk
'Add some code here
In the Employee class definition is the first line after Implements Person. This keyword indicates that you have to comply with the definition of Person of the contract interface. Now you can define in the contract all the attributes and methods. Statement in the back of each Property, Implements keyword must be included, and must specify the interface name and you are using the method / property name (both the name of a point between the [.])。 Visual Basic. NET keeps track of each interface, all interface created, you can not compile the application.
If you want to run the code, you need to create a corresponding sub-process, because in the example above, these sub-process is blank. Create all sub-processes, you can create and you usually use, like any other object, the statement and the use of a new Employee object.
Choose to use the type of inheritance is sometimes difficult in the end decided to use interface to achieve the use of inheritance or succession, in many cases, it may be two types of inheritance will be used, but only a small part. For example, you may need to add in the Line type must be covered by the method of quilt-type definition, the definition in the process can be realized using the keyword MustOverride this operation.
Public MustOverride Sub Init ()
Add to this the definition of class, its role is similar to an interface. In sub-class, the Init method must be defined and the method must use the Overrides keyword. The following is a method of how to define Init Example:
Public Overrides Sub Init ()
mstrDelim = ""
mstrLine = "test line"
Similarly, remember to use the Overrides keyword. The keywords used to inform the compiler will cover this method in the superclass Init method.
Note: Microsoft. NET framework to provide online help in the design guidelines that can help you decide to use the type of inheritance.
To prevent the succession, in some cases, you may not want others to inherit your class. If so, you can use the keyword NotInheritable to prevent the kind of succession.
Public Class NotInheritable Employee
Visual Basic 6.0 new features since the use of Visual Basic. NET, you can inherit. NET framework contains all the categories. You can create your own categories, so that these types of inheritance of existing classes; and through a simple code change to add or remove features.
Summary This article describes how to inherit the base class, base class how to add other attributes, as well as how to use the Overrides keyword to replace in the definition of base class functions. Also introduced the use of keywords MyBase call the base class methods, in order to extend the base class function. Although the succession is not the application of all applicable, but if used correctly, the succession will be a very powerful tool.
About the author
Paul D. Sheriff is the PDSA, Inc.'s Owners. The company is located in Southern California, is a custom software development and consulting firm. Paul is the MSDN Southern California Regional Director, there is the "Paul Sheriff Teaches Visual Basic" book, he Keystone Learning systems has produced more than 70 units on the Visual Basic, SQL Server,. NET and Web development of video materials and, more recently, Ken Getz will be co-publishing a book on the SAMS book, "ASP.NET Jumpstart". For more information, please visit the PDSA, Inc.'s Web site www.pdsa.com.
About Informant Communications Group
Informant Communications Group, Inc. Is a focus on the information technology industry's multi-media companies. It was founded in 1990, specializes in software development publications, conferences, catalog publishing and Web site services. ICG in the United States and the United Kingdom with offices, has become renowned for media and marketing content integrator and high-quality technical information to IT staff to meet growing demand.
.Net Object Oriented Programming Articles
- To: design patterns Singleton (the example is C #)
- Words - a prototype model
- Words: one-piece model
- To the practical application of a factory. Can be directly used by heart
- To: "simple" design pattern, then
- I Walaqi, such as with Black_Cat on "design patterns" and "factory method" "abstract factory" organize the discussion as follows, to facilitate "design mode" fans
- Words - the structure of model
- Remarks: With regard to the composition of
- Give you an example [. NET framework for development in the three examples - the user registration system]
- Jia-wen Recommended: VB.NET use object-oriented features
- Microsoft patterns and practices: model papers (Microsoft Patterns & Practices: Patterns) [strongly recommended]
- C # written norms
- Help me, I overloading (C #)
- Microsoft. NET's base class inheritance (1)
- Microsoft. NET's base class inheritance (2)
- The birth of a poker game --- (fullhouse) category on the process of design and debugging, error correction and the use of assertion (I)
- VSS data (Part III)
- VSS information (Part II, picture not uploaded)
- VSS information (and I wrote for the company, part of ICP's)
- In the team development environment using Visual Studio. NET (b)
Can't Find What You're Looking For?
Rating: Not yet rated