Basic question about implementing methods

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Basic question about implementing methods

pwarren
This is probably a very simple question from a beginner! I am rewriting
some methods (from Pascal) for doing various different types of sort and
other data manipulations and have a question about how to implement such
procedures in an object based system.

To take a very simple example, say I want a method to swap two
variables, Swap(A,B), it obviously needs to return (or directly
manipulate) both A and B.

If I implement this as a static method (part of a Class of such
standalone methods which are likely to be wanted in lots of different
places) then I cannot return both A and B from the method unless I pass
them to the method as a single variable containing both values (e.g. an
indexed string). Or have I misunderstood something already?

As I see it the alternative is to create an object that both holds the
data and implements the methods (e.g. say SortableArray) and put any
data that need sorting into that for the manipulation.  

Is this the only/best solution?  If so, presumably there would be
considerable overheads incurred in moving the data into such a structure
and out again do do the sorting.  That problem could be avoided by
having the original data structure contain the sorting methods, but then
they need to be implemented in each type of data object that uses them.
Is this where abstract classes come in?  Could each data structure be
descended from an abstract class that implemented the general sorting
methods?

Well I seem to be well and truly over the limits of my knowledge now ...
so I'd better stop.  Sorry if the questions seem naive but I would
appreciate any advice on the alternative approaches.

Many thanks

Philip Warren

University of Sheffield
UK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>