عرض عملي: انعكاس الاعتماديات لمزوّد دفع
في هذا الدرس 3 موضوعات
محتوى هذا الدرس مكتوب وينتظر المراجعة. يعرض المخطط أدناه ما سيغطيه، وسيُنشر بعد اعتماده.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
inject a payment provider through an interface. Prepares JNR-004-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Show
CheckoutServicecallingnew StripeClient()directly; tests need the network. - Extract the
PaymentProviderinterface. - Inject it through the constructor.
- Planned mistake: the interface exposes Stripe-specific types, so the core still depends on Stripe. Fix: use Shop's own types (
Money,Receipt) in the interface. - Write a fake provider for tests; run them without a network.
- Add a second provider without touching
CheckoutService.
اختبر فهمك
Where should the interface live?
أظهر الإجابة
In the core, not in the provider's code.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.