Strategy
في هذا الدرس 4 موضوعات
محتوى هذا الدرس مكتوب وينتظر المراجعة. يعرض المخطط أدناه ما سيغطيه، وسيُنشر بعد اعتماده.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
swap an algorithm without changing the caller.
الموضوعات المخطط لها
- Problem: many
if/elsebranches choose between ways of doing one thing. - Define an interface; each way is a class (or a lambda).
- The caller holds the interface and does not care which one.
- Example: shipping cost: standard, express, pickup.
- JDK example:
Comparatorpassed tosort.
تفاصيل المخطط المبدئي
عرض عملي
interface ShippingStrategy { Money cost(Order o); }
class Express implements ShippingStrategy { ... }
Money total = strategy.cost(order);اختبر فهمك
What does Strategy replace?
أظهر الإجابة
A chain of if/else or a switch choosing an algorithm.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.