c# - Why we use inner classes? -
i want ask why need inner classes , why use them ?
know how use inner classes don't know why..
some inner classes exposed publicly (eg map.entry
in java) far exception rather norm.
inner classes are, basically, implementation detail.
for example, swing makes extensive use of inner classes event listeners. without them end polluting global namespace bunch of classes otherwise don't need see (which may make purpose harder determine).
essentially inner classes form of scope. package access hides classes outside package. private inner classes hide class outside class.
inner classes in java substitute lack of function pointers or method delegates (which in c#) or closures. means of passing function function. example, in executor
class have:
void execute(runnable r);
so can pass method in. in c/c++ achieved with:
void execute(void (*run)());
being pointer function.
Comments
Post a Comment