Click here to Skip to main content
13,354,132 members (57,856 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 22 Jun 2014

Interfaces to add semantic meaning

, 22 Jun 2014
Rate this:
Please Sign up or sign in to vote.
Using interfaces to add sematic meaning to your POCO classes


Much data are organised 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:-


    ''' 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:-

    ''' <summary>
    ''' A share class
    ''' </summary>
    Public Interface IShareClassRecord
        Inherits IFundRecord

        ''' <summary>
        ''' The unique identifier of the share class
        ''' </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:-

    ''' <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


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


About the Author

Duncan Edwards Jones
Software Developer (Senior)
Ireland Ireland
C# / SQL Server developer
Microsoft MVP (Azure) 2017
Microsoft MVP (Visual Basic) 2006, 2007

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 22 Jun 2014
Article Copyright 2014 by Duncan Edwards Jones
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid