Assigning "Actions" to objects
<p>I'm developing a library in which I have two groups of classes:</p>

<p>A) a couple of classes with a bunch of functions, or "actions", already written in code</p>

<p>B) a few classes which must be "configured" when instantiated, in a way that the user using my library can instantiate objects from this second group of classes and "assign" actions from the first group</p>

<p>Right now I'm using delegates, like this:</p>

<p>Somwhere in the code I declare some delegates that are used by A and B:</p>

<pre><code>public delegate void Action03(int value);
</code></pre>

<p>Then I have the "actions" implemented in the group A:</p>

<pre><code>public Delegates.Action03 DoSomething03 = delegate(int value) { [code to execute when this action is specified on the constructor] };
</code></pre>

<p>And finally we use constructors like the following to instantiate objects from group B, where we pass as arguments the delegates/actions that we want:</p>

<pre><code>public SomethingGroupB(Delegates.Action03 act03) { ... }
</code></pre>

<p>So of course, we can instantiate objects passing delegates as arguments:</p>

<pre><code>SomethingGroupB somthg1 = new SomethingGroupB(GrpA01.DoSomething03);
</code></pre>

<p>But the whole point is that we can instantiate similar objects but assigning different actions:</p>

<pre><code>SomethingGroupB somthg2 = new SomethingGroupB(GrpA07.DoSomething03);
SomethingGroupB somthg3 = new SomethingGroupB(GrpA01.DoSomething01);
SomethingGroupB somthg4 = new SomethingGroupB(GrpA02.DoWhatever);
</code></pre>

<p>So... as a summary, I want to have pre-coded (in my library) actions, and the user must choose the actions assigned to a new object when it is instantiated, and those actions don't change.</p>

<p>I guess I could also do it with events, but I don't need to add and remove "actions", they are fixed for the whole life of each object of type B.</p>

<p>So my question is: is there a better, nicer, cleaner solution than this one I've implemented with delegates?</p>

<p>Thank you very much!</p>
