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 ...
随机推荐
- JAVA基础知识之网络编程——-网络通信模型(IO模型)
<Unix网络编程:卷1>中介绍了5中I/O模型,JAVA作为运行在宿主机上的程序,底层也遵循这5中I/O模型规则.这5中I/O模型分别是: 阻塞式IO 非阻塞式IO I/O复用 信号驱动 ...
- Windows下Eclipse连接hadoop
2015-3-27 参考: http://www.cnblogs.com/baixl/p/4154429.html http://blog.csdn.net/u010911997/article/de ...
- [问题2014S09] 复旦高等代数II(13级)每周一题(第九教学周)
[问题2014S09] 证明: \(n\) 阶方阵 \(A\) 与所有的 \(A^m\,(m\geq 1)\) 都相似的充分必要条件是 \(A\) 的 Jordan 标准型为 \[\mathrm{d ...
- 实操canvas
我觉得仅仅靠看书是不会学好canvas的,经过前几天对canvas画布属性的阅读和了解,然后我觉得还是要实际操作才会学的更好. <canvas width="" height ...
- javascript事件代理(Event Delegation)
看了几篇文章,放上来供参考 司徒正美的文章,Event Delegation Made Easy --------------------------------------------------- ...
- 跨站脚本 XSS<一:介绍>
*XSS 利用的是用户对指定网站的信任,CSRF 利用的是网站对用户网页浏览器的信任 跨站脚本(Cross-site scripting,通常简称为XSS)是一种网站应用程序的安全漏洞攻击,是代码注入 ...
- 再谈 Unlix (Linux, AIX, HPUX) 上 Java 的 java.lang.OutOfMemoryError: unable to create new native thread
首先很容易排除是 程序问题 内存用了很少,64 位 Java也没有内存限制,线程也不多,-Xss 堆栈也没人会配置很大. 那么肯定是 limit 不足引起 配置 ulimit 就可以了,问题看起来很简 ...
- C#MongoDB使用实践
9.5更新:更方便的启动命令 1)在D:\MongoDB中新建mongo.config文件,内容为 #启动mongod:mongod.exe --bind_ip 127.0.0.1 --logpath ...
- Canvas与Image互相转换
转换 Image为 Canvas要把图片转换为Canvas(画板,画布),可以使用canvas元素 context 的drawImage方法: // 把image 转换为 canvas对象 funct ...
- java并发编程-Executor框架
Executor框架是指java 5中引入的一系列并发库中与executor相关的一些功能类,其中包括线程池,Executor,Executors,ExecutorService,Completion ...