Get up to 80 % extra points for free! More info:

Discussion – Lesson 14 - Interfaces in VB.NET

Back

 

Comments
Avatar
Ama .
Member
Avatar
Ama .:2/5/2019 8:03

Visual Basic .NET, like most programming languages, doesn't support multiple inheritance. Meaning that we can't inherit one class from more than one other class.

The author says multiple inheritance = class AB based on class A and class B.
It says that is not possible.

Next, we'll try "multiple inheritance", more accurately, implement multiple interfaces by a single class.

The author says multiple inheritance = interface A1 and A2 based on class A.
It says that is the solution to the above problem. Well, that is not a solution to the above problem, and moreover that can already be done through classic class inheritance.

He is confused about what he means by Multiple inheritence.. The purpose of inheritence is to avoid rewriting existing code, but since the code is in the class block, then it is the interface which would inherit from the code in the class, no the other way around.

Hence, he should have said "Next, we'll try 'multiple inheritance', more accurately, having a single interface implemented by several classes".

And conclude the article on

Dim bird1 As IBird = New Bird()
Dim bird2 As IBird = New Pterodactyl()
Dim bird3 As IBird = New Dodo()
Dim bird4 As IBird = New Eagle()

rather than

Dim pterodactyl As Pterodactyl = New Pterodactyl()

It's a shame because the first half of the article is good.

Edited 2/5/2019 8:04
 
Reply
2/5/2019 8:03
Avatar
Replies to Ama .
David Capka Hartinger:2/5/2019 11:37

I see how you see it :) But this way makes it confusing for me. I guess we all think differently.

Next, we'll try "multiple inheritance", more accurately, implement multiple interfaces by a single class.

This sentence shouldn't say "interface A1 and A2 based on class A.", but "class A based on interface A1 and A2". As I understand it, the phrase "implement an interface" means to add "Implements A1" to your class. I can see somebody can find it confusing, didn't think about that before.

"Next, we'll try 'multiple inheritance', more accurately, having a single interface implemented by several classes".

You could say this, but I find it confusing from my understanding to this article. The chapter is talking about adding a Pterodactyl class (a single class) based on 2 interfaces (IBird and ILizard). "Several classes" would confuse me here.

Reply
2/5/2019 11:37
You can walk through a storm and feel the wind but you know you are not the wind.
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

2 messages from 12 displayed.