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

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

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

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]删除
最新教程 更多>
  • 如何在JavaScript对象中动态设置键?
    如何在JavaScript对象中动态设置键?
    在尝试为JavaScript对象创建动态键时,如何使用此Syntax jsObj['key' i] = 'example' 1;不工作。正确的方法采用方括号: jsobj ['key''i] ='example'1; 在JavaScript中,数组是一...
    编程 发布于2025-03-25
  • 可以在纯CS中将多个粘性元素彼此堆叠在一起吗?
    可以在纯CS中将多个粘性元素彼此堆叠在一起吗?
    [2这里: https://webthemez.com/demo/sticky-multi-header-scroll/index.html </main> <section> { display:grid; grid-template-...
    编程 发布于2025-03-25
  • Numpy的矢量函数如何有效地证明数组的合理性?
    Numpy的矢量函数如何有效地证明数组的合理性?
    使用向量函数 Numpy提供使用矢量化函数的数组合理的方法,提供改进的性能和代码简单性,与传统的python循环相比,提供了改进的性能和代码简单性。在保持其形状的同时,左,右,向上或向下的非零元素。以下numpy实现执行有效的理由: = a [mask] 别的: out.t ...
    编程 发布于2025-03-25
  • 版本5.6.5之前,使用current_timestamp与时间戳列的current_timestamp与时间戳列有什么限制?
    版本5.6.5之前,使用current_timestamp与时间戳列的current_timestamp与时间戳列有什么限制?
    在时间戳列上使用current_timestamp或MySQL版本中的current_timestamp或在5.6.5 此限制源于遗留实现的关注,这些限制需要对当前的_timestamp功能进行特定的实现。 创建表`foo`( `Productid` int(10)unsigned not n...
    编程 发布于2025-03-25
  • 如何基于唯一的电子邮件值合并和重塑对象数组?
    如何基于唯一的电子邮件值合并和重塑对象数组?
    在数据操作领域中合并和将对象的数组与唯一的电子邮件值 考虑需要合并两个对象阵列,每个对象都包含电子邮件属性。目标是创建一个包含所有唯一电子邮件值的新数组。 , (对象)[“电子邮件” =>“ [电子邮件  prected]”], (对象)[“电子邮件” =>“ wefe...
    编程 发布于2025-03-25
  • 为什么不使用CSS`content'属性显示图像?
    为什么不使用CSS`content'属性显示图像?
    在Firefox extemers属性为某些图像很大,&& && && &&华倍华倍[华氏华倍华氏度]很少见,却是某些浏览属性很少,尤其是特定于Firefox的某些浏览器未能在使用内容属性引用时未能显示图像的情况。这可以在提供的CSS类中看到:。googlepic { 内容:url(&#...
    编程 发布于2025-03-25
  • 如何使用不同数量列的联合数据库表?
    如何使用不同数量列的联合数据库表?
    合并列数不同的表 当尝试合并列数不同的数据库表时,可能会遇到挑战。一种直接的方法是在列数较少的表中,为缺失的列追加空值。 例如,考虑两个表,表 A 和表 B,其中表 A 的列数多于表 B。为了合并这些表,同时处理表 B 中缺失的列,请按照以下步骤操作: 确定表 B 中缺失的列,并将它们添加到表的末...
    编程 发布于2025-03-25
  • 如何在鼠标单击时编程选择DIV中的所有文本?
    如何在鼠标单击时编程选择DIV中的所有文本?
    在鼠标上选择div文本单击带有文本内容,用户如何使用单个鼠标单击单击div中的整个文本?这允许用户轻松拖放所选的文本或直接复制它。 在单个鼠标上单击的div元素中选择文本,您可以使用以下Javascript函数: function selecttext(canduterid){ if(do...
    编程 发布于2025-03-25
  • 对象拟合:IE和Edge中的封面失败,如何修复?
    对象拟合:IE和Edge中的封面失败,如何修复?
    To resolve this issue, we employ a clever CSS solution that solves the problem:position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%)...
    编程 发布于2025-03-25
  • 如何克服PHP的功能重新定义限制?
    如何克服PHP的功能重新定义限制?
    克服PHP的函数重新定义限制在PHP中,多次定义一个相同名称的函数是一个no-no。尝试这样做,如提供的代码段所示,将导致可怕的“不能重新列出”错误。 但是,PHP工具腰带中有一个隐藏的宝石:runkit扩展。它使您能够灵活地重新定义函数。 runkit_function_renction_re...
    编程 发布于2025-03-25
  • 如何将MySQL数据库添加到Visual Studio 2012中的数据源对话框中?
    如何将MySQL数据库添加到Visual Studio 2012中的数据源对话框中?
    在Visual Studio 2012 尽管已安装了MySQL Connector v.6.5.4,但无法将MySQL数据库添加到实体框架的“ DataSource对话框”中。为了解决这一问题,至关重要的是要了解MySQL连接器v.6.5.5及以后的6.6.x版本将提供MySQL的官方Visual...
    编程 发布于2025-03-25
  • 如何从Google API中检索最新的jQuery库?
    如何从Google API中检索最新的jQuery库?
    从Google APIS 问题中提供的jQuery URL是版本1.2.6。对于检索最新版本,以前有一种使用特定版本编号的替代方法,它是使用以下语法:获取最新版本:未压缩)While these legacy URLs still remain in use, it is recommended ...
    编程 发布于2025-03-25
  • 如何使用组在MySQL中旋转数据?
    如何使用组在MySQL中旋转数据?
    在关系数据库中使用mySQL组使用mySQL组进行查询结果,在关系数据库中使用MySQL组,转移数据的数据是指重新排列的行和列的重排以增强数据可视化。在这里,我们面对一个共同的挑战:使用组的组将数据从基于行的基于列的转换为基于列。 Let's consider the following ...
    编程 发布于2025-03-25
  • 大批
    大批
    [2 数组是对象,因此它们在JS中也具有方法。 切片(开始):在新数组中提取部分数组,而无需突变原始数组。 令ARR = ['a','b','c','d','e']; // USECASE:提取直到索引作...
    编程 发布于2025-03-25
  • 如何在php中使用卷发发送原始帖子请求?
    如何在php中使用卷发发送原始帖子请求?
    如何使用php 创建请求来发送原始帖子请求,开始使用curl_init()开始初始化curl session。然后,配置以下选项: curlopt_url:请求 [要发送的原始数据指定内容类型,为原始的帖子请求指定身体的内容类型很重要。在这种情况下,它是文本/平原。要执行此操作,请使用包含以下标头...
    编程 发布于2025-03-25

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

Copyright© 2022 湘ICP备2022001581号-3