From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,fb2e75ca89362493,start X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,fb2e75ca89362493,start X-Google-Attributes: gid103376,public X-Google-Thread: 109fba,fb2e75ca89362493,start X-Google-Attributes: gid109fba,public X-Google-Thread: 114809,fb2e75ca89362493,start X-Google-Attributes: gid114809,public From: "Nicolas Gautier" Subject: Conception problem Date: 1997/05/28 Message-ID: <01bc6b91$54b26a60$d19ecec2@beta>#1/1 X-Deja-AN: 244532638 Organization: SCT / Worldnet - Internet Provider & Information Exchange - Paris, France Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.eiffel,comp.lang.smalltalk Date: 1997-05-28T00:00:00+00:00 List-Id: 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(); // }