انتقل إلى المحتوى
أمين أبوزيد
قيد المراجعةJNR-001-L08

عرض عملي: تحديث فئة Java قديمة خطوة بخطوة

  • الدرس 8 من 8
  • 11 دقيقة قراءة
  • Junior
في هذا الدرس 3 موضوعات

محتوى هذا الدرس مكتوب وينتظر المراجعة. يعرض المخطط أدناه ما سيغطيه، وسيُنشر بعد اعتماده.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

turn an old getter/setter class into modern Java. Prepares JNR-001-LAB1.

تفاصيل المخطط المبدئي

خطوة بخطوة

  1. Show the legacy Product class: fields, getters, setters, equals, hashCode, toString.
  2. Run the existing tests so you have a safety net.
  3. Replace the class with a record; remove the setters and fix the callers.
  4. Planned mistake: the class had a List<String> tags. Passing a list that the caller changes later breaks immutability. Fix: copy it in the compact constructor with List.copyOf.
  5. Replace the if/else instanceof chain with a sealed interface and a switch.
  6. Run the tests again and list what you removed.

اختبر فهمك

Why copy the list?

أظهر الإجابة

A record is shallow; a shared list can still be changed from outside.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.