Lack of `outer` keyword makes inner class dup implossible
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Sat Jul 15 01:46:49 PDT 2006
Derek Parnell wrote:
> Ok, assuming that 'nested' and 'inner' are synonymous in this
> discussion, it appears that their main purpose is to provide scope
> limitation. That is, the functionality provided by inner
> classes/functions is restricted to, and there by only relevant to, the
> containing class/function.
>
> I use inner functions this way because I can see their utility, but can
> someone supply a good inner class example? As far as I can see, an
> instance of an inner class only makes sense in the context of its parent
> class and is thus reliant on the 'outer' class for relevancy. I'm having
> trouble visualizing where this might be a Cool Thing(TM).
Simulating multiple inheritance:
class Person {}
interface CompilerWriter { void writeCompiler(); }
interface PersonWithIdeas { void designStuff(); }
class GenericCompilerWriter : CompilerWriter { void writeCompiler() { /*
some basic stuff */ } }
class GenericPersonWithIdeas : PersonWithIdeas { void designStuff() { /*
some basic stuff */ } }
class Walter : Person, CompilerWriter, PersonWithIdeas {
InnerGCW a;
InnerGPWI b;
this() { a = new InnerGCW(); b = new InnerGPWI(); }
void writeCompiler() { a.writeCompiler(); }
void designStuff() { b.designStuff(); }
private class InnerGCW : GenericCompilerWriter { /* super duper
implementation */ }
private class InnerGPWI : GenericPersonWithIdeas { /* great ideas */ }
}
--
Jari-Matti
More information about the Digitalmars-d
mailing list