Results 1 to 10 of 10

Thread: [RESOLVED] [02/03] what is the difference between MustInherit Public Class and

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    244

    Resolved [RESOLVED] [02/03] what is the difference between MustInherit Public Class and

    What is the difference between MustInherit Public Class and Public MustInherit Class?? I've seen some source codes where a class is declared as MustInherit Public Class. but when i try to do that; it changes into second one. why is it so?? is there any difference between two?? if it is so then how can we do that???

    it seems very strange to me when i try to write "MustInherit Public Class myClass" it changes to "Public MustInherit Class". but in the source code; it doesn't happen. why is it so??

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,461

    Re: [02/03] what is the difference between MustInherit Public Class and

    If you have the default option selected then the IDE will reformat your code how it wants it, and it likes modifiers in a particular order. If someone has written their code outside the VS IDE or have turned of the pretty listing option then it will remain as they typed it. It makes no practical difference.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    244

    Re: [02/03] what is the difference between MustInherit Public Class and

    Quote Originally Posted by jmcilhinney
    If you have the default option selected then the IDE will reformat your code how it wants it, and it likes modifiers in a particular order. If someone has written their code outside the VS IDE or have turned of the pretty listing option then it will remain as they typed it. It makes no practical difference.
    I've declared AccessDataAccessLayer as

    Public Class AccessDataAccessLayer
    Inherits DataAccessLayerBaseClass

    while DataAccessLayer as

    Public MustInherit Class DataAccessLayerBaseClass

    but compiler IDE gives an error saying:

    "Class 'AccessDataAccessLayer' must either be declared 'MustInherit' or override the following inherited 'MustOverride' member(s)

    while i've declared its functions as

    Public MustOverride Function Authenticate(ByVal username As String, ByVal password As String) As Boolean

    what should i do to remove this error??

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: [02/03] what is the difference between MustInherit Public Class and

    Any methods marked MustOverride in the baseclass, need to be declared in the child class with the Overrides keyword... The IDE should create the function declaration for you when you set the class to inherit from the base...

    a crude example would look something like this
    VB Code:
    1. Public MustInherit Class MyBaseClass
    2.  
    3.     Public MustOverride Function DoStuff() As Boolean
    4.  
    5. End Class
    6.  
    7. Public Class ChildClass
    8.     Inherits MyBaseClass
    9.  
    10.     Public Overrides Function DoStuff() As Boolean
    11.         'DO STUFF HERE...
    12.     End Function
    13. End Class

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    244

    Re: [02/03] what is the difference between MustInherit Public Class and

    Quote Originally Posted by kleinma
    Any methods marked MustOverride in the baseclass, need to be declared in the child class with the Overrides keyword... The IDE should create the function declaration for you when you set the class to inherit from the base...

    a crude example would look something like this
    VB Code:
    1. Public MustInherit Class MyBaseClass
    2.  
    3.     Public MustOverride Function DoStuff() As Boolean
    4.  
    5. End Class
    6.  
    7. Public Class ChildClass
    8.     Inherits MyBaseClass
    9.  
    10.     Public Overrides Function DoStuff() As Boolean
    11.         'DO STUFF HERE...
    12.     End Function
    13. End Class
    i've did so but despite of this;i'm getting the above error. like my base class is


    Public MustInherit Class DataAccessLayerBaseClass

    Public MustOverride Function Authenticate(ByVal username As String, ByVal password As String) As Boolean


    While child class is as under. but i got error of the following declaration of child class giving message mentioned above. I'm totally confused why i'm getting this message

    Public Class AccessDataAccessLayer
    Inherits DataAccessLayerBaseClass

    Public Overrides Function Authenticate(ByVal username As String, ByVal password As String) As Boolean
    ' validate Parameters
    If username Is Nothing OrElse username.Length = 0 Then
    Throw New ArgumentOutOfRangeException("username")
    End If
    If password Is Nothing OrElse password.Length = 0 Then
    Throw New ArgumentOutOfRangeException("password")
    End If

    ' Execute SQL Command
    Dim sqlCmd As New OleDbCommand
    SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_USER_AUTHENTICATE)

    AddParamToSQLCmd(sqlCmd, "@userName", OleDbType.VarWChar, 255, ParameterDirection.Input, username)
    AddParamToSQLCmd(sqlCmd, "@userPassword", OleDbType.VarWChar, 255, ParameterDirection.Input, password)

    Dim returnValue As Object = ExecuteScalarCmd(sqlCmd)
    Return IIf(returnValue Is Nothing, False, True)
    End Function 'Authenticate

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: [02/03] what is the difference between MustInherit Public Class and

    I get no errors with this code

    VB Code:
    1. Public MustInherit Class DataAccessLayerBaseClass
    2.     Public MustOverride Function Authenticate(ByVal username As String, ByVal password As String) As Boolean
    3.  
    4. End Class
    5.  
    6. Public Class AccessDataAccessLayer
    7.     Inherits DataAccessLayerBaseClass
    8.  
    9.     Public Overrides Function Authenticate(ByVal username As String, ByVal password As String) As Boolean
    10.         ' validate Parameters
    11.         If username Is Nothing OrElse username.Length = 0 Then
    12.             Throw New ArgumentOutOfRangeException("username")
    13.         End If
    14.         If password Is Nothing OrElse password.Length = 0 Then
    15.             Throw New ArgumentOutOfRangeException("password")
    16.         End If
    17.  
    18.         ' Execute SQL Command
    19.         Dim sqlCmd As New OleDbCommand
    20.         SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_USER_AUTHENTICATE)
    21.  
    22.         AddParamToSQLCmd(sqlCmd, "@userName", OleDbType.VarWChar, 255, ParameterDirection.Input, username)
    23.         AddParamToSQLCmd(sqlCmd, "@userPassword", OleDbType.VarWChar, 255, ParameterDirection.Input, password)
    24.  
    25.         Dim returnValue As Object = ExecuteScalarCmd(sqlCmd)
    26.         Return IIf(returnValue Is Nothing, False, True)
    27.     End Function 'Authenticate
    28. End Class

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    244

    Re: [02/03] what is the difference between MustInherit Public Class and

    Quote Originally Posted by kleinma
    I get no errors with this code

    VB Code:
    1. Public MustInherit Class DataAccessLayerBaseClass
    2.     Public MustOverride Function Authenticate(ByVal username As String, ByVal password As String) As Boolean
    3.  
    4. End Class
    5.  
    6. Public Class AccessDataAccessLayer
    7.     Inherits DataAccessLayerBaseClass
    8.  
    9.     Public Overrides Function Authenticate(ByVal username As String, ByVal password As String) As Boolean
    10.         ' validate Parameters
    11.         If username Is Nothing OrElse username.Length = 0 Then
    12.             Throw New ArgumentOutOfRangeException("username")
    13.         End If
    14.         If password Is Nothing OrElse password.Length = 0 Then
    15.             Throw New ArgumentOutOfRangeException("password")
    16.         End If
    17.  
    18.         ' Execute SQL Command
    19.         Dim sqlCmd As New OleDbCommand
    20.         SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_USER_AUTHENTICATE)
    21.  
    22.         AddParamToSQLCmd(sqlCmd, "@userName", OleDbType.VarWChar, 255, ParameterDirection.Input, username)
    23.         AddParamToSQLCmd(sqlCmd, "@userPassword", OleDbType.VarWChar, 255, ParameterDirection.Input, password)
    24.  
    25.         Dim returnValue As Object = ExecuteScalarCmd(sqlCmd)
    26.         Return IIf(returnValue Is Nothing, False, True)
    27.     End Function 'Authenticate
    28. End Class

    that's also strange to me. there is no apparent error in this code. even in one application; this piece of code is running but when i try to use it in another application; this error comes. to you; what would be the reason of error??

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: [02/03] what is the difference between MustInherit Public Class and

    it could be a conflict somewhere.. make sure you don't have the class declared twice or something

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    244

    Resolved Re: [02/03] what is the difference between MustInherit Public Class and

    Quote Originally Posted by kleinma
    it could be a conflict somewhere.. make sure you don't have the class declared twice or something
    i've resolved it. Actually; i've made 3 layer architecture. when accessing the the classed of Busines logic layer in these methods; i was not using Namespace that's why having problem.
    Now; i've resolved it. thanx so much for ur cooperation

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,383

    Re: [02/03] what is the difference between MustInherit Public Class and

    Glad to hear you got it sorted. You can mark the thread resolved using the threadtools above

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width