legacy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Legacy Modernization

遗留系统现代化

Safely upgrade and modernize legacy systems.
安全地升级和现代化遗留系统。

When to Use

适用场景

  • Framework migrations
  • Language version upgrades
  • Monolith decomposition
  • Technical debt reduction
  • Dependency updates
  • 框架迁移
  • 语言版本升级
  • 单体应用拆分
  • 技术债务削减
  • 依赖项更新

Migration Strategies

迁移策略

Strangler Fig Pattern

绞杀者模式

┌─────────────────────────────────────┐
│           Load Balancer             │
└──────────────┬──────────────────────┘
       ┌───────┴───────┐
       │               │
┌──────▼──────┐ ┌──────▼──────┐
│   Legacy    │ │    New      │
│   System    │ │   Service   │
└─────────────┘ └─────────────┘

1. Route new features to new service
2. Gradually migrate existing features
3. Eventually retire legacy system
┌─────────────────────────────────────┐
│           Load Balancer             │
└──────────────┬──────────────────────┘
       ┌───────┴───────┐
       │               │
┌──────▼──────┐ ┌──────▼──────┐
│   Legacy    │ │    New      │
│   System    │ │   Service   │
└─────────────┘ └─────────────┘

1. Route new features to new service
2. Gradually migrate existing features
3. Eventually retire legacy system

Branch by Abstraction

抽象分支模式

python
undefined
python
undefined

1. Create abstraction layer

1. Create abstraction layer

class PaymentProcessor(ABC): @abstractmethod def process(self, amount: float) -> bool: pass
class PaymentProcessor(ABC): @abstractmethod def process(self, amount: float) -> bool: pass

2. Wrap legacy implementation

2. Wrap legacy implementation

class LegacyPaymentProcessor(PaymentProcessor): def init(self, legacy_system): self.legacy = legacy_system
def process(self, amount: float) -> bool:
    return self.legacy.old_process_method(amount)
class LegacyPaymentProcessor(PaymentProcessor): def init(self, legacy_system): self.legacy = legacy_system
def process(self, amount: float) -> bool:
    return self.legacy.old_process_method(amount)

3. Create new implementation

3. Create new implementation

class ModernPaymentProcessor(PaymentProcessor): def process(self, amount: float) -> bool: # New implementation pass
class ModernPaymentProcessor(PaymentProcessor): def process(self, amount: float) -> bool: # New implementation pass

4. Use feature flag to switch

4. Use feature flag to switch

processor = (ModernPaymentProcessor() if feature_flag("new_payment") else LegacyPaymentProcessor(legacy))
undefined
processor = (ModernPaymentProcessor() if feature_flag("new_payment") else LegacyPaymentProcessor(legacy))
undefined

Migration Checklist

迁移检查清单

Before Starting

开始前

  • Document current behavior
  • Add tests for existing functionality
  • Set up monitoring and alerts
  • Create rollback plan
  • Communicate with stakeholders
  • 记录当前系统行为
  • 为现有功能添加测试
  • 配置监控与告警
  • 制定回滚计划
  • 与相关人员沟通

During Migration

迁移中

  • Make incremental changes
  • Test after each change
  • Monitor error rates
  • Keep legacy running in parallel
  • Document breaking changes
  • 进行增量式修改
  • 每次修改后执行测试
  • 监控错误率
  • 保持遗留系统并行运行
  • 记录破坏性变更

After Migration

迁移后

  • Remove feature flags
  • Clean up legacy code
  • Update documentation
  • Archive old codebase
  • Post-mortem lessons learned
  • 移除功能开关
  • 清理遗留代码
  • 更新文档
  • 归档旧代码库
  • 总结迁移经验教训

Common Migrations

常见迁移场景

jQuery to React

从jQuery迁移到React

javascript
// Phase 1: Embed React in jQuery app
const root = document.getElementById("new-component");
ReactDOM.render(<NewComponent />, root);

// Phase 2: Shared state
window.appState = { user: null };
// Both jQuery and React read from appState

// Phase 3: Gradual replacement
// Replace one component at a time
javascript
// Phase 1: Embed React in jQuery app
const root = document.getElementById("new-component");
ReactDOM.render(<NewComponent />, root);

// Phase 2: Shared state
window.appState = { user: null };
// Both jQuery and React read from appState

// Phase 3: Gradual replacement
// Replace one component at a time

Python 2 to 3

从Python 2迁移到Python 3

python
undefined
python
undefined

Use future imports for compatibility

Use future imports for compatibility

from future import print_function, division, absolute_import
from future import print_function, division, absolute_import

Use six for cross-version compatibility

Use six for cross-version compatibility

import six if six.PY2: text_type = unicode else: text_type = str
import six if six.PY2: text_type = unicode else: text_type = str

Run 2to3 tool

Run 2to3 tool

python -m lib2to3 --write --nobackups src/

python -m lib2to3 --write --nobackups src/

undefined
undefined

Compatibility Layers

兼容层

python
undefined
python
undefined

Adapter for API changes

Adapter for API changes

class CompatibilityAdapter: def init(self, new_service): self.new = new_service
# Old API signature
def get_user(self, user_id):
    # Translate to new API
    return self.new.fetch_user(id=user_id)

# Deprecation warning
def old_method(self):
    warnings.warn(
        "old_method is deprecated, use new_method instead",
        DeprecationWarning
    )
    return self.new.new_method()
undefined
class CompatibilityAdapter: def init(self, new_service): self.new = new_service
# Old API signature
def get_user(self, user_id):
    # Translate to new API
    return self.new.fetch_user(id=user_id)

# Deprecation warning
def old_method(self):
    warnings.warn(
        "old_method is deprecated, use new_method instead",
        DeprecationWarning
    )
    return self.new.new_method()
undefined

Examples

示例

Input: "Migrate from Express to Fastify" Action: Create adapter layer, migrate routes incrementally, test each step
Input: "Reduce technical debt in this module" Action: Add tests first, refactor incrementally, maintain compatibility
输入: "从Express迁移到Fastify" 操作: 创建适配层,逐步迁移路由,每一步都进行测试
输入: "削减该模块的技术债务" 操作: 先添加测试,逐步重构,保持兼容性