我试图理解设计模式(特别是观察者模式)。我正在尝试为以下场景(特别是第二段)创建一个设计模式。我已经包含了迄今为止我设法生成的 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
最佳答案
观察者模式应该没问题。只有评论是您提供的图像不完整。
观察者和主体。
发布相同事件的类。在
future ,如果你有一个新的主题
那么你不需要做任何改变
客户端。
当然这取决于你的需要。
Subject1 ----- ---- Client1
Subject2 ----- ISubject------ Observer implements IObserver --- IClient ---- Client2
---- Client3
订阅主题 1、主题 2...
等等。
将通知与
状态(主题)引用观察者
遍历 IClient 列表和
通知每个客户。
当相同的通知可以时很有用
发生于不止一个主题。
示例:使用完成的文件夹重命名
慢速双击或按 F2 in
Windows 上下文
关于design-patterns - 设计模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5797993/