comp.lang.ada
 help / color / mirror / Atom feed
* Conception problem
@ 1997-05-28  0:00 Nicolas Gautier
  1997-05-29  0:00 ` John Heidelberger
  1997-05-30  0:00 ` Jim shaw
  0 siblings, 2 replies; 5+ messages in thread
From: Nicolas Gautier @ 1997-05-28  0:00 UTC (permalink / raw)



Hello,
Sorry if this mail is a little bit long. This is a question about what is
the best 
way to handle lists where modifications of one element can trigger
modifications
on other elements of the list.

Let us have instances of a class A. TO Each instance of A
 corresponds an instance of class B, which belongs to a list of instances
of objects
of class B(ListOfB). When an 
object A asks to his B to modify itself, the object B modify itself, but
this might have 
consequences on other objects of ListOfB. So, a change on an element of
ListOfB might 
triggers a change on an other element of ListOfB.
Here are two solution to solve the problem. I 'd like to have your opinion
about
which one should be used and why.
Thanks in advance.
 
solution 1 :
A has a reference of an instance of an object of class B. 
Each instance of class B has got data and a reference on the list of all
objects B 
(which is a variable known by all the instances of class B - static
variable in C++)
When A asks his B to modify itself, the object modify its data and then use
the 
static list to modify the others data of the list concerned by the
modification.
in C++, we would have something like:

class A {
B *TheRefOnMyB;

//implementation

*TheRefOnMyB -> modify();
}

class B{
static TheListOfAllB;

// implementation of Modify()
this -> ModifyMyself(); //modify this instance
Modify(TheListOfAllB); // modify the static list
//
}


solution 2:
A knows the structure ListofB that handles objects B  and has a key B_Key
on his
instance of B.
When A has to modify his instance of B, it asks the structure ListOfB to
modify the object
 with the key B_Key and to modify the other elements if they need to be
modified.
in C++, we would have something like :

class A {
ListOfB *TheListOfB;
BKeyType B_key; // Bref is a type defining a key on an object B, this key
is known only by
            // the object ListOfB
...
//implementation
TheListOfB -> Modify (B_Key);

//
}

class ListOfB {
...
//defintion of the list and of the type BKeyType
...
// implementation of modify(B_Key)
this -> ModifyTheElementWithTheKey(BKeyType);
this -> MOdifyTHeOtherElements();
//
}




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1997-06-03  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-28  0:00 Conception problem Nicolas Gautier
1997-05-29  0:00 ` John Heidelberger
1997-05-30  0:00 ` Jim shaw
1997-05-30  0:00   ` Russ McClelland
1997-06-03  0:00   ` Malcolm Macgregor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox