Re: recommendations to 'hold data'
Jeremy Watts wrote:
I am working on a Java GUI that basically allows a user to carry out
various functions & operations associated with 'linear algebra' - so
matrix calculations,finding eigenvalues, solving systems of equations,
that sort of thing.
Now,at the moment I am working on the 'main' GUI window. It has various
buttons on it, allowing the user to do amongst other things 'declare a
matrix'. Upon declaring a matrix, then another small GUI window opens
allowing the user to enter his/her matrix details, this information then
is then stored (after being parsed) in a 'String' array.
At various times, other classes are going to want access to this stored
information, and I have been wondering how to go about this. Is this
what Java Files are for? I've been trying to find out exactly what
these things are about but I'm having trouble cutting through the
jargon...
Upon closing the 'main' GUI window, then no the data does not need to then
persist. As for the other smaller GUI window that pops up when the user
wants to enter a matrix, then yes obviously it would need to persist upon
closing that window.
The amount of data generated will be fairly small, but I just wondered if
this was a convenient way of doing this.
A number of regulars here have sites or articles online that help get you
started, for example,
<http://mindprod.com/jgloss/gettingstarted.html>
<http://home.earthlink.net/~patricia_shanahan/beginner.html>
I shall essay to highlight what I think you might be facing, and you tell me
where I am mistaken.
John B. Matthews wrote:
While you program is running it's much easier to
pass around a reference to your data model,
which contains the matrix elements in
whatever internal format you chose.
In your case, it sounds like you are trying to model some kind of object that
represents a 'Matrix', which has attributes of dimensionality and an array of
values that fill it. Such a 'Matrix' type would have behaviors like finding
eigenvalues, performing dot or matrix products, scaling by a constant, that
sort of thing.
Object-oriented analysis and programming would have you analyze that type for
its fundamental attributes and behaviors. Define the attributes as accessor
and mutator methods, or informally, "getters" and "setters". Identify the
concepts as attributes of the type. Some of these attributes may have
subattributes, such as the "i" and "j" coordinates of a matrix element.
Add behaviors to that class, such as 'calculateEigenvalue()' or 'dotProduct(
Matrix other )'.
I'm purposely giving these concepts names that a Java interface might use to
define the type. A crude first cut at such an interface for a two-dimensional
matrix might look like this (but probably more complete and better):
public interface Matrix2D
{
public double [] [] getValues();
public double dotProduct( Matrix2D multiplicand );
public Matrix2D crossProduct( Matrix2D multiplicand );
// and so on
}
The Java tutorial briefly outlines how to create a class that has a
constructor. I left off 'setFoo( Foo f )' methods, so the constructor has to
do that job. For reasons I won't go into, I want to make the member variables
of that class 'final' so they can't be altered after the constructor. This
makes instances "immutable" and thread safe. Thread safety is a good thing to
have in a matrix implementation.
Of course, all this is likely moot in the specific case of a matrix class or
library. I'd look for a good free and/or open-source implementation already
proofed and workable.
--
Lew