Results 1 to 7 of 7

Thread: inherit or implements?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    inherit or implements?

    I have some sample code done in C#, but the code I am writing is in VB.NET

    the documentation for these DLLs I am using is total crap and gives me next to no information


    So the class declare looks like this
    Code:
    public class CImageOrderStatusListener : IOrderStatusListener
    {
        public CImageOrderStatusListener()
            {
    
            }
    
    //MORE CODE HERE
    }
    since IOrderStatusListener is an interface I would assume in my VB.NET code I would implement it, but the documentation says
    "Inner class inherits IOrderStatusListener to listen to the image order status. "

    so its a bit confusing, unless its just saying that implementing the interface is interface inheritence...

    and why have the empty function with the same name as the class.. is that a C# thing??

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: inherit or implements?

    Originally posted by kleinma
    I have some sample code done in C#, but the code I am writing is in VB.NET

    the documentation for these DLLs I am using is total crap and gives me next to no information


    So the class declare looks like this
    Code:
    public class CImageOrderStatusListener : IOrderStatusListener
    {
        public CImageOrderStatusListener()
            {
    
            }
    
    //MORE CODE HERE
    }
    since IOrderStatusListener is an interface I would assume in my VB.NET code I would implement it, but the documentation says
    "Inner class inherits IOrderStatusListener to listen to the image order status. "

    so its a bit confusing, unless its just saying that implementing the interface is interface inheritence...

    and why have the empty function with the same name as the class.. is that a C# thing??
    It's definitely implementing if the the class is an interface (which the I prefix suggests), and the method with the same name (but without a return type) as the class is the constructor

    [Edit] Got confused between inherit and implement for a moment there :P

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    and why have the empty function with the same name as the class.. is that a C# thing??
    That's the default, no arguments constructor. I don't know about your first question.

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    so it is the same thing as an empty New sub in VB.NET then right?

  5. #5
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I think it's similar, but not exactly - heh, big help I am.

    The reason I say similar is because you can freely add args to that constuctor, say in a Windows Forms app and all works fine. When I've tried to do that with VB's sub new, seemed like the form did not get initialized properly. I'm sure it's just my ignorance.

    There's also no MyBase.New business in C#, but I'm not versed well enough in the differences between those two languages to tell you what's really happening.

  6. #6
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Originally posted by Mike Hildner
    I think it's similar, but not exactly - heh, big help I am.

    The reason I say similar is because you can freely add args to that constuctor, say in a Windows Forms app and all works fine. When I've tried to do that with VB's sub new, seemed like the form did not get initialized properly. I'm sure it's just my ignorance.

    There's also no MyBase.New business in C#, but I'm not versed well enough in the differences between those two languages to tell you what's really happening.
    To get the "MyBase.New" in C#, you would:
    Code:
    public class MyClass: MyParentClass
    {
    	public MyClass(): base() // This is the call to the parent's constructor.
    	{
    		// Init code here...
    	}
    
    	// Useless info.
    	public MyClass(object someParam): this(someParam.ToString()) // This is a call to the overloaded constructor that accepts a string.
    	{
    	}
    
    	public MyClass(string someParam)
    	{
    	}
    }

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Mike Hildner
    I think it's similar, but not exactly - heh, big help I am.

    The reason I say similar is because you can freely add args to that constuctor, say in a Windows Forms app and all works fine. When I've tried to do that with VB's sub new, seemed like the form did not get initialized properly. I'm sure it's just my ignorance.

    There's also no MyBase.New business in C#, but I'm not versed well enough in the differences between those two languages to tell you what's really happening.
    you can do that in VB.NET, you just need to call the New sub that has no arguments in the first line of YOUR new sub that you created...

    like
    VB Code:
    1. Public Sub New(ByVal ID as Integer)
    2.     me.New()
    3.     'some other code here
    4. End Sub

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