Rôles d'association

De Wiki1000

Introduction

Un rôle d'association est une association bidirectionnelle entre deux clases de multiplicité 0..* dans un sens et 0..* dans l'autre.

role-association.png

Un rôle d'association utilise une classe d'association pour maintenir les couples d'objets associés.

Utilisation

  • Accès

Les rôles d'associations ont une propriété Refs[index] permettant d'accéder aux objets associés :

var idx:Integer;
begin
  for idx:=0 to instA.ClassBList.Count-1 do
   begin
     instB := instA.ClassBList.Refs[idx];
     ...
   end;
end;

ils disposent aussi d'une propriété par défaut en lecture seule :

var idx:Integer;
begin
  for idx:=0 to instA.ClassBList.Count-1 do
   begin
     instB := instA.ClassBList[idx];
     ...
   end;
end;

L'accès aux objets de la classe d'association se fait à travers une fonction AssInstance dont le paramètre est l'identifiant de l'objet associé :

var idx:Integer;
begin
  for idx:=0 to instA.ClassBList.Count-1 do
   begin
     instAB := instA.ClassBList.AssInstance(instB.ClassBList[idx].InstanceOID);
     ...
   end;
end;


  • Ajout d'objets dans l'associaton

Différentes manièrs d'ajouter un objet à un rôle liste :

begin
  instA.ClassBList.AdDRef(instA);
  instA.ClassBList.AddOID(instA.InstanceOID);
  ...
end;


Rôles (tech)Développement DSM





Whos here now:   Members 0   Guests 0   Bots & Crawlers 1
 
Outils personnels