انعكاس التحكم (Inversion of control)
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
explain IoC and dependency injection without Spring.
الموضوعات المخطط لها
- Inversion of control (IoC): someone else creates and connects your objects; you stop doing it.
- Dependency injection (DI) is the common form: dependencies are handed in from outside.
- The class declares what it needs; it does not decide which implementation.
- Depend on an interface (
PaymentProvider), not a concrete class.
تفاصيل المخطط المبدئي
عرض عملي
class OrderService {
private final PaymentProvider payment;
OrderService(PaymentProvider payment) { this.payment = payment; }
}
var service = new OrderService(new StripePayment()); // main() acts as the "container"اختبر فهمك
Who decides which implementation is used now?
أظهر الإجابة
The caller or container, not the service.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.