适用设计模式的典型场合(typical use cases for design patterns)
访问量: 3211
1. decorator: 向一杯咖啡中,加入 牛奶,糖,巧克力。 或者加入双份巧克力。 ( add sugar, milk and chocolate to a cup of coffee, or add double of sugar to the coffee)
2. template: 一份文档,要生成多种格式:HTML, 纯文本,CSV(格式固定由:头,主体,尾部组成) (Given a source data, generate multiple formats of documents, e.g. HTML , plain old text and CSV, all of them contains the same structure: HEAD, CONTENT, FOOTER )
3. strategy: 一份文档,要生成多种格式: HTML , 纯文本等等,但是他们的格式不同,例如: HTML 有头,有尾有主干,而纯文本的话只需要主干内容,CSV的话,只有头和主干。 (given a source data, generate, generate multiple formats of documents, e.g. HTML, plain old text and CSV, all of them have the different format. e.g. HTML: head, body, footer. TEXT: content only. CSV: header and content )
4. proxy: 需要对某个资源的访问进行权限控制。例如检查用户名密码等。 ( need access control to a resource)