{"id":37,"date":"2009-01-06T13:04:54","date_gmt":"2009-01-06T11:04:54","guid":{"rendered":"http:\/\/www.coolbasic.com\/blog\/?p=37"},"modified":"2009-01-06T13:04:54","modified_gmt":"2009-01-06T11:04:54","slug":"properties","status":"publish","type":"post","link":"https:\/\/www.coolbasic.com\/blog\/2009\/01\/06\/properties\/","title":{"rendered":"Properties"},"content":{"rendered":"<p>As a new feature, CoolBasic V3 will support class properties. You may have already seen a hint for property support when I discussed about the String implementation earlier in this blog. Properties work just like any other Public variable, i.e you can access then by using the dot notation, but with a added twist. Normally, when you either assign or read a value from a Public variable nothing else will happen. But with properties you are able to capture this event, and execute your custom code to get the job done. Basically, we&#8217;re talking about old-fashioned way of creating getter and setter -functions. Without properties you&#8217;d have to write these two functions in order to access, say Private variables:<\/p>\n<p><code>MyClass.SetName(\"hello\")<br \/>\nConsole.WriteLine(MyClass.GetName())<\/code><\/p>\n<p>With properties you could do the same in more decent way:<\/p>\n<p><code>MyClass.Name = \"hello\"<br \/>\nConsole.WriteLine(MyClass.Name)<\/code><\/p>\n<p>You still define the getting and setting code within the property structure, but done so they&#8217;re unaccessible from outside. So you have nice little black box of which workings not even the class members know about. There&#8217;s a difference in using the property name than assigning the value to the private variable in question by hand &#8211; even when all the setter does is the assign. There&#8217;s always code involved when accessing property values.<\/p>\n<p>In addition you can define the property as ReadOnly or WriteOnly. By doing this, you protect some data that must not be modifier from outside. One example of a ReadOnly property would be the length of a string. The property returns the value of a Private variable, however this information is related to the actual data within the String class, and should only be updated when this inner data changes. It&#8217;s the only way of keeping such information in sync in a secure way. Now if you come to think about it, constants are ReadOnly, too (except that CoolBasic compiler doesn&#8217;t work like .NET compilers in this regard).<\/p>\n<p>Since properties are really a set of methods, they can be inherited. This also means that things like overriding, are possible. However, at this point in time, I&#8217;m still a bit unsure about one thing called Default property. A property can be defined as Default when you access the object without providing further dot notation. Sound like normal object reference? Well, there&#8217;s a catch. In VB.NET Default properties always need atleast one parameter which means you must include a set of brackets to it. A typical example would be the <code>myVar.Item(index)<\/code> property you could refer to just <code>myVar(index)<\/code>. I don&#8217;t like this because it&#8217;s easy to mix this to a method call. <\/p>\n<p>On the other hand, I would still have to allow parameters for properties because it&#8217;s the only way to implement indexes to them. Like above. If I ever wanted to implement LinkedLists or Lists or any variant, I, in fact, must allow this. There are still lots of questions floating I need to chew on.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a new feature, CoolBasic V3 will support class properties. You may have already seen a hint for property support when I discussed about the String implementation earlier in this blog. Properties work just like any other Public variable, i.e you can access then by using the dot notation, but with a added twist. Normally, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[8,10],"_links":{"self":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/37"}],"collection":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":0,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coolbasic.com\/blog\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}