Однонаправленные ассоциации
Для создания подобной связи Rose генерирует специальные атрибуты. Естественно, что при подобной ассоциации связь генерируется только для одного класса. При этом Rose генерирует закрытый атрибут (Private). В остальном генерация происходит так же как и в наследовании (связь показывается стрелкой Unidirectional Association). Ниже показана картинка отношения и код, сгенерированный Rose (далее в статье также будет использоваться такой же подход: описание связи, рисунок связи, сгенерированный файл заголовка).
Рис.1
ФАЙЛ NEWSTRING.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%39FD296801A9.cm preserve=no // %X% %Q% %Z% %W% //## end module%39FD296801A9.cm
//## begin module%39FD296801A9.cp preserve=no //## end module%39FD296801A9.cp
//## Module: NewString%39FD296801A9; Pseudo Package specification //## Source file: C:\Program Files\Rational2\Rose\C++\source\NewString.h
#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>%39FD2A2602A7 //## Role: NewString::<the_String>%39FD2A270212 const String * get_the_String () const; void set_the_String (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>%39FD2A2602A7 //## begin NewString::<the_String>%39FD2A270212.role preserve=no public: String { -> RHN} String *the_String; //## end NewString::<the_String>%39FD2A270212.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 String * NewString::get_the_String () const { //## begin NewString::get_the_String%39FD2A270212.get preserve=no return the_String; //## end NewString::get_the_String%39FD2A270212.get } inline void NewString::set_the_String (String * value) { //## begin NewString::set_the_String%39FD2A270212.set preserve=no the_String = value; //## end NewString::set_the_String%39FD2A270212.set } //## begin module%39FD296801A9.epilog preserve=yes //## end module%39FD296801A9.epilog
#endif