• 0

[VB.NET] Multiple Inheritance


Question

Hey gang,

I fully understand that VB.NET does not support multiple inheritance. So that said we are trying to figure a way to get a form of MI anyway. Attached is a simple diagram. In this you will see that sometimes we need the MS Collection Base class (first box) and we have our Base class (BLBase)

We have our own class (BLCollection) that needs to inherit from the MS CollectionBase. What we want is to have some objects that have our BLCollection and some objects that do not... (bottom two classes) however both classes at the bottom need to inherit from our BLBase class. The diagram shows that BLBase is inheriting from CollectionBase, and this will work for us in that we simply will not use the CollectionBase functions in "Object w/o Collection"

There must be a better way... I read a little about using multiple interfaces but I'm not getting how to impliment this.

EDIT:

Ramesees. Thanks, yes I know that the first diagram will work... but what I want is the 2nd diagram (newly added) so that the "Object w/o Collection" would not carry around the CollectionBase inhertance. Not a BIG deal... but it would be nice. (thanks again)

Thanks for any help.

post-45653-1178290842.gif

post-45653-1178292192.gif

Edited by jameswjrose
Link to comment
https://www.neowin.net/forum/topic/558305-vbnet-multiple-inheritance/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

If I read that diagram correctly, if you set up your classes as they are described they will work the way you want

Here is some C# code (although the translation to VB.NET should not be difficult):

public class BLBase : CollectionBase
{

}

public class BLCollection : BLBase
{
		  //  By inheritance this will automatically inherit from CollectionBase
}

//  Now for the bottom classes

public class ObjWithoutCollection : BLBase
{

}

public class ObjWithCollection : BLCollection
{
	 //  This class will have all your specific collection code
	//   as well as the methods from BLBase and CollectionBase
}

I hope this helps :)

  • 0
  jameswjrose said:
Hey gang,

I fully understand that VB.NET does not support multiple inheritance. So that said we are trying to figure a way to get a form of MI anyway. Attached is a simple diagram. In this you will see that sometimes we need the MS Collection Base class (first box) and we have our Base class (BLBase)

We have our own class (BLCollection) that needs to inherit from the MS CollectionBase. What we want is to have some objects that have our BLCollection and some objects that do not... (bottom two classes) however both classes at the bottom need to inherit from our BLBase class. The diagram shows that BLBase is inheriting from CollectionBase, and this will work for us in that we simply will not use the CollectionBase functions in "Object w/o Collection"

There must be a better way... I read a little about using multiple interfaces but I'm not getting how to impliment this.

EDIT:

Ramesees. Thanks, yes I know that the first diagram will work... but what I want is the 2nd diagram (newly added) so that the "Object w/o Collection" would not carry around the CollectionBase inhertance. Not a BIG deal... but it would be nice. (thanks again)

Thanks for any help.

To utilize the interface method, you'd have to refactor BLCollection and have it implement IList, ICollection, and IEnumerable instead of inheriting CollectionBase, and have it inherit BLBase.

  • 0

Thank you very much. I'll give it a go first thing monday morn (hey, even geeks gota have a weekend, besides my wife just got out of the hospital, and hey, why dont you just cut me some slack.... I'll do it monday like I promised.... sheeeesh. Pushy guy)

<serious>

The model looks great, and I think I get it. Thank you very kindly. Great help.

</serious>

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Russia is based in Cyprus. AdGuard is about as Russian as Telegram is.
    • Pixel Recall anyone? Or LiveRecall, OpenRecall or WindRecorder? Someone, somewhere wants your data.
    • HP 15.6-inch laptop is 20 percent off for students and everyday users by Paul Hill If you’re a student or casual user, this HP 15.6-inch laptop (model 15-fc0499nr) may be a good fit for you, as it has been discounted by 20% from $499.99 to just $399.99. It’s not a cutting-edge machine, but at this price, its core specs are solid, making it a great back-to-school option. It’s worth pointing out that this laptop carries an Amazon’s Choice badge and has over 1,000 purchases in just the last month, highlighting its popularity. Next, we'll discuss the specifications, followed by a buying link if you're interested in purchasing it. Powering this laptop is an AMD Ryzen 5 7520U processor, 8GB of LPDDR5 RAM, and a 512GB PCIe NVMe M.2 SSD. These aren’t the highest specs ever, but for everyday tasks, you should get your tasks done efficiently. The inclusion of the SSD means your system will boot quickly and your apps will launch fast, even if launching for the first time. It has a 15.6-inch HD touchscreen display, which is a key feature and a pretty big deal at this price point. If you find yourself with a task where a mouse isn’t suited, just touch the screen instead; it seems pretty useful for graphics work if you need to do some. One shortcoming of this device is that it uses integrated AMD Radeon Graphics, which is enough for casual entertainment and light creative work, but don’t expect to be playing heavy games. As for the operating system, this laptop ships with Windows 11 Home. It’s worth pointing out here that this is not a Copilot+ PC, so it will be missing Recall and other AI features, but it does have a Copilot key. This laptop is great if you’re going to be taking it to school or college, as it’s lightweight at just 3.52 lbs (1.6kg). It also has decent connectivity with 1 USB Type-C (data transfer only), 2 USB Type-A, 1 HDMI 1.4b, and a headphone/microphone combo jack. It also features Wi-Fi 6 and Bluetooth 5.3 for modern connectivity. Other notable features include the HP True Vision 720p HD camera with noise reduction for video calls and a camera privacy shutter. The laptop also has a long-lasting battery life of up to 12 hours and supports Fast Charge, which gets you to 50% in 45 minutes. If you’re convinced by this solid entry-level laptop, check out the buying link below: HP 15.6-inch laptop (model 15-fc0499nr): $399.99 (Amazon US) / MSRP $499.99 This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • Install a cheap Chinese clone of Adguard and then take support from call center to restore to Windows XP.
    • Does the job, although it can't run windows 11 officially. Currently running Windows 10 modded with ReviOS
  • Recent Achievements

    • Dedicated
      Snake Doc earned a badge
      Dedicated
    • One Month Later
      Philsl earned a badge
      One Month Later
    • One Year In
      armandointerior640 earned a badge
      One Year In
    • One Month Later
      armandointerior640 earned a badge
      One Month Later
    • Week One Done
      Itbob513626 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      614
    2. 2
      ATLien_0
      236
    3. 3
      Xenon
      155
    4. 4
      +FloatingFatMan
      123
    5. 5
      Michael Scrip
      116
  • Tell a friend

    Love Neowin? Tell a friend!