|
-
May 17th, 2004, 01:45 AM
#1
Structures are a bad thing?
A book I was reading said this:
Structures are frowned upon in object-oriented programming. A class can do everything that a Structure can do—and more—so you should use classes instead of Structures.
Why does it say that structures are frowned upon?
IIRC, we can use property let/get to validate the values that we pass to the structure, so it shouldn't be that, should it?
Is it wrong to assume that creating a class for the sake of a simple structure-type implementation is a waste?
Please explain in -terms.
-
May 17th, 2004, 02:55 AM
#2
Hyperactive Member
I have your same doubt, but I know at least a little difference between them. Class is a reference type, Structure is a value type. It makes a difference when you pass them Byval to a sub. In case of Class it will be affected anyway.
Live long and prosper (Mr. Spock)
-
May 17th, 2004, 04:15 AM
#3
Retired VBF Adm1nistrator
A structure is basically just a collection of properties grouped together.
A class on the other hand is an entirely integral piece of executable code with its own methods, events and properties.
The class is the foundation of object orientated programming.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Dec 5th, 2004, 03:10 AM
#4
Fanatic Member
Re: Structures are a bad thing?
dead post alert...
 Originally Posted by plenderj
A structure is basically just a collection of properties grouped together.
A class on the other hand is an entirely integral piece of executable code with its own methods, events and properties.
The class is the foundation of object orientated programming.
I had the same question and did a search for the topic before posting... something i'm not clear on, structures can have it's own methods, events, and values as well, correct? The IDE doesn't mind when I add Public Sub Foo() to the structure...
My app will be sending data back and fourth through the internet using serialized objects. Might it be more efficient to just use structures instead since none of the objects being sent use inheritance at all (except from Object of course)?
-
Dec 5th, 2004, 06:49 AM
#5
Re: Structures are a bad thing?
You would be able to, most likely, but it would be inefficient I suppose. The struct is value type, class is reference type, so the object would be taken care of by the GC.
Besides, with a structre, you can't do things like Inheriting and I don't believe there is a way to control how the struct is "instantiated" if I may use that term.
It's best to use a struct only as your own data type for your functions or summit.
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
|