- Advanced TypeScript Programming Projects
- Peter O'Hanlon
- 224字
- 2021-06-24 13:27:10
Understanding the visitor pattern
The visitor pattern is what is known as a behavioral pattern. The term behavioral pattern is simply a classification of a group of patterns that are concerned with the way that classes and objects communicate. What the visitor pattern gives us is the ability to separate an algorithm from the object that the algorithm works on. This sounds a lot more complicated than it really is.
One of the motivations behind us using the visitor pattern is that we want to take the common ParseElement class and apply different operations on it, depending on what the underlying markdown is, which ultimately leads to us building up the MarkdownDocument class. The idea here is that if the content the user types in is something we would represent in HTML as a paragraph, we want to add different tags to those used, for example, when the content represents a horizontal rule. The convention for the visitor pattern is that we have two interfaces, IVisitor and IVisitable. At their most basic, these interfaces look like this:
interface IVisitor {
Visit(......);
}
interface IVisitable {
Accept(IVisitor, .....);
}
The idea behind these interfaces is that the object will be visitable, so when it needs to perform the relevant operations, it accepts the visitor so that it can visit the object.
- Linux Mint Essentials
- Google系統(tǒng)架構(gòu)解密:構(gòu)建安全可靠的系統(tǒng)
- 無蘋果不生活 OS X Mountain Lion隨身寶典
- VMware Horizon View 6 Desktop Virtualization Cookbook
- 構(gòu)建可擴展分布式系統(tǒng):方法與實踐
- 玩到極致 iPhone 4S完全攻略
- Linux網(wǎng)絡(luò)內(nèi)核分析與開發(fā)
- 突破平面3ds Max動畫設(shè)計與制作
- Mastering Reactive JavaScript
- Fedora 12 Linux應(yīng)用基礎(chǔ)
- iOS 8開發(fā)指南
- CentOS 6 Linux Server Cookbook
- Linux操作系統(tǒng)
- Learn SwiftUI
- Learning Continuous Integration with Jenkins(Second Edition)