Proper use of private?

BlitzMax Forums/BlitzMax Programming/Proper use of private?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

While I haven't used it yet in BMax I can tell you the best reason (IMO) to use it is this:

Make the fields in your type private and provide accessor methods for them like GetFoo() SetFoo(). The idea behind this is to hide the implementation. So for instance let's say you have a Taxes type and one of the fields is percent:Float, instead of doing

Local answer:Float = total * mytaxes.percent

you would do

Local answer:Float = total * mytaxes.GetPercent()

the upside of this is if for some reason you decide that percent needs to be a calculation instead of just a value you can change the GetPercent method and none of the rest of your code needs to be changed.