Jessica wrote:

> I have a question regarding the object-oriented issue.

> I understand that a class is a type.

> I have an array class. Now say that

> I want to implement an algorithm A that uses the array class.

> Does it make sense to make a class for the algorithm such as

>

>

> class MyAlg {

> private:

> Array A1;

> Array A2;

> // more data members

>

> public:

> // my functions

> };
I presume that your Array is some kind of container class.

What kinds of elements does your Array contain?

Your description is vague and that's a bad sign.

> Right now I have my algorithm as an interface to the Array class

> (i.e. just a bunch of global functions).
That's just fine and necessary if those functions implement *methods*

that apply to objects of type Array. It might be a good idea

if your "global" functions belonged to a namespace instead.

> The problem is that it gets pretty messy and unorganized

> since there are so many parameters associated with the algorithm.

> Since I now added a GUI for my algorithm, I thought that

> maybe if I wrap my algorithm in a class, the code will be cleaner.

> So in short, my current design is 3-tiered:

>

> GUI -> My algorithm as a set of global functions -> Array class

> implementation

>

> I want to make it into a 2-tier design:

>

> GUI -> My algorithm as a class (with Array contained in this

> class)

>

> Can someone please tell me if this is the right way to do it?

> I am puzzled because it doesn't sound semantically correct --

> since the algorithm is not really a TYPE, but rather a method.

> If I shouldn't define a class for it, what are my alternatives?

> I just don't feel that

> using a bunch of global functions is the way to go.
Suppose that your Array is actually an array of numbers -- a vector.

You probably want a *free* function that can perform

a Direct Discrete Fourier Transform (DDFT) on a complex vector

Array x(n);

Array y = ddft(x);

But you may also want to define DDFT object

that you can apply repeatedly to vectors of a given size

the way that FFTW does (

http://www.fftw.org/).

Array x(n);

DFT ddft(n, -1);

Array y = ddft(x);

Array z = ddft(y);

Matrix decompositions are also a good candidate for this approach.

Take a look at

The C++ Scalar, Vector, Matrix and Tensor Class Library

http://www.netwood.net/~edwin/svmtl/
Visit The Object-Oriented Numerics Page

http://www.oonumerics.org/oon/
for lots more good information