Results 1 to 2 of 2

Thread: Shared members and interfaces

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662

    Shared members and interfaces

    I'm trying to figure out a way to use an interface or maybe a MustInherit class to make sure a derived class has a specific shared member. Interfaces only enforce instance members. MustInherit classes support shared members but without the Overrideable keyword.

    Any ideas on how to make sure a derived class has a specific shared member? I'd rather not have the member be an instance member, but I will if this can't be done.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Shared members and interfaces

    The point of inheritance and overriding members is polymorphism and polymorphism only applies to instances. You don't call Shared members on instances so overriding Shared members serves no purpose.

    For example, you should be able to create an OleDbConnection instance and an SqlConnection instance and pass them both to a method that expects a DbConnection object and call their Open and Close methods. That's the whole point. You don't call Shared members on instances of any class so what's the point of ensuring that a class has the same member as its base when there is no instance to cast as any type?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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