class design question (inner classes) - Of course you can, just use inner classes

Downs default_357-line at yahoo.de
Tue Sep 11 13:31:21 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

coxalan wrote:
> Regan Heath Wrote:
> 
>>  > The class SymmetricGroup
>>> should collect everything that all of its elements (the object of the
>>> class Permutation) have in common.
>> Like .. (list please).  Are they all data members or methods as well.
>  
> Definitely methods, like
> uint order()
> which returns the number of the elements of the group.
> 
> For the SymmetricGroup there are no other data members, but for other Groups there could be arbitrary data members (like a big array where the multiplication results are stored).
> 
>> [...]
>> Ok.  I think I have reached the limit of my usefulness here :)
>>
>> Someone else is bound to have some ideas.
> 
> It was my fear that I put too much technical mathematics stuff into my posting.
> 
> I already put this question (in C++ form) into a mathematical internet forum, but then the  OOP-design part of the discussion got stuck at a very basic level... :-)
> 
> 
> 
> Now I rethought my question and how I can put it on a more abstract level to get out the math part.
> 
> I guess my problem comes down to this point:
> 
> class Outer {
>     class Inner {
>         [...]
>     }
>     [...]
> }
> 
> main() {
>     A a = new A();
>     [... initialize many a.Inner objects here ...]
> }
> 
> Once that "a" is initialized, te reference "a" stays constant all the time. So all further references/pointers to "a" are redundant. Especially, the references to "a" stored in "a.Inner" inner objects are redundant.
> So if there was a way to tell the compiler that the reference a will never change, the compiler could do the optimization and skip all these inner-class-references.
> 
> Now the question is:
> Is there currently a way to achieve a satisfying, equivalent result?
> If not: Should I make this a feature request?
> 
> coxalan

I'm surprised nobody brought this up before.
Yes, of course you can do this.
class Outer {
	class Inner {
		[...]
	}
}

void main() {
	Outer foo=new Outer;
	auto bar=foo.new Inner;
	auto baz=foo.new Inner;
}

That what you want? :)
 --downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG5vsZpEPJRr05fBERAtpiAJ47qu9tffXEr47OsNR3+v89i4JLEwCfU15R
rUPiTTNTUCH/o/lv52Cae2M=
=UmNC
-----END PGP SIGNATURE-----



More information about the Digitalmars-d mailing list