0
点赞
收藏
分享

微信扫一扫

git clone前不加sudo执行时报错:error reading X.509 key or certificate file

鲤鱼打个滚 2024-08-01 阅读 3

学会这套规则,并看完面向对象补全计划文章之后,可以尝试实现任意逻辑的类图了

1.类图的规则

我使用的类图软件: 

类图规则介绍:

UML访问修饰符

UML属性(对应c#的字段与属性两部分)

举例:

UML方法的参数和返回值

举例:

2.举栗子

2.1类

比如我有一个Computer类,有一系列常见的属性与方法,我就可以画出类图

2.2继承

众所周知,电脑按照形态分为很多种,比如:

Desktop Computer,Laptop/Notebook,All-in-One PC

那么就可以画出子类对父类的继承(只举一个栗子):

代码实现:

public class Computer
{
    protected string cpu;
    protected string gpu;
    protected int rom;
    protected int storage;

    protected void UpdateOS()
    {
        // 更新操作系统逻辑
    }

    protected void CheckHardwareStatus()
    {
        // 检查硬件状态逻辑
    }

    protected void InstallSoftware(string software)
    {
        // 安装软件逻辑
    }

    protected void UninstallSoftware(string software)
    {
        // 卸载软件逻辑
    }

    protected void ConnectToNetwork()
    {
        // 连接网络逻辑
    }
}

public class DesktopComputer : Computer
{
    private string CaseType;
    private int MonitorSize;

    private void ReplaceHardware()
    {
        // 更换硬件逻辑
    }

    private void AdjustMonitorSettings()
    {
        // 调整显示器设置逻辑
    }
}

 2.3 接口

举报

相关推荐

0 条评论