عرض عملي: إعادة هيكلة دالة طويلة مع بقاء الاختبارات خضراء
في هذا الدرس 3 موضوعات
محتوى هذا الدرس مكتوب وينتظر المراجعة. يعرض المخطط أدناه ما سيغطيه، وسيُنشر بعد اعتماده.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
shrink a long checkout method step by step. Prepares JNR-003-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Run all tests: green.
- Rename unclear variables with the IDE.
- Extract Method for the discount block; run tests; commit "Extract calculateDiscount".
- Planned mistake: also change the rounding "while we are here"; a test turns red. Fix: undo, keep the commit pure, and do the change later in a separate commit.
- Replace
doublemoney with theMoneyrecord where tests allow. - Show the final method: short, readable, tests green.
اختبر فهمك
Why undo the rounding change?
أظهر الإجابة
A refactoring commit must not change behavior.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.