Boundaries
Using Third-Party Code
There is a natural tension between the provider of an interface and the user of an interface.Providers of third-party packages and frameworks strive for broad applicability so they can work in many environments and appeal to a wide audience,Users, on the other hand, want an interface that is focused on their particular needs.This tension can cause problems at the boundaries of our systems.
We are not suggesting that every use of Map be encapsulated in this form.Rather, we are advising you not to pass Maps arround your system.If you use a boundary interface like Map, keep it inside the class, or close family of classes, where it is used.Avoid returning it from, or accepting it as an argument to, public APIs.
Exploring and Learning Boundaries
Third-party code helps us get more functionality delivered in less time.Where do we start when we want to utilize some third-party package? It's not our job to test the third-party code,but it may be in our best interest to write tests for the third-party code we use.
Instead of experimenting and trying out the new stuff in our production code, we could write some tests to explore our understanding of the third-party code.In learning tests we call the third-party API, as we expect to use it in our application.We're essentially doing controlled experiments that check our understanding of that APT.The tests focus on what we want out of the API.
Learning log4j
We want to use the apache log4j package rather than out own custom-built logger.We can encapsulate that knowlegde into our logger class so that the rest of our application is located from the log4j boundary interface.
Learning Tests are Better Than Free
The learning tests end up costing nothing.We had to learn the API anyway, and writing those tests was an easy and isolated way to get that knowledge.The learning tests were precise experiments that helped increase our understanding.
Not only are learning tests free, they have a positive return on investment.When there are new releases of the third-party package, we run the learning tests to see whether there are behavioral differences.
Learning tests verify that the third-party packages we are using work the way we expect them to.Once integrated, there are no gurantees that the third-party code will stay compatible with our needs.The original authors will have pressures to change their code to meet new needs of their own.They will fix bugs and add new capabilities.With each release comes new risk.If the third-party package changes in some way incompatible with our tests,we will find out right way.
Whether you need the learning provided by the learning tests or not, a clean boundary should be supported by a set of outbound tests that exercise the interface the same way the production code does.Without thest boundary tests to ease the migration, we might be tempted to stay with the old version longer than we should.
Using Code That Does Not Yet Exist
There is another kind of boundary,one that separates the known from the unknown.There are often places in the code where our knowledge seems to drop off the edge.Sometimes what is on the other side of the boundary is unknowable.Sometimes we choose to look no farther than then boundary.
Clean Boundaries
Interesting things happen at boundaries.Change is one of those things.Good software designs accommodate change without huge investments and rework.We use code that is out of our control, special care must be taken to protect our investment and make sure future change is not too costly.
Code at the boundaries needs clear separation and tests that define expectations.We should avoid letting too much of our code know about the third-party particulars.It's better to depend on something you control than on something you don't control,lest it end up controlling you.
We manage third-party boundaries by having very few places in the code that refer to them.We may wrap them as we did with Map, or we may use an ADAPTER to convert from our perfect interface to the provided interface.Either way our code speaks to us better, promotes internally consistent usage across the boundary, and has fewer maintenance point when the third-party code changes.
Boundaries的更多相关文章
- hdu 1231, dp ,maximum consecutive sum of integers, find the boundaries, possibly all negative, C++ 分类: hdoj 2015-07-12 03:24 87人阅读 评论(0) 收藏
the algorithm of three version below is essentially the same, namely, Kadane's algorithm, which is o ...
- Decision Boundaries for Deep Learning and other Machine Learning classifiers
Decision Boundaries for Deep Learning and other Machine Learning classifiers H2O, one of the leading ...
- 论文笔记(2):Deep Crisp Boundaries: From Boundaries to Higher-level Tasks
---------------------------------------------------------------------------------------------------- ...
- 学习React系列(七)——Fragments、Portals、Error Boundaries与WEB组件
React.Fragment portals Error Boundaries WEB组件 React.Fragment 想象一个场景,想把td包装为组件添加到table中去,代码如下: class ...
- Error Boundaries 错误边界
错误边界是用于捕获其子组件树 JavaScript 异常,记录错误并展示一个回退的 UI 的 React 组件,而不是整个组件树的异常.错误边界在渲染期间.生命周期方法内.以及整个组件树构造函数内捕获 ...
- BOUNDARIES AND SPACE
BOUNDARIES AND SPACE Review Nice work! You've learned a lot. Let's review the web and CSS concepts c ...
- All boundaries are conventions, waiting to be transcended.
All boundaries are conventions, waiting to be transcended.所有界限都是陈规,等着被打破.
- Image Processing and Analysis_8_Edge Detection:Learning to Detect Natural Image Boundaries Using Local Brightness, Color, and Texture Cues ——2004
此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...
- matlab boundaries和fchcode函数无法执行的解决办法 未定义与 'double' 类型的输入参数相对应的函数 'boundaries'
在测试代码时发现,自己的matlab无法执行Freeman链码函数: boundaries和fchcode函数都无法正常运行: 需要在自己的工作目录中添加如下函数: boundaries fchc ...
随机推荐
- 数据转换为json格式的方法
数据转换为json格式: 如果一张表中存在主外键关系,模板自动生成的类是不可以转换成JSON格式的,此时需要重新写一个类,类前面需加[DataContract],字段前需加[DataMember],实 ...
- javascript 函数声明和函数表达式的区别(学习笔记)
javascript中声明函数的方法有两种:函数声明式和函数表达式. 区别如下: 1).以函数声明的方法定义的函数,函数名是必须的,而函数表达式的函数名是可选的. 2).以函数声明的方法定义的函数,函 ...
- fifter常见的运用场景
没配置过滤器 package servlet; import java.io.IOException; import javax.servlet.ServletException; import ja ...
- Java:描述反射机制的作用?举几个反射的应用?
比较全的解释了:JAVA反射机制 JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法:这种动态获取的信息以及动态调用对象的方 ...
- Design pattern---观察者模式
观察者模式:发布/订阅模式,当某对象(被观察者)状态发生改变时所有订阅该对象的观察者对象(观察者)都将更新自己 成员(4种): 1.抽象被观察者:将所有的观察者对象的引用存入一个集合,并且定义了添加 ...
- setColorFilter()滤镜
----------转载于:http://blog.sina.com.cn/s/blog_5da93c8f01012pkj.html 通过setColorFilter可以实现滤镜效果. 如: ...
- ubuntu访问 windows文件
在unbunt下,想打开windows的文件,出现这个报错 安装ntfs-3g: sudo apt-get install ntfs-3g 看下自己要挂载的分区叫啥名 sudo fdisk -l 我的 ...
- Evolutionary Computing: 1. Introduction
Outline 什么是进化算法 能够解决什么样的问题 进化算法的重要组成部分 八皇后问题(实例) 1. 什么是进化算法 遗传算法(GA)是模拟生物进化过程的计算模型,是自然遗传学与计算机科学相互结合的 ...
- remount failed: Operation not permitted ,怎么办呢?
remount failed: Operation not permitted ,怎么办呢? 1. 确定是否正确连接手机了$ adb devices 2. 进入shell$ adb shell 3. ...
- News common vocabulary
英语新闻常用词汇与短语 经济篇 accumulated deficit 累计赤字 active trade balance 贸易顺差 adverse trade balance 贸易逆差 aid 援助 ...