|
-
Jan 16th, 2006, 12:21 AM
#1
Thread Starter
Admodistrator
What is the point of a class?
Honestly I see no point to it..I can do the same thing with a UDT and a module without a whole bunch of let + sets..Can anyone give me an advantage here?
-
Jan 16th, 2006, 02:33 AM
#2
Re: What is the point of a class?
- Reusability.
- Variables and methods will work from inside a particular object.
i.e.
VB Code:
Dim MyObject As clsMyClass
Set MyObject = New clsMyClass
MyObject.Prepare(SomeParameterIfYouWant)
MyObject.Process()
MyObject.PrintOut()
Set MyObject = Nothing
- It is true that the same can be achieved with UDTs + modules, but when there is many code involved, it's much easier using classes.
When using many objects It's common to use Collections to store them.
Modules are faster than classes, but when you have many many things to do in a program, it's better to spend some days preparing classes before you start with the entertaining part.
Last edited by jcis; Jan 16th, 2006 at 10:17 PM.
-
Jan 16th, 2006, 04:17 AM
#3
Fanatic Member
Re: What is the point of a class?
Classes help describe real world objects.
-
Jan 16th, 2006, 04:41 AM
#4
Re: What is the point of a class?
Class is the blueprint for objects...
-
Jan 16th, 2006, 05:04 AM
#5
Re: What is the point of a class?
Creating more instances of one object!
-
Jan 16th, 2006, 06:00 AM
#6
Re: What is the point of a class?
 Originally Posted by jcis
- Reusability.
To my mind, this is the purpose of a class module. Project specific code can, and should, be dealt with in a .bas module, or a UDT or some other project specific form. Code in a class module is code that can be used across multiple projects, and can be use across multiple projects by mutliple programmers.
-
Jan 16th, 2006, 01:26 PM
#7
Thread Starter
Admodistrator
Re: What is the point of a class?
Okay, so really I have no uses for it then. Thankyou guys
-
Jan 16th, 2006, 02:04 PM
#8
Re: What is the point of a class?
The best reason to use classes that I can think of is to have different distinct types that use a common interface. For example, if you have to deal with a group of students, you could create a student interface that is implemented by different types of students (ie underclass, graduate, audit). All of these might share a common .AddClass method, but say audit students get charged half tuition, underclass have to check for pre-requisites, etc. Given a collection of student objects, each one would be able to be processed with the same generic code.
Another reason is to enforce data integrity. A class should only allow access to it's data through it's interface, and this lets you control referational integrity. Let's say you have an SafeArray class with an element size property, a number of elements property, and a datasize property. Changes to any of these properties will effect the others. It also lets you easily validate data, as you can force a validation any time a property changes. If you combine these two ideas, it makes it a lot easier to check data who's acceptable values vary with other variables.
Finally, classes are the only way to implement event driven programs.
Last edited by Comintern; Jan 16th, 2006 at 02:06 PM.
Reason: typos
-
Jan 16th, 2006, 02:25 PM
#9
Re: What is the point of a class?
If you move to the dark side (.Net) you will see that classes become much much more useable, Vb 6 was week when it came to clases they were pretty slow if I remmber correctly.
Classes are awsome, for orginising code etc!
-
Jan 16th, 2006, 02:32 PM
#10
Re: What is the point of a class?
 Originally Posted by Comintern
...Finally, classes are the only way to implement event driven programs.
Where did you get that idea from?
-
Jan 16th, 2006, 02:35 PM
#11
Re: What is the point of a class?
 Originally Posted by Pino
If you move to the dark side (.Net) you will see that classes become much much more useable, Vb 6 was week when it came to clases they were pretty slow if I remmber correctly.
Classes are awsome, for orginising code etc!
@Pino,
Please do not start another religious war - there is one already in VB.Net forum. Your current answer shows your weekness. Sorry.
-
Jan 16th, 2006, 02:36 PM
#12
Re: What is the point of a class?
 Originally Posted by nkad
Classes help describe real world objects.
I wonder how?
-
Jan 16th, 2006, 02:37 PM
#13
Re: What is the point of a class?
 Originally Posted by RhinoBull
@Pino,
Please do not start another religious war - there is one already in VB.Net forum. Your current answer shows your weekness. Sorry.
@Rhino,
Is it not true that classes in vb6 are slow?
-
Jan 16th, 2006, 02:40 PM
#14
Re: What is the point of a class?
 Originally Posted by RhinoBull
Where did you get that idea from? 
Got it from the fact that you can only raise an event from an object module.
-
Jan 16th, 2006, 02:41 PM
#15
Re: What is the point of a class?
They are even slower in .Net so please I insist that if you want to continue arguments then do not mention VB.Net anymore.
-
Jan 16th, 2006, 02:44 PM
#16
Re: What is the point of a class?
 Originally Posted by Comintern
Got it from the fact that you can only raise an event from an object module.
You've got to be kidding me - VB since its first releases is an EVENT driven language and that's how it was designed - objects respond to events that could be trapped. What you reffer is simply a custom events that could be added to some objects.
-
Jan 16th, 2006, 02:45 PM
#17
Re: What is the point of a class?
Well seriously i'm interested to know since the subject is clasess, I didnt relise they were slower in .Net? Is there any test on this I could read?
I know classes have become a lot more 'used' in .Net
Be interesting to see non-theless
-
Jan 16th, 2006, 02:56 PM
#18
Re: What is the point of a class?
 Originally Posted by RhinoBull
They are even slower in .Net so please I insist that if you want to continue arguments then do not mention VB.Net anymore.
RhinoBull, you cannot compare classes in VB6 to classes in .net. VB6 does not have real classes, not by ANY stretch of the imagination. They don't even remotely count as objects either.
Admittedly, .NET wouldn't win the 100 metres OOP sprint (not with C++ hogging the track), but VB6 wouldn't even get into the qualifying rounds. VB6 is so archaic its not even funny any more. So please don't pretend that VB6 is somehow better simply because you have a fondness for VB6. Pino has much VB6 experience and is learning .net at a geometric rate, he knows more about it than you do so just shut up.
I don't live here any more.
-
Jan 16th, 2006, 02:57 PM
#19
Re: What is the point of a class?
 Originally Posted by RhinoBull
You've got to be kidding me - VB since its first releases is an EVENT driven language and that's how it was designed - objects respond to events that could be trapped. What you reffer is simply a custom events that could be added to some objects.
No, actually I'm not kidding you. Do you actually think there is some real distinction between the events that VB has built into it's objects and custom events programmed into custom objects? A form is just a class with some baggage attached to it. If you have some sample code that is event driven with only modules in it, I'd be delighted to see it.
 Originally Posted by RhinoBull
@Pino,
Please do not start another religious war - there is one already in VB.Net forum. Your current answer shows your weekness. Sorry.
Religious wars tend to get started by self-righteous idiots, and I think your general attitude on this thread would show your weakness.
-
Jan 16th, 2006, 03:02 PM
#20
Re: What is the point of a class?
Sorry Pino but I am not upto benchmarking at the moment.
-
Jan 16th, 2006, 03:17 PM
#21
Re: What is the point of a class?
 Originally Posted by RhinoBull
Sorry Pino but I am not upto benchmarking at the moment.
...or indeed justifying your argument.
I don't live here any more.
-
Jan 16th, 2006, 03:17 PM
#22
Re: What is the point of a class?
@Comintern:
I'd be carefull in using strong expressions if I was you.
-
Jan 16th, 2006, 03:18 PM
#23
Re: What is the point of a class?
 Originally Posted by RhinoBull
@Comintern:
I'd be carefull in using strong expressions if I was you.
Dude, are you drunk?
-
Jan 16th, 2006, 03:20 PM
#24
Re: What is the point of a class?
 Originally Posted by wossname
RhinoBull, you cannot compare classes in VB6 to classes in .net. VB6 does not have real classes, not by ANY stretch of the imagination. They don't even remotely count as objects either.
Admittedly, .NET wouldn't win the 100 metres OOP sprint (not with C++ hogging the track), but VB6 wouldn't even get into the qualifying rounds. VB6 is so archaic its not even funny any more. So please don't pretend that VB6 is somehow better simply because you have a fondness for VB6. Pino has much VB6 experience and is learning .net at a geometric rate, he knows more about it than you do so just shut up.
This is not a chit-chat wossy and this not amusing. I would expect apologies from you.
-
Jan 16th, 2006, 03:49 PM
#25
Re: What is the point of a class?
We have a VB6 "general maintenance program" that allows us to build entry forms at run time from tables in SQL. We did all this work with ARRAY's and UDT's and function/subs in a MODULE.
It was a huge mistake - that we continue to pay for.
First - enhancing the program is a nightmare - adding columns to an array to store new information about behaviour.
Second - it's an MDI app - so each child form has an entry in the array's...
It would have been so much easier to use a CLASS - and creating a new occurrance of the object for each child form.
The SET/GET part makes so much sense now - you can validate and put all kinds of business logic in the property code.
We are now doing a "report writer user interface" in VB.Net and fully embracing the class concept. Writing up a property to get and set a value might take a bit of time - but it's a really, really good way to organize a large program that will have a future of enhancing.
I've always supported black-box concepts - creating functions to hide logic from the main code. A class is just a really clean way to achieve that goal and a whole lot more.
-
Jan 16th, 2006, 04:36 PM
#26
Thread Starter
Admodistrator
Re: What is the point of a class?
Okay let me put my project, can you tell me if I would need a class for it?
I have a UDT Named person:
[Example]
VB Code:
Public Type Person
FName as string
LName as string
Address as string
Town as string
End Type
Okay, and now I have another type:
VB Code:
Public Type Location
Hemisphere as string
Country as string
X as long
Y as long
End Type
VB Code:
Dim tPerson as Person
Dim tLocation as Location
So in my form, I send some of the info in a strange order to my server
VB Code:
With winsock1
.senddata tPerson.FName & tPserson.LName & Chr(0) & tPerson.Address & chr(0) & tLocation.Country
End with
I fill in the value with previous winsock requests/sends..Is there reason to use a class? I have some other UDT's with permanent values also that I send in some winsocks also.
Is this reason enough to use a class or should I stick with the UDT + other code?
-
Jan 16th, 2006, 04:46 PM
#27
Re: What is the point of a class?
UDT can only hold variables a class can hold routines.
If people was a class you could do somthing like
Dim People as New ClassPeople
msgbox people.find("John")
You dont need a class for anything you should just use it when you need it 
Pino
-
Jan 16th, 2006, 04:50 PM
#28
Re: What is the point of a class?
If you want to enforce any rules on the data (such as Hemisphere must be "North" or "South", and LName must be at least 2 characters) then classes are a good way to do it.
If you are only storing data (and dont care what values are stored) then use of a class is a matter of opinion - mine is that it would be OTT, and that a UDT is better.
-
Jan 16th, 2006, 05:51 PM
#29
Re: What is the point of a class?
 Originally Posted by Hack
To my mind, this is the purpose of a class module. Project specific code can, and should, be dealt with in a .bas module, or a UDT or some other project specific form. Code in a class module is code that can be used across multiple projects, and can be use across multiple projects by mutliple programmers.
Believe it or not, Hack, I have regular .bas modules that are typically reuseable. It all depends on what you are coding really, in my case, games.
-
Jan 16th, 2006, 06:10 PM
#30
Re: What is the point of a class?
 Originally Posted by Pino
@Rhino,
Is it not true that classes in vb6 are slow?
Based on many performance tests that I have done, yes they are slow. Here's the order from fastest to slowest that code is executed:
.bas modules
.frm form modules
.cls class modules
That's why I typically use regular modules in my projects cause the code is executed so fast. And some of them are even reusable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|