class design question (inner classes)

Regan Heath regan at netmail.co.nz
Tue Sep 11 07:26:09 PDT 2007


> With your code, the uint-value "degree" gets stored once for every
> instance of SGP. This is not what I want. 

Make it "static" or, make it a template parameter and just use that, eg.

class SymmetricGroup
{
}

class Permutation(T, int D) : T
{
          uint data[];

          this() {
              data.length = D;
          }

          this(uint[] dataIn) {
              data = dataIn;
          }

          Permutation opMul(Permutation b) {
		auto result = new Permutation;
		foreach(int i, uint val; b.data) {
		    result.data[i] = data[val] * b.data[val];
		}
		return result;
         }
}

alias Permutation!(SymmetricGroup, 3) SGP;

void main()
{
	SGP a = new SGP();
	SGP b = new SGP();
	SGP c = a * b;
}

 > 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.

Have you considered using mixins to mix a SymmetricGroup template 
containing methods/data members into Permutation.

>> In the above you don't actually need SymmetricGroup at all, your 
>> template could just take "int D" and use that for degree, however I
>>  suspect you want to add more to SymmetricGroup?
> 
> Yes, of course this is only an example which I made as short as
> possible.

Sure, but a short example can make it hard (for us/me) to see the whole 
picture. :)  Especially when my formal maths education stopped at high 
school level.

> There are two reasons for this class [these are the classes of kind
> 1) in my first posting]:
> 
> * I want to implement more kinds of groups, for example also matrix
> groups. All the groups should have a common interface which will be
> used in templated group algorithms. * There are constructions which
> combine two or more groups into a new one. For the implementation of
> such combined groups, It will be very convenient to have classes of
> this kind 1).

Ok.  I think I have reached the limit of my usefulness here :)

Someone else is bound to have some ideas.

Regan



More information about the Digitalmars-d mailing list