zoukankan      html  css  js  c++  java
  • EA UML 建模——类图

      Enterprise Architect(EA) 是一个功能比较强悍的建模工具,本篇文章仅使用其 UML 建模功能,其他更多功能,可以Google。

      一、简单梳理C#中类与类、类与接口、接口与接口的关系

    一、继承 (子类 : 父类、子接口 : 父接口) Is
    
    子类 : 父类
    abstract class Fruit{}
    class Apple : Fruit{}
    
    子接口 : 父接口
    interface IBase{}
    interface ISon : IBase{}
    
    
    二、实现 (类 : 接口) realse
    class Banna : IBase{}
    class Cana : Fruit,IBase{}
    
    
    三、组合 Has (类中有类,类中有接口,接口中有类,接口中有接口)
    class House
    {
        //构造器中包含
        House(IBase base){}
       // 方法中包含
       void    Invoke(IBase base){}
        //属性中包含
        IBase BaseInter{get{return null;}}
    
       // 包含类
       void Show(Banna b){}
    }
    
    interface ISampleInterface
    {
        // 接口中有接口  
         void Show(IBase base);
    
        // 接口中有类
        void Invoke(House house);
    }
    
    其实组合还可以分为 更细的,这个在OOA&OOD的书上讲的很多,不过我觉得 对C#而言就了解 上面的三种关系足矣
    View Code

      二、下载、安装 EA及部分设置

      我在网上找到汉化新世纪汉化的"Enterprise Architect 8.0.858",及相应注册码打包到百度网盘(http://pan.baidu.com/s/1pJ9JKaZ

      安装过程略

      将默认代码模式设置为 C#,"工具 ==> 选项 ==> 代码工程" 代码工程默认语言改为 C#

      

      三、需要关注的几个ToolBox项目

      

      Class  类

      interface 接口

      标号1Generalize(泛化)就上面讲“继承”关系

      标号2 Compose(组成) 就是上面讲的“组成”关系  

      标号3 Realize(实现)就是上面将的“实现”关系

      四、画类图

      以王翔设计模式书LSP和DIP原则一节的例子为例

      LSP(里氏替换原则):子类可替换父类(实现可替换接口)

      DIP(依赖倒置原则):高层对象与低层对象互补依赖,它们都依赖于抽象(依赖于抽象而非具体)

      类图:

      

      实现代码:

     1 #region[抽象]
     2 public interface IVehicle
     3 {
     4     void Run();
     5 }
     6 #endregion
     7 
     8 #region[低层对象]
     9 public class Bicycle : IVehicle
    10 {
    11 
    12     public void Run()
    13     {
    14         // 自行车的实现
    15     }
    16 }
    17 
    18 public class Train : IVehicle
    19 {
    20     public void Run()
    21     {
    22         // 火车的实现
    23     }
    24 }
    25 #endregion
    26 
    27 #region[高层对象]
    28 public class Client
    29 {
    30     public void ShowAVehicleRun(IVehicle vehicle)
    31     {
    32         vehicle.Run();
    33     }
    34 }
    35 #endregion
    View Code

    具体操作

      操作演示

  • 相关阅读:
    GitLab 介绍
    git 标签
    git 分支
    git 仓库 撤销提交 git reset and 查看本地历史操作 git reflog
    git 仓库 回退功能 git checkout
    python 并发编程 多进程 练习题
    git 命令 查看历史提交 git log
    git 命令 git diff 查看 Git 区域文件的具体改动
    POJ 2608
    POJ 2610
  • 原文地址:https://www.cnblogs.com/Aphasia/p/4147042.html
Copyright © 2011-2022 走看看