locked
Implements ICalculate RRS feed

  • Question

  • User1080785583 posted

    I am creating an interface that auto generates my get,set routines for a certain interface. The problem is when it is auto generated it is missing the Get code, which is easily fixed by typing it in. Just wondering what I need to do to fix the auto-generate feature of Implements ICalculate.

     

    --ICalculate

    Imports Microsoft.VisualBasic
    
    Namespace ContractCalcuation
        Public Interface ICalculate
            Property MaterialsEstimate(ByVal myFace As Integer) As String
            Property SubContractsEstimate() As String
            Property LaborEstimate() As String
            Property ProfitEstimate() As String
            Property MaterialsActual() As String
            Property SubContractActual() As String
            Property LaborActual() As String
            Property ProfitActual() As String
        End Interface
    
    End Namespace

    --test Implements ICalculate

    Imports Microsoft.VisualBasic
    
    Namespace ContractCalcuation
        Public Class Test
            Implements ICalculate
    
    
            Public Property LaborActual() As String Implements ICalculate.LaborActual
                Get
    
                End Get
                Set(ByVal value As String)
    
                End Set
            End Property
    
            Public Property LaborEstimate() As String Implements ICalculate.LaborEstimate
                Get
    
                End Get
                Set(ByVal value As String)
    
                End Set
            End Property
    
            Public Property MaterialsActual() As String Implements ICalculate.MaterialsActual
                Get
    
                End Get
                Set(ByVal value As String)
    
                End Set
            End Property
    
            Public Property MaterialsEstimate(ByVal myFace As Integer) As String Implements ICalculate.MaterialsEstimate
                Get
    
                End Get
                Set(ByVal value As String)
    
                End Set
            End Property
    
            Public Property ProfitActual() As String Implements ICalculate.ProfitActual
                Get
    
                End Get
                Set(ByVal value As String)
    
                End Set
            End Property
    
            Public Property ProfitEstimate() As String Implements ICalculate.ProfitEstimate
                Get
    
                End Get
                Set(ByVal value As String)
    
                End Set
            End Property
    
            Public Property SubContractActual() As String Implements ICalculate.SubContractActual
                Get
    
                End Get
                Set(ByVal value As String)
    
                End Set
            End Property
    
            Public Property SubContractsEstimate() As String Implements ICalculate.SubContractsEstimate
                Get
    
                End Get
                Set(ByVal value As String)
    
                End Set
            End Property
        End Class
    End Namespace
    
    


     


     

    Tuesday, May 25, 2010 9:33 AM

Answers

  • User-952121411 posted

    So if my application has multiple types of Update, Insert, Delete procedures,
     

    While you could do this, it would not make too much sense to isolate those methods into their own interfaces.  Those CRUD type methods are usually a part of a larger class (i.e. Customer, Orders, Products, etc.) that all contain their own '.Get', '.Save', '.Delete', etc methods.  Each of those classes might have an Interface designed for them, but I typically do not design one specifically for those operations.  Also remember that the Interface also declares the method parameters.  A .Save method for one Interface might take a type of ICustomer, and another takes a type of IOrders, so it would be difficult to create a Single Interface for a Insert or Update unless all classes shred the same Interface.

    You also don't have to design your interfaces to expose/use all of the OOP attributes available.  What I mean is, go ahead and design the Interfaces for your classes and begin to learn how they work.  If you don't design them perfectly the 1st time, and figure out how to make objects polymorphic, etc. no need to worry.  At this point just become familiar on how they work.  As a side note, if you ever build a WCF service you will learn about Interfaces really quickly.  This is because they all require defining the Interface for the methods exposed by the service.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 27, 2010 9:16 AM

All replies

  • User-952121411 posted

    I am a bit confused on this one.  I tested your interface code 'ICalculate' and one of my own interfaces separately, and in both instance when I typed in under my class delcaration Implements ICalculate and then press 'Enter' all of the property signatures are created including both the Get and Set.  Now obviously the backing properties are not defined (i.e. Private mLaborActual As String = String.Empty) and then Setting and Returning that variable within the property, but implementing an Interface never provides the implementation code; just the method or property signature.  I used VS.NET 2008 for my tests. 

    Wednesday, May 26, 2010 11:19 AM
  • User1080785583 posted

    Is there a way to do this, by creating the backing contract with the interface? I am really trying to implement oop and hope i am doing it right. Here is what I have, different interface though. Am i doing this correctly or should I do it an easier way? Thanks in advance!

     --IClaimsBondsLiens--

    Imports Microsoft.VisualBasic
    
    Namespace ClaimsBondsLiens
        Public Interface IClaimsBondsLiens
            Property ContractNumber() As String
            Property SiteID() As String
            Property DivisionNumber() As String
            Property ClaimantAddress() As String
            Property ClaimantCity() As String
            Property ClaimantEmail() As String
            Property ClaimantName() As String
            Property ClaimantPhone() As String
            Property ClaimantState() As String
            Property ClaimantZip() As String
            Property ClaimantContact() As String
            Property DateOfClaim() As String
            Property LocationOfLoss() As String
            Property LossDescription() As String
            Property ChangeOrderIssued() As String
            Property MatterLitigated() As String
            Property MatterDisputed() As String
            Property Comments() As String
            Property SuretyAddress() As String
            Property SuretyCity() As String
            Property SuretyContact() As String
            Property SuretyEmail() As String
            Property SuretyName() As String
            Property SuretyPhone() As String
            Property SuretyState() As String
            Property SuretyZip() As String
            Property BondNumber() As String
            Property RiskManagementNumber() As String
            Property Defendants() As String
            Property ThirdPartyRefNumber() As String
    
        End Interface
    
    End Namespace
    


    --ClaimsBondsLiensBLL? --

    Imports Microsoft.VisualBasic
    Namespace ClaimsBondsLiens
        Public MustInherit Class ClaimsBondsLiens
            Implements IClaimsBondsLiens
    
            Public _contractNumber As String = String.Empty
            Public _siteID As String = String.Empty
            Public _divisionNumber As String = String.Empty
            Public _claimantAddress As String = String.Empty
            Public _claimantCity As String = String.Empty
            Public _claimantEmail As String = String.Empty
            Public _claimantName As String = String.Empty
            Public _claimantPhone As String = String.Empty
            Public _claimantState As String = String.Empty
            Public _claimantZip As String = String.Empty
            Public _claimantContact As String = String.Empty
            Public _dateOfClaim As String = String.Empty
            Public _locationOfLoss As String = String.Empty
            Public _lossDescription As String = String.Empty
            Public _changeOrderIssued As String = String.Empty
            Public _matterLitigated As String = String.Empty
            Public _matterDisputed As String = String.Empty
            Public _comments As String = String.Empty
            Public _suretyAddress As String = String.Empty
            Public _suretyCity As String = String.Empty
            Public _suretyContact As String = String.Empty
            Public _suretyEmail As String = String.Empty
            Public _suretyName As String = String.Empty
            Public _suretyPhone As String = String.Empty
            Public _suretyState As String = String.Empty
            Public _suretyZip As String = String.Empty
            Public _bondNumber As String = String.Empty
            Public _riskManagementNumber As String = String.Empty
            Public _defendants As String = String.Empty
            Public _thirdPartyRefNumber As String = String.Empty
    
            'Public Sub ClaimBondLien(ByVal contractNumber As String, ByVal siteID As String, ByVal divisionNumber As String, _
            '                                     ByVal claimantAddress As String, ByVal claimantCity As String, ByVal claimantEmail As String, _
            '                                     ByVal claimantName As String, ByVal claimantPhone As String, ByVal claimantState As String, _
            '                                     ByVal claimantZip As String, ByVal claimantContact As String, ByVal dateOfClaim As String, _
            '                                     ByVal locationOfLoss As String, ByVal lossDescription As String, ByVal changeOrderIssued As String, _
            '                                     ByVal matterLitigated As String, ByVal matterDisputed As String, ByVal comments As String, _
            '                                     ByVal suretyAddress As String, ByVal suretyCity As String, ByVal suretyContact As String, _
            '                                     ByVal suretyEmail As String, ByVal suretyName As String, ByVal suretyPhone As String, _
            '                                     ByVal suretyState As String, ByVal suretyZip As String, ByVal bondNumber As String, _
            '                                     ByVal riskManagementNumber As String, ByVal defendants As String, _
            '                                     ByVal thirdPartyRefNumber As String)
            '    _contractNumber = contractNumber
            '    _siteID = siteID
            '    _divisionNumber = divisionNumber
            '    _claimantAddress = claimantAddress
            '    _claimantCity = claimantCity
            '    _claimantEmail = claimantEmail
            '    _claimantName = claimantName
            '    _claimantPhone = claimantPhone
            '    _claimantState = claimantState
            '    _claimantZip = claimantZip
            '    _claimantContact = claimantContact
            '    _dateOfClaim = dateOfClaim
            '    _locationOfLoss = locationOfLoss
            '    _lossDescription = lossDescription
            '    _changeOrderIssued = changeOrderIssued
            '    _matterLitigated = matterLitigated
            '    _matterDisputed = matterDisputed
            '    _comments = comments
            '    _suretyAddress = suretyAddress
            '    _suretyCity = suretyCity
            '    _suretyContact = suretyContact
            '    _suretyEmail = suretyEmail
            '    _suretyName = suretyName
            '    _suretyPhone = suretyPhone
            '    _suretyState = suretyState
            '    _suretyZip = suretyZip
            '    _bondNumber = bondNumber
            '    _riskManagementNumber = riskManagementNumber
            '    _defendants = defendants
            '    _thirdPartyRefNumber = thirdPartyRefNumber
    
            'End Sub
    
            Public Sub ClaimBondLienSetup()
    
            End Sub
            Public Property ContractNumber() As String Implements IClaimsBondsLiens.ContractNumber
                Get
                    Return _contractNumber
                End Get
                Set(ByVal value As String)
                    value = _contractNumber
                End Set
            End Property
    
            Public Property DivisionNumber() As String Implements IClaimsBondsLiens.DivisionNumber
                Get
                    Return _divisionNumber
    
                End Get
                Set(ByVal value As String)
                    value = _divisionNumber
    
                End Set
            End Property
    
            Public Property SiteID() As String Implements IClaimsBondsLiens.SiteID
                Get
                    Return _siteID
    
                End Get
                Set(ByVal value As String)
                    value = _siteID
    
                End Set
            End Property
    
            Public Property BondNumber() As String Implements IClaimsBondsLiens.BondNumber
                Get
                    Return _bondNumber
    
                End Get
                Set(ByVal value As String)
                    value = _bondNumber
                End Set
            End Property
    
            Public Property ChangeOrderIssued() As String Implements IClaimsBondsLiens.ChangeOrderIssued
                Get
                    Return _changeOrderIssued
                End Get
                Set(ByVal value As String)
                    value = _changeOrderIssued
                End Set
            End Property
    
            Public Property ClaimantAddress() As String Implements IClaimsBondsLiens.ClaimantAddress
                Get
                    Return _claimantAddress
    
                End Get
                Set(ByVal value As String)
                    value = _claimantAddress.ToLower()
                End Set
            End Property
    
            Public Property ClaimantCity() As String Implements IClaimsBondsLiens.ClaimantCity
                Get
                    Return _claimantCity
                End Get
                Set(ByVal value As String)
                    value = _claimantCity
                End Set
            End Property
    
            Public Property ClaimantContact() As String Implements IClaimsBondsLiens.ClaimantContact
                Get
                    Return _claimantContact
    
                End Get
                Set(ByVal value As String)
                    value = _claimantContact
                End Set
            End Property
    
            Public Property ClaimantEmail() As String Implements IClaimsBondsLiens.ClaimantEmail
                Get
                    Return _claimantEmail
                End Get
                Set(ByVal value As String)
                    value = _claimantEmail
                End Set
            End Property
    
            Public Property ClaimantName() As String Implements IClaimsBondsLiens.ClaimantName
                Get
                    Return _claimantName
                End Get
                Set(ByVal value As String)
                    value = _claimantName
                End Set
            End Property
    
            Public Property ClaimantPhone() As String Implements IClaimsBondsLiens.ClaimantPhone
                Get
                    Return _claimantPhone
                End Get
                Set(ByVal value As String)
                    value = _claimantPhone
                End Set
            End Property
    
            Public Property ClaimantState() As String Implements IClaimsBondsLiens.ClaimantState
                Get
                    Return _claimantState
                End Get
                Set(ByVal value As String)
                    value = _claimantState
                End Set
            End Property
    
            Public Property ClaimantZip() As String Implements IClaimsBondsLiens.ClaimantZip
                Get
                    Return _claimantZip
                End Get
                Set(ByVal value As String)
                    value = _claimantZip
                End Set
            End Property
    
            Public Property Comments() As String Implements IClaimsBondsLiens.Comments
                Get
                    Return _comments
    
                End Get
                Set(ByVal value As String)
                    value = _comments
                End Set
            End Property
    
            Public Property DateOfClaim() As String Implements IClaimsBondsLiens.DateOfClaim
                Get
                    Return _dateOfClaim
                End Get
                Set(ByVal value As String)
                    value = _dateOfClaim
                End Set
            End Property
    
            Public Property Defendants() As String Implements IClaimsBondsLiens.Defendants
                Get
                    Return _defendants
    
                End Get
                Set(ByVal value As String)
                    value = _defendants
                End Set
            End Property
    
            Public Property LocationOfLoss() As String Implements IClaimsBondsLiens.LocationOfLoss
                Get
                    Return _locationOfLoss
                End Get
                Set(ByVal value As String)
                    value = _locationOfLoss
                End Set
            End Property
    
            Public Property LossDescription() As String Implements IClaimsBondsLiens.LossDescription
                Get
                    Return _lossDescription
                End Get
                Set(ByVal value As String)
                    value = _lossDescription
                End Set
            End Property
    
            Public Property MatterDisputed() As String Implements IClaimsBondsLiens.MatterDisputed
                Get
                    Return _matterDisputed
                End Get
                Set(ByVal value As String)
                    value = _matterDisputed
                End Set
            End Property
    
            Public Property MatterLitigated() As String Implements IClaimsBondsLiens.MatterLitigated
                Get
                    Return _matterLitigated
                End Get
                Set(ByVal value As String)
                    value = _matterLitigated
                End Set
            End Property
    
            Public Property RiskManagementNumber() As String Implements IClaimsBondsLiens.RiskManagementNumber
                Get
                    Return _riskManagementNumber
                End Get
                Set(ByVal value As String)
                    value = _riskManagementNumber
                End Set
            End Property
    
            Public Property SuretyAddress() As String Implements IClaimsBondsLiens.SuretyAddress
                Get
                    Return _suretyAddress
                End Get
                Set(ByVal value As String)
                    value = _suretyAddress
                End Set
            End Property
    
            Public Property SuretyCity() As String Implements IClaimsBondsLiens.SuretyCity
                Get
                    Return _suretyCity
    
                End Get
                Set(ByVal value As String)
                    value = _suretyCity
                End Set
            End Property
    
            Public Property SuretyContact() As String Implements IClaimsBondsLiens.SuretyContact
                Get
                    Return _suretyContact
    
                End Get
                Set(ByVal value As String)
                    value = _suretyContact
                End Set
            End Property
    
            Public Property SuretyEmail() As String Implements IClaimsBondsLiens.SuretyEmail
                Get
                    Return _suretyEmail
    
                End Get
                Set(ByVal value As String)
                    value = _suretyEmail
                End Set
            End Property
    
            Public Property SuretyName() As String Implements IClaimsBondsLiens.SuretyName
                Get
                    Return _suretyName
    
                End Get
                Set(ByVal value As String)
                    value = _suretyName
                End Set
            End Property
    
            Public Property SuretyPhone() As String Implements IClaimsBondsLiens.SuretyPhone
                Get
                    Return _suretyPhone
    
                End Get
                Set(ByVal value As String)
                    value = _suretyPhone
                End Set
            End Property
    
            Public Property SuretyState() As String Implements IClaimsBondsLiens.SuretyState
                Get
                    Return _suretyState
    
                End Get
                Set(ByVal value As String)
                    value = _suretyState
                End Set
            End Property
    
            Public Property SuretyZip() As String Implements IClaimsBondsLiens.SuretyZip
                Get
                    Return _suretyZip
    
                End Get
                Set(ByVal value As String)
                    value = _suretyZip
                End Set
            End Property
    
            Public Property ThirdPartyRefNumber() As String Implements IClaimsBondsLiens.ThirdPartyRefNumber
                Get
                    Return _thirdPartyRefNumber
    
                End Get
                Set(ByVal value As String)
                    value = _thirdPartyRefNumber
                End Set
            End Property
    
            Public MustOverride Function UpdateData(ByVal _contractNumber As String, ByVal _siteID As String, _
                                                    ByVal _divisionNumber As String, ByVal _claimantAddress As String, _
                                                    ByVal _claimantCity As String, _
                                                    ByVal _claimantEmail As String, ByVal _claimantName As String, _
                                                    ByVal _claimantPhone As String, ByVal _claimantState As String, _
                                                    ByVal _claimantZip As String, ByVal _claimantContact As String, _
                                                    ByVal _dateOfClaim As String, ByVal _locationOfLoss As String, _
                                                    ByVal _lossDescription As String, ByVal _changeOrderIssued As String, _
                                                    ByVal _matterLitigated As String, ByVal _matterDisputed As String, _
                                                    ByVal _comments As String, ByVal _suretyAddress As String, _
                                                    ByVal _suretyCity As String, ByVal _suretyContact As String, _
                                                    ByVal _suretyEmail As String, ByVal _suretyName As String, _
                                                    ByVal _suretyPhone As String, ByVal _suretyState As String, _
                                                    ByVal _suretyZip As String, ByVal _bondNumber As String, _
                                                    ByVal _riskManagementNumber As String, ByVal _defendants As String, _
                                                    ByVal _thirdPartyRefNumber As String) As Boolean
    
            Public MustOverride Function InsertData(ByVal _contractNumber As String, ByVal _siteID As String, _
                                                    ByVal _divisionNumber As String, _
                                                    ByVal _claimantAddress As String, ByVal _claimantCity As String, _
                                                    ByVal _claimantEmail As String, ByVal _claimantName As String, _
                                                    ByVal _claimantPhone As String, ByVal _claimantState As String, _
                                                    ByVal _claimantZip As String, ByVal _claimantContact As String, _
                                                    ByVal _dateOfClaim As String, ByVal _locationOfLoss As String, _
                                                    ByVal _lossDescription As String, ByVal _changeOrderIssued As String, _
                                                    ByVal _matterLitigated As String, ByVal _matterDisputed As String, _
                                                    ByVal _comments As String, ByVal _suretyAddress As String, _
                                                    ByVal _suretyCity As String, ByVal _suretyContact As String, _
                                                    ByVal _suretyEmail As String, ByVal _suretyName As String, _
                                                    ByVal _suretyPhone As String, ByVal _suretyState As String, _
                                                    ByVal _suretyZip As String, ByVal _bondNumber As String, _
                                                    ByVal _riskManagementNumber As String, ByVal _defendants As String, _
                                                    ByVal _thirdPartyRefNumber As String) As Boolean
    
    
        End Class
    End Namespace
    


    --ClaimsBondsLiensDAL --

    Imports System
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Web.Configuration
    Imports System.IO
    Imports Microsoft.VisualBasic
    Imports System.Data.Linq.DataContext
    
    Namespace ClaimsBondsLiens
        Public Class ClaimsBondsLiensDAL
            Inherits ClaimsBondsLiens
    
    
            Dim connectionstring As String = WebConfigurationManager.ConnectionStrings("ContractsConnectionString").ConnectionString
    
    
            Public Overrides Function InsertData(ByVal _contractNumber As String, ByVal _siteID As String, ByVal _divisionNumber As String, _
                                                 ByVal _claimantAddress As String, ByVal _claimantCity As String, ByVal _claimantEmail As String, _
                                                 ByVal _claimantName As String, ByVal _claimantPhone As String, ByVal _claimantState As String, _
                                                 ByVal _claimantZip As String, ByVal _claimantContact As String, ByVal _dateOfClaim As String, _
                                                 ByVal _locationOfLoss As String, ByVal _lossDescription As String, ByVal _changeOrderIssued As String, _
                                                 ByVal _matterLitigated As String, ByVal _matterDisputed As String, ByVal _comments As String, _
                                                 ByVal _suretyAddress As String, ByVal _suretyCity As String, ByVal _suretyContact As String, _
                                                 ByVal _suretyEmail As String, ByVal _suretyName As String, ByVal _suretyPhone As String, _
                                                 ByVal _suretyState As String, ByVal _suretyZip As String, ByVal _bondNumber As String, _
                                                 ByVal _riskManagementNumber As String, ByVal _defendants As String, _
                                                 ByVal _thirdPartyRefNumber As String) As Boolean
    
    
            End Function
    
            Public Overrides Function UpdateData(ByVal _contractNumber As String, ByVal _siteID As String, _
                                                 ByVal _divisionNumber As String, ByVal _claimantAddress As String, _
                                                 ByVal _claimantCity As String, ByVal _claimantEmail As String, _
                                                 ByVal _claimantName As String, ByVal _claimantPhone As String, _
                                                 ByVal _claimantState As String, ByVal _claimantZip As String, _
                                                 ByVal _claimantContact As String, ByVal _dateOfClaim As String, _
                                                 ByVal _locationOfLoss As String, ByVal _lossDescription As String, _
                                                 ByVal _changeOrderIssued As String, ByVal _matterLitigated As String, _
                                                 ByVal _matterDisputed As String, ByVal _comments As String, _
                                                 ByVal _suretyAddress As String, ByVal _suretyCity As String, _
                                                 ByVal _suretyContact As String, ByVal _suretyEmail As String, _
                                                 ByVal _suretyName As String, ByVal _suretyPhone As String, _
                                                 ByVal _suretyState As String, ByVal _suretyZip As String, _
                                                 ByVal _bondNumber As String, ByVal _riskManagementNumber As String, _
                                                 ByVal _defendants As String, ByVal _thirdPartyRefNumber As String) As Boolean
    
    
            End Function
        End Class
    End Namespace
    


     

     -- function in code to execute logic layers --

    Dim c As ClaimsBondsLiens.ClaimsBondsLiens = New ClaimsBondsLiensDAL
            c._contractNumber = Session("ContractNumber")
            c._siteID = Session("SITEID")
            c._divisionNumber = Session("DIVISION")
            c._claimantAddress = ClaimantAddressTextBox.Text
            c._claimantCity = ClaimantCityTextBox.Text
            c._claimantEmail = ClaimantEmailTextBox.Text
            c._claimantName = ClaimantNameTextBox.Text
            c._claimantPhone = ClaimantPhoneTextBox.Text
            c._claimantState = ClaimantStateTextBox.Text
            c._claimantZip = ClaimantZipTextBox.Text
            c._claimantContact = ClaimantContactTextBox.Text
            c._dateOfClaim = DateOfClaimTextBox.Text
            c._locationOfLoss = LocationOfLossTextBox.Text
            c._lossDescription = LossDescriptionTextBox.Text
            c._changeOrderIssued = ChangeOrderIssuedTextBox.Text
            c._matterLitigated = MatterLitigatedTextBox.Text
            c._matterDisputed = MatterDisputedTextBox.Text
            c._comments = CommentsTextBox.Text
            c._suretyAddress = SuretyAddressTextBox.Text
            c._suretyCity = SuretyCityTextBox.Text
            c._suretyContact = SuretyContactTextBox.Text
            c._suretyEmail = SuretyEmailTextBox.Text
            c._suretyName = SuretyNameTextBox.Text
            c._suretyPhone = SuretyPhoneTextBox.Text
            c._suretyState = SuretyStateTextBox.Text
            c._suretyZip = SuretyZipTextBox.Text
            c._bondNumber = BondNumberTextBox.Text
            c._riskManagementNumber = RiskManagementNumberTextBox.Text
            c._defendants = DefendantsTextBox.Text
            c._thirdPartyRefNumber = ThirdPartyRefNumberTextBox.Text
    
            c.UpdateData(c._contractNumber, c._siteID, c._divisionNumber, c._claimantAddress, c._claimantCity, c._claimantEmail, _
                         c._claimantName, c._claimantPhone, c._claimantState, c.ClaimantZip, c._claimantContact, c._dateOfClaim, _
                         c._locationOfLoss, c._lossDescription, c._changeOrderIssued, c._matterLitigated, c._matterDisputed, c._comments, _
                         c._suretyAddress, c._suretyCity, c._suretyContact, c._suretyEmail, c._suretyName, c._suretyPhone, c._suretyState, _
                         c._suretyZip, c._bondNumber, c._riskManagementNumber, c._defendants, c._thirdPartyRefNumber)


     

    Wednesday, May 26, 2010 12:10 PM
  • User-952121411 posted

     

    Is there a way to do this, by creating the backing contract with the interface? I am really trying to implement oop and hope i am doing it right.

    I just had a nice response typed, opened a new tab, hit the 'Home' button, and it reverted this tab to my home page instead of the new tab.  Result: I lost everything I had typed to you.  Thanks IE Yell

    Anyways, in my last response I was referring to the 'backing variables' of the properties not a backing contract as you mention.  However I believe we are talking about the same thing.  I understand what you are attempting to accomplish.  You want the developer implementing your Interface to have the backing variables of the properties predefined upon implementation which is essentially the implementation code.  I don't think typically you want to do this as you are defeating the main purpose of what an Interface contract does.  The only Interface I am aware of that does anything like this is the IDisposable Interface in .NET, which does define some of the code upon implementation. In theory and in practice, an Interface you are designing defines what the implementing class should look like but not the actual 'How' or details.

    Lets use an example of an Interface named IStartEngine.  On this interface is a method named GetStartProcedure().  You know that various types of engines on different consumers will be used such as a Boat, Car, Lawnmower, etc.  If the Car implements the Interface, its implementation code for the GetStartProcedure() method would be 'Get keys, put keys in ignition, turn keys, etc.'.  Now if a Lawnmower type Implemented the same Interface its implementation code for GetStartProcedure() might be 'Prime Engine, Pull Clutch Handle, Pull Cord, etc.'.  So see they both inherit the same Interface but have different Implementation details.  This is the power behind an Interface.  Especially when working with the Interface type.  If your code works with the Interface type as opposed to the concrete type, you don't know how the code was implemented or really care.  Different objects can have identical requests but have different implementations to fulfill the request.  Being able to substitute objects that have the same interface is powerful. This little OOP notion is called Polymorphism.

    So you see to leverage the true power of an Interface, you probably don't want to provide the actual implementation code for the Implementing class.  Hopefully you can apply this to your design to help.

    Wednesday, May 26, 2010 3:28 PM
  • User1080785583 posted

    So if my application has multiple types of Update, Insert, Delete procedures, I could make an interface called IUpdate, IDelete and IInsert which will require my class to use the MustOverride Update function that I include? Can I do this with 3 Interfaces or would it be better to generalize, how your IStartEngine example explains there are different types of engines which is the purpose of the interface.

    Wednesday, May 26, 2010 3:47 PM
  • User-952121411 posted

    So if my application has multiple types of Update, Insert, Delete procedures,
     

    While you could do this, it would not make too much sense to isolate those methods into their own interfaces.  Those CRUD type methods are usually a part of a larger class (i.e. Customer, Orders, Products, etc.) that all contain their own '.Get', '.Save', '.Delete', etc methods.  Each of those classes might have an Interface designed for them, but I typically do not design one specifically for those operations.  Also remember that the Interface also declares the method parameters.  A .Save method for one Interface might take a type of ICustomer, and another takes a type of IOrders, so it would be difficult to create a Single Interface for a Insert or Update unless all classes shred the same Interface.

    You also don't have to design your interfaces to expose/use all of the OOP attributes available.  What I mean is, go ahead and design the Interfaces for your classes and begin to learn how they work.  If you don't design them perfectly the 1st time, and figure out how to make objects polymorphic, etc. no need to worry.  At this point just become familiar on how they work.  As a side note, if you ever build a WCF service you will learn about Interfaces really quickly.  This is because they all require defining the Interface for the methods exposed by the service.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 27, 2010 9:16 AM