对association class的疑问

今天看association class怎么看好像都不是很明白。

摘自UML2.0 in a Nutshell

2.6.6. Association Classes

Often the relationship between two elements isn't a simple structural connection. For example, a football player may be associated with a league by virtue of being on a team. If the association between two elements is complex, you can represent the connection using an association class. An association class is an association that has a name and attributes, like a normal class. You show an association class like a regular class with a dashed line connecting it to the association it represents. Figure 2-29 shows a football player's relationships to a league.

 

Figure 2-29. Example association class

 


When translated into code, relationships with association classes often result in three classes: one for each end of the association and one for the association class itself. There may or may not be a direct link between the association ends; the implementation may require you to traverse through the association class to get to the opposite end of the link. In other words, FootballPlayer may not have a direct reference to FootballLeague but may have a reference to FootballTeam instead. FootballTeam would then have a reference to FootballLeague. How the relationships are constructed is a matter of implementation choices; however, the fundamental concept of an association class is unchanged.

按照我的理解以上例子其实看成是FootballPlayer和FootballTeam的Aggregation relationship和FootballTeam和FootballLeague的Aggregation relationship.只不过用Association Classes可以更好的表达FootballPlayer和FootballLeague的间接关系。但这两种表达方法最后的代码表达应该都是一样的。

[代码表现](我认为)

java 代码
public class FootballPlayer {           public int name;           public int number;                FootballTeam footballTeam;    }  
java 代码
public class FootballTeam {           public String name;           public int numPlayers;           public String homeCity;           Collection<FootballPlayer> footballPlayer;           FootballLeague footballLeague;    }  
java 代码
public class FootballLeague {           public String name;           public int numTeams;           Collection<FootballTeam> footballTeam;    }  

但用together生成的代码和我的想法又不一样

[代码表现](together generation)

java 代码
public class FootballPlayer {           /**        * @model.uin <code>design:node:::hnimszew7l00y4-ezsg1t:-tdsqjuew7kty3j-7fwj74</code>        */       public int name;           /**        * @model.uin <code>design:node:::2plt7ew7l4dei-q4hyxp:-tdsqjuew7kty3j-7fwj74</code>        */       public int number;           /**        * @model.uin <code>design:link:::ieje0rew8ip8hf-3ho9xj:-2urp5jew7l1xaj1vaegh</code>        */       FootballLeague footballLeague;           /**        * @model.uin <code>design:node:::-s99ai1ew7l1xajmc7cgz</code>        */       FootballTeam footballTeam;    }       public class FootballTeam {           /**        * @model.uin <code>design:node:::hnimszew7lak9j-67pmjw:-s99ai1ew7l1xajmc7cgz</code>        */       public String name;           /**        * @model.uin <code>design:node:::hnimszew7lb0vy-dlg5p6:-s99ai1ew7l1xajmc7cgz</code>        */       public int numPlayers;           /**        * @model.uin <code>design:node:::hnimszew7lbej9s8soby:-s99ai1ew7l1xajmc7cgz</code>        */       public String homeCity;           /**        * @model.uin <code>design:link:::ieje0rew8ip4w3-eo406e:-2urp5jew7l1xaj1vaegh</code>        */       FootballPlayer footballPlayer;           /**        * @model.uin <code>design:link:::ieje0rew8ip8hf-3ho9xj:-2urp5jew7l1xaj1vaegh</code>        */       FootballLeague footballLeague;    }       public class FootballLeague {           /**        * @model.uin <code>design:node:::hnimszew7l0j2az6d4si:-tdsqjuew7ku7zj-apfzse</code>        */       public String name;           /**        * @model.uin <code>design:node:::hnimszew7l0vjz-ahe69h:-tdsqjuew7ku7zj-apfzse</code>        */       public int numTeams;           /**        * @model.uin <code>design:link:::ieje0rew8ip4w3-eo406e:-2urp5jew7l1xaj1vaegh</code>        */       Collection<FootballPlayer> footballPlayer;           /**        * @model.uin <code>design:node:::-s99ai1ew7l1xajmc7cgz</code>        */       Collection<FootballTeam> footballTeam;    }  
所以我现在我都不清楚这个association class到底是怎么用的了。假如那位有任何思路请一起讨论下。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值