用Strangler Fig模式重构遗留代码

Large objects are a code smell: overloaded with responsibilities and dependencies, as they continue to grow, it becomes more difficult to define what exactly they’re responsible for. Large objects are harder to reuse and slower to test. Even worse, they cost developers additional time and mental effort to understand, increasing the chance of introducing bugs. Unchecked, large objects risk turning the rest of your codebase into a ball of mud, but fear not! There are strategies for reducing the size and responsibilities of large objects. Here’s one that worked for us at Shopify, an all-in-one commerce platform supporting over one million merchants across the globe. 

大对象是一种代码气味:责任和依赖性过重,随着它们的不断增长,定义它们到底负责什么变得越来越困难。大型对象更难重用,测试也更慢。更糟糕的是,它们会花费开发人员额外的时间和精力去理解,增加引入错误的机会。如果不加控制,大对象有可能把你的代码库的其他部分变成一团泥巴,但不要害怕!有一些策略可以减少大对象的大小,并使之成为你的代码库。有一些策略可以减少大型对象的大小和责任。以下是我们在Shopify的一个成功案例,一个支持全球超过一百万商家的一体化商务平台。

As you can imagine, one of the most critical areas in Shopify’s Ruby on Rails codebase is the Shop model. Shop is a hefty class with well over 3000 lines of code, and its responsibilities are numerous. When Shopify was a smaller company with a smaller codebase, Shop’s purpose was clearer: it represented an online store hosted on our platform. Today, Shopify is far more complex, and the business intentions of the Shop model are murkier. It can be described as a God Object: a class that knows and does too much.

你可以想象,Shopify的Ruby on Rails代码库中最关键的领域之一是商店模型。Shop是一个巨大的类,有超过3000行的代码,它的职责也很多。当Shopify还是一个较小的公司,拥有较小的代码库时,Shop的目的更明确:它代表了托管在我们平台上的一个在线商店。今天,Shopify要复杂得多,而Shop模型的商业意图也更加模糊。它可以被描述为一个 "上帝对象":一个知道和做得太多的类。

My team, Kernel Architecture Patterns, is responsible for enforcing clean, efficient, scalable architecture in the Shopify codebase. Over the past few years, we invested a huge effort into componentizing Shopify’s monolithic codebase (see Deconstructing the Monolith) with the goal of establishing well-defined boundaries between different domains of the Shopify platform.

我的团队,Kernel Architecture Patterns,负责在Shopify代码库中执行干净、高效、可扩...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.1. UTC+08:00, 2024-11-22 14:37
浙ICP备14020137号-1 $访客地图$