473,418 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Define "class" please

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
5 1934
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
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter King | last post by:
if you assign multiple classes in order to keep your classes generic e.g ..classA { position.absolute; left:5 top:5 height:200 width:800 } ..classB { background-color: red} ..classC {...
0
by: Gianni Mariani | last post by:
It started out as an ugly hack and it turned out to be very easy to do but I'm concerned about wether I'm not seeing somthing so I'm asking the wise ladies and gents of clc++ as to wether they turn...
3
by: hutch | last post by:
Hi, I'm making use of this VERY useful function for a so called 'standards compliant' replacement for target="_blank": function externalLinks() { if (!document.getElementsByTagName) return;...
1
by: BobPaul | last post by:
I'm following code out of a howto book and this is really bugging me. This header file was created by VStudio 6.0 when I did a "Right Click: Add Member Function" CLine is a class I wrote (per the...
4
by: Yarco | last post by:
In c++ we could modify the private variable in a class use friend keyword. How could it be done in php? class YourBag { int money; friend class Thief; // friend? };
3
by: Sudhanshu | last post by:
I have a c code that uses "class" as the variable name in a function prototype I want to use this in c++ file How can I use it ? Any ideas Sudhanshu
36
by: Roedy Green | last post by:
The only browser I have encountered that supports <colgroup><col class="behold"></colgroup> to apply a CSS style to a whole column, is Microsoft Internet Explorer. I have been told it SHOULD NOT...
2
by: Hukkky | last post by:
File : NodeList.h //---------------------------------------------------------------------- #ifndef NODELIST_H #define NODELIST_H #include <string> using std::string; template <typename T>...
6
by: Luna Moon | last post by:
Here is a quote from the book: C++ Annotations, I don't understand these sentences, could anybody help me? thanks! As a side effect to this implementation it must be stressed that it is not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.