Re: selective access to different classes



Hi abir,

Lets try to verify my understanding of your question first.
You have a template method operate() which handles a fixed sequence of
operations on data which are transformed by the operations, but not
constructed.. All those operations and the data which are used
in it are set from outsite your SoundDataHolder. Your question
seems to be how to ensure that your operations only modify the data
which are passed to them, while they have readonly access to the other
data in SoundDataHolder. Is this the question ?

Would it be a suggestion to consider your problem a pipes and filters
problem( see Buschman e.a A system of patterns) ? You already divided
the system in a sequence of processing steps and data formats for each
step. Now define the pipes and its connections.

Another suggestion would be to reframe your problem as a state
transition problem(GOF fyi). In that case your predefined state
transitions handle the immutable/mutable problem for you. It all
depends on the state of your data.

Rick


Op 24 Aug 2006 04:26:11 -0700 schreef abirbasak@xxxxxxxxx:

Hi,
I have asked the question in java programmer newsgroup, but I think
it is better suited here, as it is manly related to design pattern.
Hence a repost (with little modification).
Any help is appreciated.

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.

Thus In brief, a singleton class holds the data used by the program
globally.
Operation is performed over the input data's to generate several
intermediate data, by stages through a sequence of operation, and
finally result is obtained. Operations only which allowed, can modify
the data. But any operation is free to access existing data.
Note, making data immutable means nobody can access it. And I can't put
the data in the hierarchy of operator to acces it selectively, as that
is not is-a relationship. I prefer composition model.
My question is,
How to allow such senario will passing data to and fro through a
pattern can be achieved.
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?
(basically the operators take the data from the self, modify and place
them on the self, but also allowed to look what other is there in the
self. Also never, the self GIVES the data to operator or TAKES it from
it! )
The requirement is something like this, but class's can be arranged
any way to better suited the problem. Also a generic non-language
specific solution is good for me (C++, Java C# or any pseudocode is OK)

Thanks for any kind of help.
abir

.



Relevant Pages

  • Re: modify PVA.pl (z/OS and perl-5.8.6)
    ... This contains a sequence of property aliases ('ea' for EastAsianWidth, 'jt' for JoiningType and so on) and their corresponding values. ... I changed the order of propertynames in PVA_abbr_map, but perl -d still continues to follow the original sequence of property names and exits before 'ea' is used. ... I tried to modify PVA.pl manually on the linux box to to see if perl ran with this new sequence, so that the 'ea' case would be picked up before perl -d had a chance to exit. ...
    (perl.beginners)
  • returning final reference
    ... parameters which they modify. ... SoundDataHolder is a singleton, and can return all of its data, and set ... Also note the operator interface knows what data ... Can Java return a const/final reference? ...
    (comp.lang.java.programmer)
  • Re: string upper, string lower, string subthisforthat
    ... Non-modifying sequence operations ... So I read it that the function object cannot modify the sequence ... "25.1 Non-modifying sequence operations". ...
    (alt.comp.lang.learn.c-cpp)
  • selective access to different classes
    ... I have asked the question in java programmer newsgroup, ... operate in turns call each operaion in sequence, passing only those ... parameters which they modify. ... If any other common design pattern exists for this kind of selective ...
    (comp.object)
  • Re: Bizzare lst length problem
    ... and so was casting to a string as a stopgap measure that I then forgot ... def function: ... # modify the sequence ...
    (comp.lang.python)