method hiding with Private

BlitzMax Forums/BlitzMax Programming/method hiding with Private

someone else, somewhere else on these forums did a posting that i am using pretty successfuly in my own code for hiding fields, which, as an OO person, is my #1 mission.

private methods being next in line ...

the sample i'm including shows how you can make a "Field" private, but provide an accessor for the "Field" as Public, allowing encapsulation of the attribute.

i'm writing this on the fly ... so grain of salt please ...

-- SNIP --

Private

Type TypeImpl extends TypeBase
Field field1:Int
Method GetField1:Int()
Return field1
End Method
End Type

Public

Type TypeBase
Method GetField1() Abstract
End Type

' return abstract type, created as concrete type in function
' the Field should be innaccessible outside of the source file
Function Create:TypeBase()
Return New TypeImpl
End Function

-- END SNIP --