Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Interfaces to Add Semantic Meaning

5.00/5 (1 vote)
5 Dec 2019CPOL 1.7K  
Interfaces to add semantic meaning

Much data are organized in a hierarchical manner - for example, as Region.Country.Office or Fund.ShareClass.Account. Each level of these requires a foreign key up to its parent level and this is usually a primitive data type (string, GUID or integer for example) with a meaningful name.

A good habit to get into is the creation of interfaces for these hierarchical layers to tag the properties involved in the hierarchy. For example, if we are using integers for our hierarchy navigation, then the fund->shareclass->account we could create interfaces like:

VB.NET
<summary>
    ''' A fund - top level DTO
    ''' </summary>
    Public Interface IFundRecord
         ''' <summary>
        ''' The unique identifier of the fund
        ''' </summary>
        ReadOnly Property FundIdentifier As Integer
    End Interface

Then share class inherits from this:

VB.NET
''' <summary>
''' A share class
''' </summary>
Public Interface IShareClassRecord
    Inherits IFundRecord
    ''' <summary>
    ''' The unique identifier of the task
    ''' </summary>
    ReadOnly Property ShareClassIdentifier As Integer
End Interface

And because .NET allows multiple interface inheritance, we could make an account link to both a share class and an investor:

VB.NET
''' <summary>
''' An investor account in a share class
''' </summary>
Public Interface IAccountRecord
    Inherits IShareClassRecord, IInvestorRecord
    ''' <summary>
    ''' The unique identifier of the account
    ''' </summary>
    ReadOnly Property AccountIdentifier As Integer
End Interface

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)