Ассоциации с ограниченной множественностью
Данный вид ассоциаций представляет логическое продолжение предыдущего типа ассоциаций, но в отличие от него имеет строго ограниченное количество связей (ограничение по диапазону). Рисунок 5 показывает модель подобного взаимоотношения классов
Рис.5
Код получается следующим:
ФАЙЛ STRING.h
//## begin module%1.3%.codegen_version preserve=yes // Read the documentation to learn more about C++ code generator // versioning. //## end module%1.3%.codegen_version
//## begin module%39FD295103B9.cm preserve=no // %X% %Q% %Z% %W% //## end module%39FD295103B9.cm
//## begin module%39FD295103B9.cp preserve=no //## end module%39FD295103B9.cp
//## Module: String%39FD295103B9; Pseudo Package specification //## Source file: C:\Program Files\Rational2\Rose\C++\source\String.h
#ifndef String_h #define String_h 1
//## begin module%39FD295103B9.additionalIncludes preserve=no //## end module%39FD295103B9.additionalIncludes
//## begin module%39FD295103B9.includes preserve=yes //## end module%39FD295103B9.includes
// NewString #include "NewString.h" //## begin module%39FD295103B9.additionalDeclarations preserve=yes //## end module%39FD295103B9.additionalDeclarations
//## begin String%39FD295103B9.preface preserve=yes //## end String%39FD295103B9.preface //## Class: String%39FD295103B9 //## Category: <Top Level> //## Persistence: Transient //## Cardinality/Multiplicity: 1
class String { //## begin String%39FD295103B9.initialDeclarations preserve=yes //## end String%39FD295103B9.initialDeclarations
public: //## Constructors (generated) String();
String(const String &right);
//## Destructor (generated) ~String();
//## Assignment Operation (generated) String & operator=(const String &right);
//## Equality Operations (generated) int operator==(const String &right) const;
int operator!=(const String &right) const;
//## Get and Set Operations for Associations (generated)
//## Association: <unnamed>%39FD300C00A9 //## Role: String::<the_NewString>%39FD300C033E const NewString * get_the_NewString () const; void set_the_NewString (NewString * value);
#ifndef NewString_h #define NewString_h 1
//## begin module%39FD296801A9.additionalIncludes preserve=no //## end module%39FD296801A9.additionalIncludes
//## begin module%39FD296801A9.includes preserve=yes //## end module%39FD296801A9.includes
// String #include "String.h" //## begin module%39FD296801A9.additionalDeclarations preserve=yes //## end module%39FD296801A9.additionalDeclarations
//## begin NewString%39FD296801A9.preface preserve=yes //## end NewString%39FD296801A9.preface
//## Class: NewString%39FD296801A9 //## Category: <Top Level> //## Persistence: Transient //## Cardinality/Multiplicity: n
class NewString { //## begin NewString%39FD296801A9.initialDeclarations preserve=yes //## end NewString%39FD296801A9.initialDeclarations
public: //## Constructors (generated) NewString();
NewString(const NewString &right);
//## Destructor (generated) ~NewString();
//## Assignment Operation (generated) NewString & operator=(const NewString &right);
//## Equality Operations (generated) int operator==(const NewString &right) const;
int operator!=(const NewString &right) const;
//## Get and Set Operations for Associations (generated)
//## Association: <unnamed>%39FD300C00A9 //## Role: NewString::<the_String>%39FD300C0348 const UnboundedSetByReference<String> get_the_String () const; void set_the_String (UnboundedSetByReference<String> value);
// Additional Public Declarations //## begin NewString%39FD296801A9.public preserve=yes //## end NewString%39FD296801A9.public
protected: // Additional Protected Declarations //## begin NewString%39FD296801A9.protected preserve=yes //## end NewString%39FD296801A9.protected
private: // Additional Private Declarations //## begin NewString%39FD296801A9.private preserve=yes //## end NewString%39FD296801A9.private
private: //## implementation // Data Members for Associations //## Association: <unnamed>%39FD300C00A9 //## begin NewString::<the_String>%39FD300C0348.role preserve=no public: String {1 -> nRHN} UnboundedSetByReference<String> the_String; //## end NewString::<the_String>%39FD300C0348.role
// Additional Implementation Declarations //## begin NewString%39FD296801A9.implementation preserve=yes //## end NewString%39FD296801A9.implementation };
//## begin NewString%39FD296801A9.postscript preserve=yes //## end NewString%39FD296801A9.postscript
// Class NewString
//## Get and Set Operations for Associations (inline)
inline const UnboundedSetByReference<String> New-String::get_the_String () const { //## begin NewString::get_the_String%39FD300C0348.get preserve=no return the_String; //## end NewString::get_the_String%39FD300C0348.get }
inline void NewString::set_the_String (UnboundedSetByReference<String> value) { //## begin NewString::set_the_String%39FD300C0348.set preserve=no the_String = value; //## end NewString::set_the_String%39FD300C0348.set }
//## begin module%39FD296801A9.epilog preserve=yes //## end module%39FD296801A9.epilog
#endif
Код специально приведен полностью, чтобы можно было бы оценить размах Rose в плане генерации сложных связей.
Лаконичным завершение данного вида связи можно считать связь один к:. В нашем случае 1 к 6
Рис.6
При этом код будет выглядеть следующим образом
ФАЙЛ NEWSTRING.h
* * *
private: //## implementation // Data Members for Associations
//## Association: <unnamed>%39FD4614028A //## begin NewString::<the_String>%39FD461502A0.role preserve=no public: String {1 -> 6RHN} String *the_String[6];
//## end NewString::<the_String>%39FD461502A0.role
// Additional Implementation Declarations //## begin NewString%39FD296801A9.implementation preserve=yes //## end NewString%39FD296801A9.implementation
* * *
Таким же образом можно сгенерировать любой вид связи. Скажем, разработчику ничего не мешает определить связь 6 к 6 или 10 к 10. Код, сгенерированный системой, при этом будет выглядеть как "положено":