Inheritance

  • Thread starter Thread starter Chris Kennedy
  • Start date Start date
Hi Chris,

These two things are in theory very different, although it might look
like they are sort of having a similar effect. I'm not sure that the
straightforward answer will actually help you very much because if you
haven't ever come across it before the concept is a bit complex.

Importing (adding an Imports reference to the top of a class file) is a
kind of "reference" from your file to a specific namespace. The simple way
to understand it is by example:

Without importing any namespaces into my file I might want to refer to a
class within the system.web.util namespace - to do so every time I referred
to it I would need to write:

dim XXX as system.web.util.transactions

If I add the line Imports system.web.util at the top of my file I can refer
to it simply as

dim XXX as transactions

Inheritance is totally different. Inheritance is a way of
"compartmentalising", sharing, reusing and organising chunks of code into
"objects" (classes). When I say:

Public Class MyCustomControl : inherits Webcontrol

Then I'm using inheritance - what I'm doing is saying "here is a blueprint
for a MyCustomControl - it's a type of WebControl, so it shares everything
that a webcontrol has, but with additions and differences". A really good
book on inheritance and object orientated programming is (in my opinion)
Thinking in Java by Bruce Eckel. I know java is mud - but Bruce Eckel is
very very good at helping you to "think" in object orientated ways rather
than just learn about how it works.

As always I stand ready to be corrected by someone more knowedgeable than
me - but this is my understanding of the differences between imports and
inheritance. Anyone else care to comment?

Nick
 
Importing a namespace is simply a convenience which allows you to refer to
classes in that namespace without having to type the full namespace.
Example:

Imports System.Web.UI

Dim C As Control

Without the Imporst statement, every time you created a Control, you'd have
to write:

Dim C As System.Web.UI.Control

---

Inheritng is the process of assigning all the inheritable characteristics of
a class to a new class which inherits and extends the original class with
additional characteristics. Example:

Class foo
public Integer fooNum
End Class

Class bar
Inherits foo
public string barString
End Class

Class bar has 2 members: fooNum from the inherited class, and barString from
the derived class.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Back
Top