zoukankan      html  css  js  c++  java
  • UML中的关联关系

    UML中的关联关系其内在意思就是has a 如图: 
    image

    相对于依赖关系,关联关系在代码中有所体现.上图中的关联关系在代码中体现为 
     

         image     image

    其中water 中将Climate作为其中的属性. 
    当然,关联关系中也有双相关联,如图:

    image

    image image

    关联又分为组合,聚合

    image

    对应的代码如下: 
    image image

    设计模式中的关联关系 
    image

    代码如下:

      1: //工作经历
    
      2:     class WorkExperience
    
      3:     {
    
      4:         private string workDate;
    
      5:         public string WorkDate
    
      6:         {
    
      7:             get { return workDate; }
    
      8:             set { workDate = value; }
    
      9: 
    
     10:         }
    
     11: 
    
     12:         private string company;
    
     13:         public string Company
    
     14:         {
    
     15:             get { return workDate; }
    
     16:             set { workDate = value; }
    
     17:         }
    
     18:     }
    
     19: 
    
     20:     //简历
    
     21:     class Resume : ICloneable
    
     22:     {
    
     23:         private string name;
    
     24:         private string sex;
    
     25:         private string age;
    
     26:         
    
     27:         private WorkExperience work;//组合关系,简历必须有工作经历
    
     28: 
    
     29:         public Resume(string name)
    
     30:         {
    
     31:             this.name = name;
    
     32:             work = new WorkExperience();
    
     33:         }
    
     34: 
    
     35:         //设置个人信息
    
     36:         public void SetPersonInfo(string sex, string age)
    
     37:         {
    
     38:             this.age = age;
    
     39:             this.sex = sex;
    
     40:         }
    
     41: 
    
     42:         //设置个人经历
    
     43:         public void SetWorkExperience(string workDate, string company)
    
     44:         {
    
     45:             work.WorkDate = workDate;
    
     46:             work.Company = company;
    
     47:         }
    
     48:         //显示
    
     49:         public void Display()
    
     50:         {
    
     51:             Console.WriteLine("个人信息");
    
     52: 
    
     53:         }
    
     54:         public object clone()
    
     55:         {
    
     56:             return (Object)this.MemberwiseClone();
    
     57: 
    
     58:         }
    
     59:     }

     转自:http://blog.csdn.net/lsh6688/article/details/6027922

  • 相关阅读:
    localStorage用法
    es6写法
    div滚动条
    搜索框聚焦和失焦
    初步理解前端模块化开发
    clam安装
    div行高不确定,文字和图片居中
    html页面设置<span>的高度和宽度
    一款好用的wangEditor编辑器
    3月23 防360网页的示意图
  • 原文地址:https://www.cnblogs.com/liushui-sky/p/6126019.html
Copyright © 2011-2022 走看看