A Question on VB Classes

G

Guest

I am having trouble finding uderstanding why using a public variable instead
of a property with get and set is bad programming practice. In fact, there
are a lot of properties that don't do anything that requres a get or set and
it's much easier to accumulate these just below the class statement as public
variables as you dont' have to scroll down thru a lot of screens to read the
code.

Each to his own I guess. What's good programming practice to one is not to
another.
 
B

Brian

Thanks rowe and others for your help.

I know the basics of programming in Visual Basic but I want to get a
more deeper understanding of this language.

Regards Brian
 
R

rowe_newsgroups

I am having trouble finding uderstanding why using a public variable instead
of a property with get and set is bad programming practice. In fact, there
are a lot of properties that don't do anything that requres a get or set

In my experience classes tend to "morph" over time. This includes
inheriting the class and overriding various methods. Or adding
overloading versions of properties. Or implementing try catch blocks.
And so on and so on. All of the above examples are common things that
are done with/to classes, and none are possible with with variables.
This is why using properties can make your life (and your fellow
coder's lives) much easier in the long run. It's kind of like the
object orientated programming ideals, it is nothing more than a set of
good ideas. You don't need to use any of them to make good programs,
and in many causes it takes longer to build the program and requires
more code. But in the long run OOP makes things much easier on you,
through code reuse and everything else it offers. I guess you could say
using properties is more conformant to OOP standards than using
variables.
it's much easier to accumulate these just below the class statement as public
variables as you dont' have to scroll down thru a lot of screens to read the
code.

That's what the new outlining feature is for! Besides if you're just
using standard get set property blocks why do you need to read through
the code anyway? I say just type up the property, hit the " - " button
to hide it, and forget it.

Thanks,

Seth Rowe
 
G

GhostInAK

Hello rowe_newsgroups,

Seth is entirely correct in his assesment. I work on medium to large projects
everyday. Properties are a must. The code becomes unmaintainable without
them. The instant you have to add error or bounds checking, data transformations,
or simply causing something to be readonly.. all common things to do with
properties, you've broken your interface. Everyone was hitting Class.Variable...
now.. we add bounds checking, and the business rules say the bounds checking
is manditory.. so now we MUST hide the Variable (since it can't provide the
checks).. now.. that class uses the Variable extensively.. do we rename the
variable, and expose a property of its old name? Or do we leave the variable
and create a property of a new name? Either way somebody's code is gonna
have to change. No. We do things right from the start and anything exposed
through the public interface is done via proeprties, not variables.

-Boo
 
G

GhostInAK

Hello rowe_newsgroups,

Protected is also used for sharing variables with inherited classes.
Nested classes are something to be avoided like the plague.

-Boo
 
R

rowe_newsgroups

Protected is also used for sharing variables with inherited classes.

Thanks for adding that, I left it out of my original post.
Nested classes are something to be avoided like the plague.

I agree, about the only time I nest classes is to create very specific
custom exceptions that don't make sense apart from the "host" class.

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top