A Group is formally defined as a set of Element's,
over which a single operator mul is defined.
There are different kinds of Groups,
and each kind requires a different set of parameters.
Operator mul also depends on the parameters.
I'm trying to design an abstraction of this scenario,
where I can use a generic Group and a generic Element,
thereby hiding the details of the group that I'm using.
So far, I have only managed to model the one-to-many relation between a group instance and its elements:
class Element {
public:
Element(Group* group) {
this->group = group;
}
private:
Group* group;
};
class Group {
public:
virtual Element* mul(Element* a, Element* b) = 0;
};
Let's say my Group has another method, namely exp,
that takes element a and exponent n,
and performs mul(mul(...(a, a)...)) (i.e., a^n).
Is it possible to easily abstract away this method?
My main challenge was dealing with memory (de-)allocation,
as the base Group does not know about
the implementation details of Elements,
and I need to also abstract away a lot of memory management.
I would greatly appreciate your corrections to my design as well.