design-patterns - 设计模式

标签 design-patterns architecture uml

我试图理解设计模式(特别是观察者模式)。我正在尝试为以下场景(特别是第二段)创建一个设计模式。我已经包含了迄今为止我设法生成的 UML 图的图像。人们能否就它是否正确/错误/充分/不足提出建议,或者给我任何有用的提示?我尝试使用观察者模式对系统进行建模 - 是否有任何其他模式可用于对这种情况进行建模?

Consider the design of a system to support flight reservations and flight status alerts for an airline. The system centrally stores information about registered customers and controls customers' access to the information. A customer maintains a profile describing some basic information including name, country of residence, gender, birth date, email address and mobile number. A customer can search for round-trip flights on the airline by entering the city name or airport code for the origin and destination. Upon finding an itinerary of acceptable flights, a customer can purchase the flights in economy class, business class or first class. Upon completing the purchase, a customer can select seats on the chosen flights in the class of service paid for. The system will deliver alerts about the flights to the customer's alert address, which can be the email address and/or mobile number, depending on the customer's choice. An alert may indicate a delay to a flight, a cancellation to a flight, or some other change to flight status that may be introduced in future versions of the system.

At some point a flight becomes available for purchase with a specified flight date. A customer can purchase a seat on the flight np to one week before the flight date; after this date the flight is closed to further seat purchases. In addition, once a flight becomes available for purchase, its status is on-time until one day before the flight, after which it can become delayed upon occurrence of a weather delay, cancelled upon a decision to cancel the flight, and landed upon successful completion of the flight. A flight ceases to exist after it becomes cancelled or landed.



http://i.stack.imgur.com/YB9lJ.jpg

最佳答案

观察者模式应该没问题。只有评论是您提供的图像不完整。

  • 尽量避免直接耦合
    观察者和主体。
  • 而是使用一个可以管理所有观察者的类。
  • 这为您的设计提供了具有多个主题的灵 active
    发布相同事件的类。在
    future ,如果你有一个新的主题
    那么你不需要做任何改变
    客户端。

  • 当然这取决于你的需要。
    Subject1 -----                                                             ---- Client1
    Subject2 ----- ISubject------  Observer implements IObserver  --- IClient  ---- Client2
                                                                               ---- Client3
    
  • Observer 维护 IClient 和
    订阅主题 1、主题 2...
    等等。
  • 任何主题都可以
    将通知与
    状态(主题)引用观察者
    遍历 IClient 列表和
    通知每个客户。
  • 这是
    当相同的通知可以时很有用
    发生于不止一个主题。
    示例:使用完成的文件夹重命名
    慢速双击或按 F2 in
    Windows 上下文
  • 关于design-patterns - 设计模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5797993/

    相关文章:

    javascript - 仅在客户端导出 CSV 是一种不好的做法吗?

    c++ - 作为 DSL 的 UML 事件图;转换为 C++

    java - 适用于 HTTP 和数据库的 DAO 模式

    c++ - 在访问者模式中使用 accept()

    .net - 寻找在我们的应用程序中实现版本控制功能的建议

    java - RMI:客户端是否必须拥有所有实现或仅拥有接口(interface)?

    uml - UML 状态图中具有相同开始/结束的转换

    java - 在设计继承时陷入困境,哪一个是正确的?

    java - 责任链设计模式实现,在不同点开始停止链

    java - 处理以下场景的设计模式