By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,387 Members | 1,729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,387 IT Pros & Developers. It's quick & easy.

Define "class" please

P: n/a
Rob
In many articles related to VB.net the word "class" is used...

How many meanings are there to this word ?

"possible to derived a class from another"

"forms are full-fledged classes"

"base class"


Nov 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
A "class" really is just an object. It's the most basic thing to
Object Oriented Programming.

A class is merely a code file that defines an object - defines
properties of an object, and methods (functions or procedures) of an
object. Pretty much, what the object is and what it can do. That's
the most basic definition of a class.

As far as deriving a class from another class or deriving from a base
class, that deals with inheritance. Inheritance is another major
concept of Object Oriented Programming. Here's a quick explanation of
what a base class is. A base class is an object that can be inherited
by other classes. In other words, these sub-classes (classes that
inherit from the base class. aka child classes) have all the behavior
of the base class (sometimes called the parent class) plus the
additional behavior of the child class. So think about a Vehicle. Say
you defined a vehicle as a base class. Well a car could be a child
class as well as a boat. They can share some of the same types of
behavior - properties such as color and size, while it can have some
similar methods like Turn On and Turn Off. But then each of the child
classes would also need to have their own methods and/or properties. A
car for example would need a wheel axle, while a boat will need to have
a rudder.

And as for Windows Forms, well those are classes too in .NET. Think of
the form as an object. The form has controls on it such as text boxes
and buttons. Also any forms you add to your project are also child
classes which derive from a base class. You'll notice in the
definition of the class you'll see
Public Class Form1 Inherits System.Windows.Forms

All that means is that the object (class) Form1 shares behaviors of
System.Windows.Forms and also will have the behavior that is described
in the class itself (All the code between "Public Class" and "End
Class")

I hope that clears it up for you. You might want to not try and read
articles about VB.Net and rather get a beginnning VB.Net book. That
will not only help you understand VB .NET but also get you some insight
into Object Oriented Programming and its concepts. You might also want
to get an Obj. Oriented Prog. book too if you're having further trouble
understanding the concepts. Or even better, think about taking a class
at a local Community College for VB .NET and/or OOP. You may event
want to look for a Java class which will help with a lot with the OOP
concepts.

Nov 23 '05 #2

P: n/a
sounds like you need to pick up a book on oo (object oriented) design.

a class is a template for an object. you create objects from classes.

class dog - can bark, has four legs

instantiate this class to make an object of this class (dog), call it
"collie"

now you have an object that can bark and has four legs. You can extend this
definition to have long hair, because a collie does. now you have a derived
class called "collie" that inherits the class "dog".

a windows form is the same type of thing. when you make a new form (form1),
you automatically inherit the base "windows.forms.form" class....you can
"extend" this form you created and make a form2. Form 2 magically has all
the same labels, textboxes, and other controls that your form1 does. but
you can make it do even more.

but, dont take my word for it...i probably screwed up this explination, so
get a book on object oriented design.

hope this helps you get started!

gh
"Rob" <rw*****@comcast.net> wrote in message
news:mv********************@comcast.com...
In many articles related to VB.net the word "class" is used...

How many meanings are there to this word ?

"possible to derived a class from another"

"forms are full-fledged classes"

"base class"

Nov 23 '05 #3

P: n/a
Rob wrote:
In many articles related to VB.net the word "class" is used...
How many meanings are there to this word ?
"possible to derived a class from another"
"forms are full-fledged classes"
"base class"


A class is the definition of a type. Whenever you declare a class, you
introduce a new type in your program (or library, whatever).

Ex:
Class Ancestor
'...
End Class

After having declared this new type (Ancestor) I'm able to create
instances of that type:

Ex:
Dim X As New Ancestor

Now X references an instance of a class named Ancestor. The instance of
the class is called "object". The variable X is called a "reference".

So far so good. Of course, having new types means nothing if I can't
manipulate them. That's why class types may implement behaviour (by way
of Subs, Functions and Operators) and properties (by way of err...
Properties). Besides, they may have internal members just like
variables. So let's redesign our Ancestor class to give it a few
"members".

Ex:
Class Ancestor
Private mName As String

Public Sub DoThis: End Sub
Public Sub DoThat: End Sub

Public Property Name As String
Get: Return mName: End Get
Set(Value As String): mName = Value.ToUpper: End Set
End Property
End Class

Now, if I declare a variable of the Ancestor type, say, Dim X As New
Ancestor, I may manipulate the object through X.

Ex:
Dim X As New Ancestor
X.DoThis
X.DoThat
X.Name = "Francisco"

Notice that the member mName is private, and therefore can't be seen
"from the outside". This is called "Encapsulation" in OOP speak, and
means that classes may hide details of their implementation.

Well, contrary to other types you see in VB.Net (Integer, Double, etc),
class-based types can be extended. This means that I can declare
another class type that extends an existing one.

Ex:
Class Derived : Inherits Ancestor
Sub DoSomething: End Sub
End Class

I just created a new type, this time called Derived. I may declare
variables of type "Derived" from now on.

Ex:
Dim Y As New Derived

The fact that the Derived type inherits from the Ancestor type means
that besides being the "Derived" type, this new type is also an
"Ancestor". In other words, whenever I declare a variable of type
Derived, I'm implicitly saying that it's of type Ancestor also. This
means also that all functionality implemented in the Ancestor type is
still available in the Derived type, together with the functionality
declared in the Derived type itself.

Ex:
Dim Y As New Derived
Y.DoThis 'Inherited from Ancestor
Y.DoThat 'Inherited from Ancestor
Y.DoSomething 'specific of Derived
Y.Name = "Carmen" 'Inherited from Ancestor

This quality of classes is called Inheritance. It allows a great deal
of code reuse, because you create base types (ancestors) with a base
functionality and create derived types that extend or alter that base
functionality.

Nevertheless, the fact that a type inherits from another, means also
that the derived type may be taken as if it was it's ancestor!

Ex:
Dim Z As Ancestor
Z = New Derived 'Wow! what gives???
Z.DoThis
Z.DoThat
Z.Name = "Maria"

The previous example is perfectly legal: derived types may represent
ancestor types (but not the contrary!). Of course, since the variable Z
represents an Ancestor type, even though it is "loaded" with an
instance of a Derived type, you can only use it as if it was an
Ancestor...

Ex:
Dim Z As Ancestor = New Derived
Z.DoThis 'Ok, it's an Ancestor method
Z.DoSomething 'na-na-na... DoSomething doesn't exist in the Ancestor
type

This may seem like a show stoper, but actually there's more things
going on under the curtains. It turns out that a derived type may
change the behaviour of methods declared in the ancestor type. If, for
instance, our ancestor type was declared like this:

Ex:
Class Ancestor
'...
Overridable Sub PrintYourName
Console.Writeln(mName)
End Sub
End Class

Dim W As New Ancestor
W.Name = "Pedro"
W.PrintYourName ' will print "PEDRO"

No we could change the behavior of the PrintYourName method from a
derived class. More over, whenever a variable *of the ancestor type*
(but referencing an instance of the derived type) executed the
PrintYourName method, the executed code would come from the derived
type!

Ex:
Class Derived
'...
Overrides Sub PrintYourName
Console.WriteLn(Name & " derived!")
End Sub
End Class

Dim W As Ancestor = New Derived
W.Name = "Pedro"
W.PrintYourName ' will print "PEDRO derived!"

This characteristic of classes is called Polymorphism.

Although all this may seem far-fetched, notice that you're constantly
applying these concepts in your VB.Net programs. When you declare a
form (or, actually, the framework declares one for you) you'll notice
that it's a new type extending an existing one:

Ex:
Public Class Form1
Inherits System.Windows.Forms.Form
'...
End Class

And many methods of your form are actually overrides of methods
declared in the Form class. Because of this, the framework may treat
objects of your new type (Form1 in the example) as if they were of type
Form. That's how all the magic happens. ;-)

Hope this helped.

Regards,

Branco.

Nov 23 '05 #4

P: n/a

"Rob" <rw*****@comcast.net> wrote in message
news:mv********************@comcast.com...
In many articles related to VB.net the word "class" is used...

How many meanings are there to this word ?

"possible to derived a class from another"

"forms are full-fledged classes"

"base class"


You can create (instantiate) objects from a class.
For instance:
a text box you see in the toolbox is a 'Class'
when you drag the textbox onto your form, you create an instance of the
textBox class - you have 'instantiated' it. it has identity and state.
Identity is the name you give to the textbox. Its state refers to the values
of its instance variables (the properties).
a Class is the code from which you can instantiate objects.
that's enough for now - you won't get a complete lesson over a newsgroup.
When you see the word 'Class' in the book - keep reading.
Nov 23 '05 #5

P: n/a
Rob,

In addition to the others

A class can have shared members, than the class is for those shared members
direct a part of the program. It does not need to be instanced, those
members are a consistent part of your program.

In the mainform in VBNet is a construction that automatic instances that
mainform as a shared class in your program. This as you set in the project
properties that it is the startup class. I thought that there are 7 other
startup methods once described by Jay. With that startup form you get than a
kind of behaviour as wooster11 describes.

I hope this helps,

Cor
"Rob" <rw*****@comcast.net> schreef in bericht
news:mv********************@comcast.com...
In many articles related to VB.net the word "class" is used...

How many meanings are there to this word ?

"possible to derived a class from another"

"forms are full-fledged classes"

"base class"

Nov 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.