Design Pattern Application by dasien/retrowarden
npx skills add https://github.com/dasien/retrowarden --skill 'Design Pattern Application'识别何时应用已确立的设计模式,以创建灵活、可维护和可重用的代码结构。
# Problem: Multiple payment methods with different processing logic
class PaymentStrategy:
def process(self, amount): pass
class CreditCardPayment(PaymentStrategy):
def process(self, amount):
# Credit card processing logic
print(f"Processing ${amount} via credit card")
class PayPalPayment(PaymentStrategy):
def process(self, amount):
# PayPal processing logic
print(f"Processing ${amount} via PayPal")
class Order:
def __init__(self, payment_strategy: PaymentStrategy):
self.payment = payment_strategy
def checkout(self, amount):
self.payment.process(amount)
# Usage
order1 = Order(CreditCardPayment())
order1.checkout(100)
order2 = Order(PayPalPayment())
order2.checkout(50)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
每周安装数
0
代码仓库
GitHub 星标数
4
首次出现时间
1970年1月1日
安全审计
Recognize when to apply established design patterns to create flexible, maintainable, and reusable code structures.
# Problem: Multiple payment methods with different processing logic
class PaymentStrategy:
def process(self, amount): pass
class CreditCardPayment(PaymentStrategy):
def process(self, amount):
# Credit card processing logic
print(f"Processing ${amount} via credit card")
class PayPalPayment(PaymentStrategy):
def process(self, amount):
# PayPal processing logic
print(f"Processing ${amount} via PayPal")
class Order:
def __init__(self, payment_strategy: PaymentStrategy):
self.payment = payment_strategy
def checkout(self, amount):
self.payment.process(amount)
# Usage
order1 = Order(CreditCardPayment())
order1.checkout(100)
order2 = Order(PayPalPayment())
order2.checkout(50)
Weekly Installs
0
Repository
GitHub Stars
4
First Seen
Jan 1, 1970
Security Audits
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
109,600 周安装