الربط اليدوي: المشكلة
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
see why creating collaborators inside a class hurts.
الموضوعات المخطط لها
- If
OrderServicedoesnew StripePayment()itself, it is glued to that class. - You cannot swap the payment provider or test the service with a fake.
- A dependency is any object a class needs to do its work.
- Hard-wiring spreads: change one constructor and many places break.
تفاصيل المخطط المبدئي
عرض عملي
class OrderService {
private final PaymentProvider payment = new StripePayment(); // glued
}اختبر فهمك
Why is this hard to test?
أظهر الإجابة
The service always uses the real provider; you cannot give it a fake.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.