课程: Python: Design Patterns (2021)

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Visitor

Visitor

- The visitor design pattern allows adding new features to an existing class hierarchy without changing it. It's sometimes necessary to add new operations, dynamically to exist in classes with minimal changes. For our scenario, we present a house class. Visitors in this scenario include an HVAC specialist and an electrician. The HVAC specialist in our scenario is visitor type one, and the electrician is visitor type two. The visitor pattern represents new operations to be performed on the various elements of an existing class hierarchy. Visitors can also provide operations on a composite object.

内容