January 16th, 2009, 6:30 am
It seems indeed that multiple constructors are not allowed QuoteComparisons to other object-oriented languagesFor those familiar with other object-oriented languages such as C++ and Java, some of the features found in those languages will be noticeably absent: Multiple constructors cannot be defined. The only method for defining different constructors is to check the number of arguments in the one and only constructor and invoke different behavior based on that clue. In this way one may initialize default values for arguments not specified in the original call. Static properties are handled differently. One can use the persistent keyword to create a static variable in a static function, but there is no concept of a persistent property in the class definition. Member methods require incessant dereferencing. The first argument of each member method is a handle to the class instance, usually called "obj". This might be viewed as the "this" pointer used in C++ and is required for accessing member data in member methods. MATLAB is weakly typed and what method to call is not based on argument signature.So, you have to create a big 'catch-all' constructor with a large number of arguments. Since Matlab is weakly typed I reckon that this is an error-prone trick. Another trick is to define set(arguments) functions after the object has been created.hth//. property 'b' is not initialised!?. in general i would avoid 'obj' if possible (performance, safety)
Last edited by
Cuchulainn on January 15th, 2009, 11:00 pm, edited 1 time in total.