知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

    • Java basic

    • Java OOP

    • 应知

    • 扩展

      • Theory:Units of information
      • Theory:IDE
      • Theory:IDEA
      • Theory:Build tools
      • Theory:Operating systems
      • Theory:Gradle basics
      • Theory:Basic project with Gradle
      • Theory:Building apps using Gradle
      • Theory:Dependency management
      • Theory:Formatted output
      • Theory:Libraries
      • Theory:Frameworks
      • Theory:Modules
      • Theory:Introduction to software architecture
      • Theory:Class Diagrams
        • What is a class diagram?
        • Description of a class
        • Description of class relationships
        • Description of association relationships
        • Conclusion
      • Theory:Text blocks
      • Theory:YAML
      • Theory:XML
      • Theory:JSON
    • IO & Stream

    • Error & Exception

    • Algorithm & Data structure

    • Design pattern

    • Web

    • Spring boot

  • 练习题

  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • Hyperskill - Java
  • 扩展
Jim
2022-10-15
目录

Theory:Class Diagrams

When you work on a project, you might need a proper visual representation of a system structure. If you can divide your project into a set of objects and use the Object-Oriented Paradigm (OOP) on it, you can use Class Diagram. It would help you to describe the components of your application and better understand the connections between them.

If you are working on an application that uses OOP, Class Diagram will define your project structure and will make it apparent to the developers.

# What is a class diagram?

In Unified Model Language (UML), Class Diagram is a visual representation of an object-oriented structure. To describe said structure the diagram uses the following elements:

  • Classes;
  • Class attributes;
  • Class methods;
  • Class relationships.

These elements form a set of classes and relationships between them. Such structure provides a better understanding of connections within a system and allows us to easily demonstrate the contents of an object.

# Description of a class

Class is a representation of an object that describes its methods and attributes. Simply put class can be seen as a blueprint for an object. When the system creates a specimen of an object, it will be created according to a template that was described by the class. Here's an example of a class, called "Student":

img

Student has 2 attributes: Name defined by String type, and Age defined by int type. The class also has 2 methods: write() which returns String type and study() which returns nothing. Methods also have brackets that can be filled in with some parameters. In this example, we have the parameter String str that is required to activate method write*()*.

Each element of a class has a visibility option, defined before the name of the element. In this example, all the elements have a "+" before their names. That means that all the visibility options of these elements are set to public. Let's elaborate on these visibility options:

  • + (Public) – element can be accessed by any class in the system;
  • - (Private) – element can be accessed only by a class that owns it;
  • # (Protected) – element can be accessed by classes that have a generalization (or inheritance) relationship with its class;
  • ~ (Package) – element can be accessed by classes that are located in the same package.

# Description of class relationships

Class relationships are a concept that defines connections between classes. For example, we have 2 classes in our applications: Student headman and Teacher. We define their connection by establishing a relationship of some sort. Here's an example:

img

In this example, we use the type of relationship called generalization (or inheritance). Let's elaborate on the relationship types:

  • Generalization (inheritance) – a type of relationship where one class could be described as a child class which assumes and could use methods of a parent class. In our case Student headman is the child class of Teacher. This relationship could be visualized by this arrow below:

img

  • Dependency – a type of relationship that indicates that some change in one class can affect another class. Here's an example of Student depending on School:

img

  • Realization – the relationship between the blueprint class and the object containing its respective implementation level details. For example, we have a class Person which describes the basic attributes of a person. It's a blueprint that can be made into an object that represents a specific person like a Student, or a Salesman. Our Student class can study and go to school, and our Salesman class can go to work and sell stuff, but they are people, so they will have Age and Name attributes. Here's how you could visualize it:

img

# Description of association relationships

Association – a type of relationship that indicates that instances of one class are connected to instances of another. For example, Teacher teaches Student. This relationship can be visualized by a straight line:

img

Association relationships could also include a cardinality attribute. Simply put, this attribute defines the number of instances of a class that could exist in this relationship. Here's how it can be visualized for different situations:

img

A basic example of this concept is this: class Teacher and class Student are connected by an association relationship. It means that Teacher teaches Student. One student can have one or multiple teachers, and the same can be said about teachers. So the diagram that describes this relationship would look like this:

img

Association relationships also have two special types:

  • Aggregation – a special type of association relation that describes one class as a part of the other. Classes in this relation have a separate lifespan. If we come back to our Student example, we can describe class Student as part of a Group. This relation can be represented in this way:

img

  • Composition – a special type of aggregation, where classes share lifespan. If the main class (School) stops its functions, the class that is a part of it (Group) will stop functioning too. This relationship can be visualized like this:

img

# Conclusion

Class Diagram could be seen as too complicated at first. But when you start working on your first project, making your first framework, and connecting all the components into one structure, you may realize that this way of presenting project structure is really helpful. It makes all the application components look more apparent, and it also helps to set boundaries of their contents.

编辑 (opens new window)
#Pattern#Programming
上次更新: 2022/10/25, 17:57:56
Theory:Introduction to software architecture
Theory:Text blocks

← Theory:Introduction to software architecture Theory:Text blocks→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式