I am looking at the String class in Actionscript 3.0.It has a property called String.length . Internally it's a getter function (or method ?) that returns the length of string. Why can't it be String.getLength() ? Methods can take in 1, 2 or more values...so their significance can be understood. But what significance does property have? As it is, after all, a function only. So, why the categorization into properties? Is it just for adding an overhead botheration to remember that something has been categorized into a property?In other words, as a programmer, how am I helped when I'am told that String.length is a property of the String class when I can't find any method for the same.While writing a program, how would I know what is a property and what is a method?I appreciate having someone shed some light on this.V.
Why categorization into Property and Methods
programming practices;actionscript
String.Length is a read/only property, so it's possibly not the best place to start.Imagine you have a Person class that needs to store a persons full name.In Java, you might create a pair of methods, setName() and getName(), to handle this value. That's two methods, required to handle a single value.It's only convention that links those two methods together. Someone who didn't know the convention - say, someone self taught - might instead write AssignName() and Name() methods. It is, after all, just a convention.By formalising the relationship into something called a property, C# (and other languages) remove the need for developers to know about, and to adhere to, the same convention as everyone else.Once you have the unified property, there are other benefits. For example, you can pass a property as an out or ref parameter if you want, you can't do that with a pair of methods.As you look across other programming languages, there are other examples of this approach to be found.An Interface is just a pure abstract class.A Delegate is just a function as a value.MethodMissing() and dynamic are just ways for a class to allow you to call methods that don't exist.An event is just the way the language supports the Observer pattern.The async and await keywords in C# 5.0 are just another way to write asynchronous code.  Extension Methods are just static methods.Except that all of these things are more than what they are just. They increase the expressiveness of the language involved, allowing better abstractions and more effective code.