面向对象开发的核心概念与UML应用

需积分: 9 0 下载量 187 浏览量 更新于2024-07-09 1 收藏 204KB PPT 举报
"软件工程-Chapter06.ppt-综合文档" 在软件工程领域,第六章通常关注对象导向(Object-Oriented, OO)开发的关键概念。本章深入探讨了OO开发的特殊性质,以及如何在需求捕获、系统设计和程序设计中应用这些概念。为了更直观地展示这些理念,内容将利用统一建模语言(Unified Modeling Language, UML)进行阐述。 首先,什么是对象导向?对象导向是一种软件开发方法论,它将问题域和解决方案都组织成一系列离散的对象。这些对象不仅包含数据结构,还包含了行为。对象导向的七个主要特征包括: 1. **身份(Identity)**:每个对象都有其独一无二的标识,使得它们在系统中的状态和交互可以被独立跟踪。 2. **抽象(Abstraction)**:通过提取共同属性和行为,对现实世界的复杂性进行简化,形成类或接口。 3. **分类(Classification)**:对象可以被归类到特定的类别(类),共享相同的属性和操作。 4. **封装(Encapsulation)**:隐藏对象的内部实现细节,只暴露必要的接口供其他对象交互。 5. **继承(Inheritance)**:子类可以继承父类的属性和行为,实现代码重用和结构的层次化。 6. **多态(Polymorphism)**:对象可以有多种形态,即同一种操作可以有不同的实现方式,增强了代码的灵活性和可扩展性。 7. **持久性(Persistence)**:对象的状态能够在程序运行结束后仍然保持,例如数据库存储或文件系统中的数据。 接下来,内容将讨论**用例(Use Cases)**,这是需求分析阶段的重要工具,用于描述系统与用户之间的交互,定义系统的功能需求。通过用例,可以清晰地描绘出系统的主要参与者和他们的目标,有助于确定系统的边界和核心功能。 在**UML**的应用部分,将会介绍如何使用UML的图表(如用例图、类图、序列图等)来表示和改进设计。UML提供了一种标准化的图形表示法,帮助团队成员之间更好地沟通和理解设计意图。通过不同视角审视UML模型,可以发现潜在的设计问题并进行优化。 **面向对象系统设计(OO System Design)**阶段,将涉及到如何根据用例和业务需求来构建类和对象的关系,设计系统的架构。这包括了接口设计、包和组件的划分,以及依赖关系的管理。 **面向对象程序设计(OO Program Design)**则关注如何将系统设计转化为具体的编程实现,包括类的实现、方法的编写以及对象间的协作。 最后,**面向对象度量(OOMeasurement)**是评估和改进设计质量的关键。这可能涉及类的复杂性度量、耦合性和内聚性分析,以及其他有助于提高可维护性和可扩展性的指标。 Chapter06的内容涵盖了对象导向开发的全面视图,从理论基础到实践应用,为软件工程师提供了理解和运用面向对象技术的坚实基础。通过深入学习这一章,读者将能够更好地理解和应用面向对象的原理,以创建高效、可维护的软件系统。

7.main方法参数的使用。阅读下面的代码。 --------程序清单------------------------------------------------------------------------------------------------------------ package chapter06; public class CommandLine { public static void main(String[] args) { if (args.length == 0) { System.out.println("Hello, welcome to Java!"); } else { switch (args[0]) { case "-draw" -> { for (int i = 0; i < 3; i++) { for (int j = i; j < 3; j++) System.out.print("*"); System.out.println(); } } case "-add" -> {// + int sum = 0; for (int i = 1; i < args.length; i++) { int num = Integer.parseInt(args[i]); sum += num; if (i != 1 && num > 0) System.out.print("+"); System.out.print(args[i]); } System.out.println("=" + sum); } default -> { System.out.println("no such command-line option"); } } } } } --------------------------------------------------------------------------------------------------------------------------------- 以下操作都在该类源文件所在的文件夹下。 (a)(2分)编译完该类后,如果在终端通过输入命令“java chapter06.CommandLine -cdl Wenzhou”运行该类,此时main方法的形参args其每个元素的值是什么? (b)(16分)分别通过以下命令运行该程序,其输出结果是什么?请简单说明你的理由(没有理由不给分)。 java chapter06.CommandLine -add 12 31 44 -1 -2 java chapter06.CommandLine -draw java chapter06.CommandLine java chapter06.CommandLine -cdl (c)(2分)在Eclipse里设置运行配置,然后得到(b)中第1条命令运行效果并截图。 答:

2023-05-25 上传

xiazai.py:10:0: C0301: Line too long (130/100) (line-too-long) xiazai.py:29:21: C0303: Trailing whitespace (trailing-whitespace) xiazai.py:30:0: W0311: Bad indentation. Found 10 spaces, expected 12 (bad-indentation) xiazai.py:40:0: C0301: Line too long (103/100) (line-too-long) xiazai.py:41:0: C0301: Line too long (153/100) (line-too-long) xiazai.py:53:0: C0305: Trailing newlines (trailing-newlines) xiazai.py:1:0: C0114: Missing module docstring (missing-module-docstring) xiazai.py:7:0: C0103: Constant name "url" doesn't conform to UPPER_CASE naming style (invalid-name) xiazai.py:13:13: W3101: Missing timeout argument for method 'requests.get' can cause your program to hang indefinitely (missing-timeout) xiazai.py:14:16: I1101: Module 'lxml.etree' has no 'HTML' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) xiazai.py:19:0: C0103: Constant name "num" doesn't conform to UPPER_CASE naming style (invalid-name) xiazai.py:21:4: R1723: Unnecessary "elif" after "break", remove the leading "el" from "elif" (no-else-break) xiazai.py:24:17: W3101: Missing timeout argument for method 'requests.get' can cause your program to hang indefinitely (missing-timeout) xiazai.py:25:20: I1101: Module 'lxml.etree' has no 'HTML' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) xiazai.py:28:8: C0103: Constant name "judge" doesn't conform to UPPER_CASE naming style (invalid-name) xiazai.py:28:31: C0209: Formatting a regular string which could be a f-string (consider-using-f-string) xiazai.py:30:22: C0209: Formatting a regular string which could be a f-string (consider-using-f-string) xiazai.py:31:14: C0209: Formatting a regular string which could be a f-string (consider-using-f-string) xiazai.py:34:8: C0103: Constant name "chapter_num" doesn't conform to UPPER_CASE naming style (invalid-name) xiazai.py:38:29: W3101: Missing timeout argument for method 'requests.get' can cause your program to hang indefinitely (missing-timeout) xiazai.py:39:32: I1101: Module 'lxml.etree' has no 'HTML' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member) xiazai.py:41:22: C0209: Formatting a regular string which could be a f-string (consider-using-f-string) xiazai.py:42:16: C0103: Constant name "all_content" doesn't conform to UPPER_CASE naming style (invalid-name) xiazai.py:44:20: R1713: Consider using str.join(sequence) for concatenating strings from an iterable (consider-using-join) ----------------------------------- Your code has been rated at 5.43/10

2023-07-15 上传