![]() ![]() Make it a function, not a property, if using it has a side effect or returns something random. The value of the property should not change unexpectedly. Again, the good convention is to make it behave like a constant, at least constant for this object instance with this state. The read-only properties are often used to make some field read-only from the outside. The idea is that after M圜lass.MyProperty := 123 the programmer can expect that M圜lass.MyProperty = 123. Do not convert or scale the requested value. Do not reject invalid values silently in the "setter" (raise an exception if you must). The setter function should always set the requested value, such that calling the getter yields it back. This is in fact one of the cool possibilities of a "getter" function. Note that it’s OK for getter to have some invisible side-effect, for example to cache a value of some calculation (known to produce the same results for given instance), to return it faster next time. Using COM interfaces with reference-counting disabled More stuff inside classes and nested classes Callbacks (aka events, aka pointers to functions, aka procedural variables) Containers (lists, dictionaries) using generics How the exceptions are displayed by various libraries Finally (doing things regardless if an exception occurred) Free notification observer (Castle Game Engine) Virtual methods, override and reintroduce Exposing one unit identifiers from another Enumerated and ordinal types and sets and constant-length arrays Testing single expression for multiple values (case) Logical, relational and bit-wise operators ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |