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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 论文笔记(2):Deep Crisp Boundaries: From Boundaries to Higher-level Tasks

    ---------------------------------------------------------------------------------------------------- ...

  4. 学习React系列(七)——Fragments、Portals、Error Boundaries与WEB组件

    React.Fragment portals Error Boundaries WEB组件 React.Fragment 想象一个场景,想把td包装为组件添加到table中去,代码如下: class ...

  5. Error Boundaries 错误边界

    错误边界是用于捕获其子组件树 JavaScript 异常,记录错误并展示一个回退的 UI 的 React 组件,而不是整个组件树的异常.错误边界在渲染期间.生命周期方法内.以及整个组件树构造函数内捕获 ...

  6. BOUNDARIES AND SPACE

    BOUNDARIES AND SPACE Review Nice work! You've learned a lot. Let's review the web and CSS concepts c ...

  7. All boundaries are conventions, waiting to be transcended.

    All boundaries are conventions, waiting to be transcended.所有界限都是陈规,等着被打破.

  8. Image Processing and Analysis_8_Edge Detection:Learning to Detect Natural Image Boundaries Using Local Brightness, Color, and Texture Cues ——2004

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  9. matlab boundaries和fchcode函数无法执行的解决办法 未定义与 'double' 类型的输入参数相对应的函数 'boundaries'

    在测试代码时发现,自己的matlab无法执行Freeman链码函数: boundaries和fchcode函数都无法正常运行: 需要在自己的工作目录中添加如下函数: boundaries   fchc ...

随机推荐

  1. Animation小问题整理

    1.在动画播放中改变层级内容的名字,不会造成动画内容映射的改变. 2.Animator动画剪辑层级没问题,但是不播放 检查是否Mask损坏,FBX文件的Animations选项下面有个Mask.Uni ...

  2. iOS 枚举的巧用

    前言 在之前的一篇文章中简单的提到了这个问题, 但是自己写的不详细, 并且自己深入了解的也不是特别多, 在开发中也没怎么用到,所以经过阅读者的反馈对这个问题很是疑惑! 本篇文章会分析之前的不足之处, ...

  3. tomcat证书配置(来源于http://my.oschina.net/zhxm/blog/161159)

    第一步:为服务器生成证书 1.进入%JAVA_HOME%/bin目录 2.使用keytool为Tomcat生成证书,假定目标机器的域名是“localhost”,keystore文件存放在“D:\tom ...

  4. [HIHO1196]高斯消元·二(高斯消元、枚举自由变元)

    题目链接:http://hihocoder.com/problemset/problem/1196 #include <bits/stdc++.h> using namespace std ...

  5. 浅谈JavaScript中的闭包

    浅谈JavaScript中的闭包 在JavaScript中,闭包是指这样一个函数:它有权访问另一个函数作用域中的变量. 创建一个闭包的常用的方式:在一个函数内部创建另一个函数. 比如: functio ...

  6. Codeforces Round #263 (Div. 1)

    B 树形dp 组合的思想. Z队长的思路. dp[i][1]表示以i为跟结点的子树向上贡献1个的方案,dp[i][0]表示以i为跟结点的子树向上贡献0个的方案. 如果当前为叶子节点,dp[i][0] ...

  7. poj3301Texas Trip(三分)

    链接 这题还真没看出来长得像三分.. 三分角度,旋转点. 最初找到所有点中最左边.右边.上边.下边的点,正方形边长为上下距离和左右距离的最大值,如图样例中的四个点(蓝色的),初始正方形为红色的正方形. ...

  8. Mysql 中有关日期的函数(sql)

    DAYOFWEEK(date)返回日期date的星期索引(1=星期天,2=星期一, ……7=星期六).这些索引值对应于ODBC标准.mysql> select DAYOFWEEK('1998-0 ...

  9. [css] CSS相对定位|绝对定位

    第一篇链接:http://www.zhangxinxu.com/wordpress/2010/12/css-%E7%9B%B8%E5%AF%B9%E7%BB%9D%E5%AF%B9%E5%AE%9A% ...

  10. SCCM 2007日志

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://ycrsjxy.blog.51cto.com/618627/203174      ...