Help: Class, Inheritance

Cavar

Well-known member
Joined
Sep 5, 2006
Messages
60
Programming Experience
5-10
Hi,

I've been programming in VB6 so long that I have no idea how I would go about creating a class (OOP?) that would give me the following intellisense format when using my class.

VB.NET:
Customer.Name.First
Customer.Name.MI
Customer.Name.Last
Customer.Name.Prefix
Customer.Name.Suffix
 
Customer.Address.Line1.StreetNo
Customer.Address.Line1.StreetName
Customer.Address.Line1.UnitNo
Customer.Address.Line2.StreetNo
Customer.Address.Line2.StreetName
Customer.Address.Line2.UnitNo
Customer.Address.City
Customer.Address.State
Customer.Address.Zip
Customer.Address.Zip4
 
Customer.Phone.Cell
Customer.Phone.Fax
Customer.Phone.Home
Customer.Phone.Pager
Customer.Phone.Work.Number
Customer.Phone.Work.Extension

I would like to create a class so that when I when I type Customer, which is my object, and press the period (.) key I will have intellisense options for .Address, .Name and .Phone.. Then if I pressed .Name I would get the intellisense for .First, .MI, etc.

I'm not sure of the best way to proceed, but if you can point me in the general direction, such as keywords I should use in a search and/or tutorial links, I will be more than happy to do the leg work.

I would just like to understand the basics of how to accomplish this, so that I can modify it for other needs, such as having a class to read MP3 tags.

string title = myMP3.IDv1.Title or
string title = myMP3.IDv2.Title or
string title = myMP3.Title, which would return return IDv2 if it was set, otherwise IDv1 or blank if neither were set.

If I am just overcomplicating things, please let me know.

Thanks in advance.

CT
 
There is no inheritance sketched out here, only a structured layout of classes and fields/properties. This can be designed by both a number of Classes or a number of Structures. Each level you write here is a class/structure and the type of the child field/property. Each class/structure may be defined nested or flat. Here is an example (flat), I just enter some fields instead of a full property (with Get/Set and private field to hold the value/reference):
VB.NET:
Class customer
    Public name As New customername
    Public address As New customeraddress
    Public phone As New customerphone
End Class
 
Class customername
    Public first, middle, last As String
End Class
 
Class customeraddress
End Class
 
Class customerphone
End Class
Usage example:
VB.NET:
Dim c1 As New customer
c1.name.first = "firstname"
 
I wasn't sure about the using Inheritance, but I thought I would put it in the title in case I could use it.

I was thinking that maybe I could have done something like:

VB.NET:
Public Class EntityName
 Dim _First As String
 Public Property First() As String
  Get
   Return _First
  End Get
  Set
   _First = Value
  End Set
 End Property
End Class
 
Public Class Entity
 Inherits EntityName
End Class

But, I wasn't sure how this would translate to the Customer.Name.First format.

Anyway, thanks for the input it's given food for thought.

CT
 
If you had a base-customer type and one or more sub-customer types each with the base-properties plus their own special sub-type properties you would have an inheritance situation. Here is only one customer with several properties, where several of the properties is grouped as their own class/structure type.
 
Back
Top