How do I define static class properties that are accessed without allocating the object?
By object I mean class instance. I would just need constant properties (snippet below) but would also like to know how it would work for non-static properties too. I definetely prefer method 2 over 1 but calling foo.prop1 may create a temporary object tmp of class foo. In detail: The call of prop1 is the made via tmp. After the value of prop1 has been returned, the temporary object tmp is destroyed (deallocated). The described behavior would cause a small but significant load on performance/memory that can accumulate when one uses method 2 a lot or very often.
Method 1 has its own problems, where one is definitely that complicated construction of the member with a function and a persistant variable.
function out = prop1()
prop1_loc = 1;
out = prop1_loc;
prop1 = 1;
prop2 = 2;
x = foo.prop1;