重走Java設計模式——訪問者模式(Visitor Pattern)

訪問者模式 定義 主要將數據結構與數據操作分離。 代碼示例 創建一個定義接受操作的ComputerPart接口。Keyboard、Mouse、Monitor和Computer 是實現了 ComputerPart 接口的實體類。我們將定義另一個接口 ComputerPartVisitor,它定義了訪問者類的操作。Computer 使用實體訪問者來執行相應的動作。 VisitorPatternDemo
相關文章
相關標籤/搜索