Re: implementation dilema



ma740988@xxxxxxxxx wrote:
Assume a system with three cards. For discussion purposes we'll call
them A B and C. Assume data comes in from an external source to A & B.
A and B computes mean on data and transmits result to C. C performs a
sum on the mean of A and B and transmits _its_ (C's result) result to A
and B. A and B runs an _algorithm_ on the data utilizing the result
from C. A and B sends result from the algorithm to C. A, B and C play
this 'game' (i.e A and B does something send results to C, C does
something send result to A and B and so on ) for say 7 iterations.

Assume pictorially this is akin to:

A & B C
---------------------------------------------------------
mean mean
standard deviation standard deviation
algorithm_ab1 algorithm_c1
algorithm_ab2 algorithm_c2
algorithm_ab3 algorithm_c3
algorithm_ab4 algorithm_c4
algorithm_ab5 algorithm_c5


The question: I'm trying to design a class that'll capture the fact
that the mean and standard deviation are common to 'both' ( code on A
and B is generic, so both here is A/B and C). From there the
algorithms are different.. I'm not sure if I'm missing a design
pattern or .. what's a good way to architect this?
One other thing. Some of the algorithms on both sides is comprised of
FFTs. For instance ( algorithm_ab1/ab2/ab4 is comprised of an FFT,
similarily algorithm_c2/c3/c4 is comprised of an FFT).
Not sure how to put this together nicely to make maintenance easy.


Think: variance encapsulation.

Ask yourself, "What part of this design is changing?" Or more generally, "What concept is varying and how can I encapsulate it?"

The variance would appear to be: the algorithms working on the
data, and the data themselves. (So, pretty much the entire thing,
then.)

Rather than seeing A, B, and C, you should probably have an Algorithm
interface and a Data interface.

The Algorithm interface will be implemented by all the various
alorithms that you use, for example, you'll have a MeanAlgorithm,
StandardDeviationAlgoirthm, FFTAlgorithm, etc. This way, if both
MeanAlgorithm and StandardDeviationAlgoirthm share common behaviour,
then they can inherit from some CommonMeanAlgorithm: all of this will
be hidden to clients, who just see an Algorithm interface. This
strongly suggests a strategy pattern and some sort of factory pattern.

For flexibility, don't hard-code the sequence in
which the algorithms are executed in the algorithms themselves. Instead, you could consider having an AlgorithmSequence, in which is configured at start-up with the algorithms and sequence that you want; you'll thus be able to change this easily as your needs evolve.

So, pseudo-code:

class Configuration {

void start() {
AlgorithmSequence algorithmSequence = new AlgorithmSequence();
algorithmSequence.add(new MeanAlgorithm());
algorithmSequence.add(new StandardDeviationAlgoirthm());
algorithmSequence.add(new FFTAlgorithm());
}
}

class CalculationRun {

void calculate(Data data) {
Configuration configuration = getConfiguration();
AlgorithmSequence algorithmSequence = configuration.getAlgSeq();
int numAlgorithms = algorithmSequence.getNum();
for (int i = 0; i < numAlgorithms; i++) {
Algorithm alg = algorithmSequence.getAlg(i);
data = alg.execute(data);
}
System.out.println("Answer = " + data);
}

Of course, this presumes a uniform interface towards the data.

Actually, it presumes quite a lot ...


--
www.EdmundKirwan.com - Home of The Fractal Class Composition.

Download Fractality, free Java code analyzer:
www.EdmundKirwan.com/servlet/fractal/frac-page130.html
.



Relevant Pages

  • Re: Freeing Algorithms
    ... detail about how the algorithm works, ... is the same shape whatever the power requirements of the ... OTOH, if the hardware interface were as specific as in your example with Years, ... And there's the same tension in the design of hardware interfaces. ...
    (comp.lang.java.programmer)
  • Re: Delegates VS interfaces - some confusion
    ... one member of the interface, whereas with a delegate you can specify ... delegate void Func; ... algorithm not changing at run time and how that makes it intrinsic to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TCP_NODELAY at loopback interface
    ... I expected that the Nagle algorithm would affect connections at the loopback ... Nagle to keep this under all circumstances. ... operations when using the loopback interface but that unless this ...
    (microsoft.public.windowsce.embedded)
  • Re: Strategy Design Pattern
    ... really apply to Python per say, but the idea behind the patterns can be ... think the goal is to abstract out of the class an algorithm that can ... this is quite simple - decide upon an interface that the ... def TakeOff: ...
    (comp.lang.python)
  • Re: Precise Permissive Field of View: Request for comments
    ... that convinced me to use it as a default FOV algorithm in RoguelikeLib:) ... The interface is not yet very swapable, I will work on it with a new version. ... map data structure, it should have a map interface (not necessarily ...
    (rec.games.roguelike.development)