Download objects
Transcript
07: Objects - 215 internal call this is a method of a nested/nested class constant is 12 How would you benefit from using a nested class in the Object Pascal language? The concept is commonly used in Java to implement event handler delegates and makes sense in C# where you cannot hide a class inside a unit. In Object Pascal nested classes are the only way you can have a field of the type of another private class (or inner class) without adding it to the global name space and making it globally visible. If the internal class is used only by a method, you can achieve the same effect by declaring the class within the implementation portion of the unit. But if the inner class is referenced in the interface section of the unit (for example because it is used for a field or a parameter), it must be declared in the same interface section and will end up being visible. The trick of declaring such a field of a generic or base type and then casting it to the specific (private) type is much less clean than using a nested class. note In chapter 10 there is a practical example in which nested classes come in handy, namely imple menting a custom iterator for a for in loop. Marco Cantù, Object Pascal Handbook