”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 面向对象设计注意事项|部分-

面向对象设计注意事项|部分-

发布于2024-07-31
浏览:179

Part 1 - Object-Oriented Analysis and Design

1. Object-Oriented Thinking

Object-oriented thinking is fundamental for object-oriented modelling, which is a core aspect of this post. It involves understanding problems and concepts by decomposing them into component parts and considering these parts as objects.

  • Definition: Object-oriented thinking means viewing various elements as discrete objects. For example, in a software system, a tweet, a user, or a product can be viewed as objects.
  • Attributes and Behaviours:
    • Attributes: Properties or characteristics of an object (e.g., a person's name, age, height).
    • Behaviours: Actions that an object can perform (e.g., a device powering on or off, a user logging in).
  • Benefits:
    • Organization: Objects encapsulate both data and behaviour, keeping related details and functions together.
    • Flexibility: Changes to an object’s attributes or behaviours can be made independently of other objects.
    • Reusability: Objects can be reused across different parts of a program or even in different programs, reducing the amount of code that needs to be written and maintained.

2. Design in the Software Process

The design phase is critical in the software development lifecycle. It ensures that the final product meets user requirements and functions as intended.

  • Software Development Process: The software development process is iterative and involves several key stages:
    1. Requirements Gathering: Understanding what the client or user needs from the software.
    2. Conceptual Design: Developing high-level design outlines and mock-ups.
    3. Technical Design: Creating detailed specifications for each component.
    4. Implementation: Writing the actual code based on the designs.
    5. Testing: Verifying that the software works correctly and meets requirements.
    6. Deployment: Releasing the software for use.
    7. Maintenance: Ongoing updates and bug fixes.
  • Importance of Design: Skipping or inadequately addressing design phases can lead to project failure. A solid design foundation ensures that the software development starts on the right track and reduces the risk of costly changes later on.

3. Requirements

Requirements gathering is the foundation of a successful project. It involves understanding what the client or user needs from the software.

  • Definition: Requirements are the conditions or capabilities that the software must satisfy.
  • Elicitation:
    • Client Interviews: Direct discussions with the client to understand their vision and needs.
    • Questionnaires and Surveys: Collecting structured information from potential users or stakeholders.
    • Observation: Watching how users interact with current systems to identify needs and pain points.
    • Workshops: Collaborative sessions with stakeholders to gather and prioritize requirements.
  • Trade-offs: Clients may need to balance different needs and constraints. For instance, they might need to choose between more features or faster delivery.

Example: When designing a house, the architect gathers requirements by asking detailed questions about the homeowner’s preferences for room sizes, placements, and specific features. This helps prevent costly changes during construction.

4. Design

Design in software development involves creating both conceptual and technical blueprints that guide the implementation phase.

  • Conceptual Design:
    • Definition: High-level outline of the software’s major components and their responsibilities.
    • Mock-ups and Wireframes: Visual representations that help stakeholders understand and approve the design before detailed work begins.
    • Responsibilities: Defining what each component of the software is supposed to do.
    • Examples:
    • Mock-ups: Visual layouts of user interfaces showing how screens will look and function.
    • Wireframes: Simple sketches or diagrams showing the layout of components without detailed design elements.
    • Importance: Ensures all stakeholders have a clear understanding and agreement on the high-level structure of the software.

Example: In building a house, the conceptual design outlines the general layout of rooms and their connections but does not yet detail the plumbing or wiring.

  • Technical Design:
    • Definition: Detailed specifications of each component, including how they will be built and interact.
    • Technical Diagrams: Detailed drawings showing how components fit together and how data flows between them.
    • Breakdown of Components: Further decomposing high-level components into smaller, manageable parts until each can be implemented.
    • Examples:
    • Class Diagrams: Show the structure of classes, their attributes, methods, and relationships.
    • Sequence Diagrams: Illustrate how objects interact in a particular sequence of events.
    • Component Diagrams: Depict the organization and dependencies among components.
    • Importance: Provides developers with the detailed information they need to write code effectively and ensures consistency across the development team.

Example: In house construction, the technical design specifies the exact materials for walls, floors, and roofs, as well as the detailed plans for plumbing and electrical systems.

5. Compromise in Requirements and Design

Throughout the design process, compromises are often necessary to balance client needs and project constraints.

  • Communication: Constant feedback loops with clients are essential to ensure the design remains aligned with their vision and constraints.
    • Iterative Reviews: Regularly reviewing and refining designs with client input.
    • Prototyping: Building early versions of components to test and validate ideas with clients.
  • Reworking: Both conceptual and technical designs may need to be revised if they do not meet requirements or prove unfeasible.
    • Flexibility: Being open to changes and adjustments as new information emerges or as requirements evolve.
    • Impact Analysis: Evaluating the potential impact of changes on the overall project to make informed decisions.

Example: If a client wants an open kitchen but structural needs require a supporting beam, the architect and client must find a compromise that maintains structural integrity while satisfying the client’s aesthetic preferences.

6. Design for Quality Attributes

Designing software involves balancing various quality attributes to meet both functional and non-functional requirements.

  • Quality Attributes: Characteristics that affect the performance, usability, and maintainability of software.
    • Performance: How fast and efficiently the software performs its tasks.
    • Security: Measures taken to protect the software from threats and vulnerabilities.
    • Scalability: The ability of the software to handle increased load or usage.
    • Maintainability: How easily the software can be updated or modified.
    • Usability: The ease with which users can learn and use the software.
  • Trade-offs: Balancing these attributes often involves trade-offs, as optimizing for one attribute can affect others.
    • Performance vs. Security: Enhancing security measures can sometimes slow down performance.
    • Scalability vs. Usability: Adding features to improve scalability might complicate the user interface.
  • Context: The specific context of the software influences how these attributes are balanced.
    • Critical Systems: Prioritize reliability and security over other attributes.
    • Consumer Applications: Emphasize usability and performance to enhance user satisfaction.

Example: When designing a front door, balancing security (sturdy locks) with convenience (ease of access) is crucial. Too many locks make the door secure but inconvenient, while too few locks make it convenient but less secure.

7. Class Responsibility Collaborator (CRC) Cards

CRC card

CRC cards are a tool used to identify and organize classes, their responsibilities, and collaborators in the design process.

  • Definition: CRC cards help in visualizing and organizing the responsibilities of different classes and how they interact with each other.
    • Class: Represents an object or concept in the system.
    • Responsibility: Defines what the class knows and does.
    • Collaborator: Other classes with which the class interacts.
  • Usage:
    • Brainstorming: Helps teams brainstorm and identify necessary classes and their roles.
    • Design Sessions: Facilitates discussions about class responsibilities and interactions.
    • Documentation: Serves as a documentation tool to capture design decisions.
  • Process:
    • Identify Classes: List all potential classes involved in the system.
    • Define Responsibilities: Write down the main responsibilities of each class.
    • Identify Collaborators: Determine which classes each class needs to interact with to fulfil its responsibilities.
  • Benefits:
    • Clarity: Provides a clear and concise way to organize and communicate design ideas.
    • Flexibility: Easy to update and modify as the design evolves.
    • Collaboration: Enhances team collaboration by making it easy to discuss and refine design decisions.

Example: In a banking application, a CRC card for the "Account" class might list responsibilities like "manage balance" and "track transactions," with collaborators like "Customer" and "Transaction" classes.

8. Prototyping and Simulation

Prototyping and simulation techniques are used to test and refine designs early in the process, helping to identify and fix issues before full-scale development.

  • Prototyping:
    • Low-Fidelity Prototypes: Simple, rough versions of the software or specific components, often created with paper or basic digital tools.
    • High-Fidelity Prototypes: More detailed and interactive versions that closely resemble the final product.
    • Purpose: Validate design concepts, gather user feedback, and identify usability issues.
    • Methods:
    • Paper Prototyping: Creating hand-drawn sketches of user interfaces and interactions.
    • Digital Prototyping: Using software tools to create interactive mock-ups and simulations.
  • Simulation:
    • Definition: Running models to test the behaviour and performance of a design under various conditions.
    • Use Cases: Evaluating system performance, load testing, and validating design decisions.
    • Benefits:
    • Early Validation: Identifies potential issues before full-scale development.
    • Cost-Effective: Reduces the risk of costly changes by addressing issues early.
    • User Feedback: Allows users to interact with the prototype and provide feedback on functionality and usability.
    • Tools: Various software tools and platforms are available for creating prototypes and running simulations.

Example: Before finalizing the design of a house, an architect might build a small-scale model or use software simulations to visualize the layout and identify potential issues with space utilization and design.

版本声明 本文转载于:https://dev.to/anshulanand/object-oriented-design-part-13-4nb1?1如有侵犯,请联系[email protected]删除
最新教程 更多>
  • Java中假唤醒真的会发生吗?
    Java中假唤醒真的会发生吗?
    在Java中的浪费唤醒:真实性或神话?在Java同步中伪装唤醒的概念已经是讨论的主题。尽管存在这种行为的潜力,但问题仍然存在:它们实际上是在实践中发生的吗? Linux的唤醒机制根据Wikipedia关于伪造唤醒的文章,linux实现了pthread_cond_wait()功能的Linux实现,利用...
    编程 发布于2025-07-16
  • 如何限制动态大小的父元素中元素的滚动范围?
    如何限制动态大小的父元素中元素的滚动范围?
    在交互式接口中实现垂直滚动元素的CSS高度限制问题:考虑一个布局,其中我们具有与用户垂直滚动一起移动的可滚动地图div,同时与固定的固定sidebar保持一致。但是,地图的滚动无限期扩展,超过了视口的高度,阻止用户访问页面页脚。$("#map").css({ marginT...
    编程 发布于2025-07-16
  • 如何使用FormData()处理多个文件上传?
    如何使用FormData()处理多个文件上传?
    )处理多个文件输入时,通常需要处理多个文件上传时,通常是必要的。 The fd.append("fileToUpload[]", files[x]); method can be used for this purpose, allowing you to send multi...
    编程 发布于2025-07-16
  • 为什么使用固定定位时,为什么具有100%网格板柱的网格超越身体?
    为什么使用固定定位时,为什么具有100%网格板柱的网格超越身体?
    网格超过身体,用100%grid-template-columns 为什么在grid-template-colms中具有100%的显示器,当位置设置为设置的位置时,grid-template-colly修复了?问题: 考虑以下CSS和html: class =“ snippet-code”> g...
    编程 发布于2025-07-16
  • 如何克服PHP的功能重新定义限制?
    如何克服PHP的功能重新定义限制?
    克服PHP的函数重新定义限制在PHP中,多次定义一个相同名称的函数是一个no-no。尝试这样做,如提供的代码段所示,将导致可怕的“不能重新列出”错误。 但是,PHP工具腰带中有一个隐藏的宝石:runkit扩展。它使您能够灵活地重新定义函数。 runkit_function_renction_re...
    编程 发布于2025-07-16
  • 编译器报错“usr/bin/ld: cannot find -l”解决方法
    编译器报错“usr/bin/ld: cannot find -l”解决方法
    错误:“ usr/bin/ld:找不到-l “ 此错误表明链接器在链接您的可执行文件时无法找到指定的库。为了解决此问题,我们将深入研究如何指定库路径并将链接引导到正确位置的详细信息。添加库搜索路径的一个可能的原因是,此错误是您的makefile中缺少库搜索路径。要解决它,您可以在链接器命令中添加...
    编程 发布于2025-07-16
  • 如何使用Python理解有效地创建字典?
    如何使用Python理解有效地创建字典?
    在python中,词典综合提供了一种生成新词典的简洁方法。尽管它们与列表综合相似,但存在一些显着差异。与问题所暗示的不同,您无法为钥匙创建字典理解。您必须明确指定键和值。 For example:d = {n: n**2 for n in range(5)}This creates a dicti...
    编程 发布于2025-07-16
  • 在JavaScript中如何并发运行异步操作并正确处理错误?
    在JavaScript中如何并发运行异步操作并正确处理错误?
    同意操作execution 在执行asynchronous操作时,相关的代码段落会遇到一个问题,当执行asynchronous操作:此实现在启动下一个操作之前依次等待每个操作的完成。要启用并发执行,需要进行修改的方法。 第一个解决方案试图通过获得每个操作的承诺来解决此问题,然后单独等待它们: co...
    编程 发布于2025-07-16
  • 为什么在我的Linux服务器上安装Archive_Zip后,我找不到“ class \” class \'ziparchive \'错误?
    为什么在我的Linux服务器上安装Archive_Zip后,我找不到“ class \” class \'ziparchive \'错误?
    Class 'ZipArchive' Not Found Error While Installing Archive_Zip on Linux ServerSymptom:When attempting to run a script that utilizes the ZipAr...
    编程 发布于2025-07-16
  • Java的Map.Entry和SimpleEntry如何简化键值对管理?
    Java的Map.Entry和SimpleEntry如何简化键值对管理?
    A Comprehensive Collection for Value Pairs: Introducing Java's Map.Entry and SimpleEntryIn Java, when defining a collection where each element com...
    编程 发布于2025-07-16
  • 如何使用组在MySQL中旋转数据?
    如何使用组在MySQL中旋转数据?
    在关系数据库中使用mySQL组使用mySQL组进行查询结果,在关系数据库中使用MySQL组,转移数据的数据是指重新排列的行和列的重排以增强数据可视化。在这里,我们面对一个共同的挑战:使用组的组将数据从基于行的基于列的转换为基于列。 Let's consider the following ...
    编程 发布于2025-07-16
  • PHP未来:适应与创新
    PHP未来:适应与创新
    PHP的未来将通过适应新技术趋势和引入创新特性来实现:1)适应云计算、容器化和微服务架构,支持Docker和Kubernetes;2)引入JIT编译器和枚举类型,提升性能和数据处理效率;3)持续优化性能和推广最佳实践。 引言在编程世界中,PHP一直是网页开发的中流砥柱。作为一个从1994年就开始发展...
    编程 发布于2025-07-16
  • CSS强类型语言解析
    CSS强类型语言解析
    您可以通过其强度或弱输入的方式对编程语言进行分类的方式之一。在这里,“键入”意味着是否在编译时已知变量。一个例子是一个场景,将整数(1)添加到包含整数(“ 1”)的字符串: result = 1 "1";包含整数的字符串可能是由带有许多运动部件的复杂逻辑套件无意间生成的。它也可以是故意从单个真理...
    编程 发布于2025-07-16
  • 如何正确使用与PDO参数的查询一样?
    如何正确使用与PDO参数的查询一样?
    在pdo 中使用类似QUERIES在PDO中的Queries时,您可能会遇到类似疑问中描述的问题:此查询也可能不会返回结果,即使$ var1和$ var2包含有效的搜索词。错误在于不正确包含%符号。通过将变量包含在$ params数组中的%符号中,您确保将%字符正确替换到查询中。没有此修改,PDO...
    编程 发布于2025-07-16
  • 如何在Java字符串中有效替换多个子字符串?
    如何在Java字符串中有效替换多个子字符串?
    在java 中有效地替换多个substring,需要在需要替换一个字符串中的多个substring的情况下,很容易求助于重复应用字符串的刺激力量。 However, this can be inefficient for large strings or when working with nu...
    编程 发布于2025-07-16

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3