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.

时间: 2024-10-08 08:12:06

Boundaries的相关文章

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 deep learning framework in python, is now available in R. We will show how to get started with H2O, its working, plotting of decision boundaries and

Architects’ Focus Is on the Boundaries and Interfaces

? Architects' Focus Is on the Boundaries and Interfaces Einar Landre SinCE loRd nElSon dESTRoyEd the French and Spanish fleet at Trafalgar in 1805, "divide and conquer" has been the mantra for dealing with complex and difficult problems. A more

hdu 1231, maximum consecutive sum of integers, finding the boundaries, possibly all negative, C++

the algorithm of three version below is essentially the same, namely, Kadane's algorithm, which is of O(n) complexity. https://en.wikipedia.org/wiki/Maximum_subarray_problem the evolution of the implementations is to remove redundancy and do what is

CVE-2014-0050: Exploit with Boundaries, Loops without Boundaries、Apache Commons FileUpload and Apache Tomcat DoS

catalog 1. Description 2. Analysis 3. POC 4. Solution 1. Description MultipartStream.java in Apache Commons FileUpload before 1.3.1, as used in Apache Tomcat, JBoss Web, and other products, allows remote attackers to cause a denial of service (infini

Extjs event domain 研究

Listeners and Event Domains In Ext JS 4.2, the MVC event dispatcher was generalized with the introduction of event domains. These event domains intercepted events as they were fired and dispatched them to controllers controlled by selector matching.

Fulltext Index Study3:Query

在query 语句中,可以使用 contains predicate来调用Fulltext Index,实现比like速度更快的查询.使用contains能够进行term的extract匹配查询或term的前缀匹配查询,还能够进行基于词根的steming查询,基于自定义同义词文件的synonym查询,基于距离和顺序的相邻term查询.和like 相比,contains不能进行后缀匹配查询.如果Fulltext Index 能够满足业务需求,那么Fulltext Index是一个非常不错的选择,跟

Transactional Replication

事务复制的原理是复制publisher的事务日志,通过distributor,传送到subscriber,在subscirber端重做事务日志,要求事务日志是连续和完整的. distributor有两个Agent:一个是Log Reader Agent,一个是Distribution Agent.Log Reader Agent负责将Publisher中的transaction log读取到Distribution database,Distribution负责将Distribution dat

malloc和free的内存到底有多大?——GNU glib库

大家应该都比较熟悉这一点:malloc分配的内存一定大于用户指定的大小!而且很多人也问过这样的问题:到底大多少?以及实际上malloc到底分配了多少? 我们知道这个大小一定在某个"神奇"地方记录着,但是就像自己的"思维"一样,你确无法感知!不过,这是错觉,只是我们习惯了只使用,而没有深入剖析源码,在这里我将揭开这个面纱,去掉其透明化! 声明:源码基于GNU glib库的2.7版本的malloc目录下相关文件 再声明:不同的C库实现方式不一定一样,这里是glib库,如

ios uilable折行后文字怎么都是左对齐

typedef NS_ENUM(NSInteger, NSLineBreakMode) {        /* What to do with long lines */ NSLineBreakByWordWrapping = 0,         /* Wrap at word boundaries, default */ NSLineBreakByCharWrapping,        /* Wrap at character boundaries */ NSLineBreakByClip