Abstract Document

UML :

abstract-document.png

introduction :

/**
 * The Abstract Document pattern enables handling additional, non-static
 * properties. This pattern uses concept of traits to enable type safety and
 * separate properties of different classes into set of interfaces.
 * 
 * In Abstract Document pattern,({@link AbstractDocument}) fully implements
 * {@link Document}) interface. Traits are then defined to enable access to
 * properties in usual, static way.
 */
  • Abstract Document Pattern
    • 结构型设计模式
    • 个人理解主要是处理额外的非静态的属性,将他们放入Map<String,Object> 来进行存储
    • 同时又用到了Java8的新特性,Stream和Optional来保证数据读取时类型的一致性和稳定性(类似于泛型,和非空检查)
    • Kotlin很好的解决了后者的检查问题,但是编写起来还是需要理解哪里可以为null哪里不行
  • 此模式的目的是提供强类型语言中实现组件之间的高度灵活性,使新的属性可以在对象树上快速添加,而不会失去类型安全的支持。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容