Class properties?
Monkey Forums/Monkey Programming/Class properties?
| ||
Hello, I noticed that "Property" was a reserved keyword in Monkey (though in the documentation, it is spelled "Propery" in the reserved keywords list). Is there good documentation out there on how to utilize class property syntax in Monkey? What's weird to me is that a lot of the built-in containers seem to use getters and setters, whereas certain other features seem to exhibit the properties of... well, a class property. I'm curious about this, because there are times when it is a lot more convenient syntactically to access a method as a property, with different behaviors for getting and setting. There appears to be some use of the keyword sprinkled about various modules, but I'm not sure they work the same way as in the language I'm used to. Thanks in advance to anyone who can clarify any of this :) Edit: For reference, here's how VB.NET handles class properties. (Most properties are read/write, but the example below shows both kinds) Public Class Line Private mstrLine As String Property Line() As String Get Return mstrLine End Get Set(ByVal Value As String) mstrLine = Value End Set End Property ReadOnly Property Length() As Integer Get Return mstrLine.Length End Get End Property End Class |
| ||
Class Foo Private Field bar:String Public Method Bar:String() Property Return bar End Method Bar:Void(bar:String) Property Self.bar = bar End End Function Main:Int() Local f:Foo = New Foo f.Bar = "Hello World!" Print f.Bar Return 0 End I generally define properties with the same name as their corresponding private field, but with a capital letter. Omit either method to make it read-only or write-only. |