Structures are a bad thing?
A book I was reading said this:
Quote:
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 :afrog:-terms. :)
Re: Structures are a bad thing?
dead post alert...
Quote:
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)?
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. :wave: