returning final reference

T

toton

Hi,
I have a class which holds different objects and gives selective
access to different operations on this according to interface
specified. All the other operations can use it, but no modification
except those who are allowed. To demonstrate, I am having an example
like below,

public class SoundDataHolder{
private://data
RawSoundData _rawData;
FilteredSoundData _filteredData;
QuantizedData _qData;
...
private: //operators
IDataCollector _dataColector;
IGenericFilter _filter;
IQuantizer _quantizer;
....
public:
void operate() {...}
}
now one can set different concrete class for all of the operators. &
call operate.
operate in turns call each operaion in sequence, passing only those
parameters which they modify. (passing all of the data will be
difficult as it is a long list of data which they use).
now, IDataCollector can modify RawSoundData, thus its operate signature
is void operate(DawSoundData data); while IGenericFilter may have a
operator as, operate(FilteredSoundData) , but it uses RawSoundData
also. Note , none of the data (they are collections) are created by the
operator, they pre-exists, and created by some other classes, gets
recycled, The operators only set the contents of the container.
SoundDataHolder is a singleton, and can return all of its data, and set
all of the operators, and call operate on it.
I want to return all data as const/final reference thus any operator
can use it, but the operator's parameter will take only the data which
it needs to modify. Also note the operator interface knows what data
they are modifying, thus I can put them on the operate method call. But
what data they need for this operation is not known also to the
interface. They are free to take any data from the SoundDataHolder
singleton, but not allowed to modify.

In C++ I was doing this returning all data from SoundDataHolder as
const reference, thus any non const member was not allowed to invoke
(eg any setter methods)
while I was passing a non const reference to the operators which needs
to modify it.

My question is,
1) Can Java return a const/final reference ? or declare a final method
? How? Will the C++ scheme will work in that case?
2) If any other common design pattern exists for this kind of selective
access? Any other way to do it (need good secure programming) ? Can you
refer any book/ website having an example?
Thanks for any kind of help.
(I had asked same kind of question previously in the newsgroup, got
many valuable suggestions. But at that time the example was somewhat
misleading. Some suggestion was on inner class, but now I find that it
not works exactly in my case. Now looking for a geneic solution, based
on a good design)

Thanks again,
abir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,265
Messages
2,571,069
Members
48,771
Latest member
ElysaD

Latest Threads

Top