الـ Repositories: الوصول إلى البيانات خلف واجهة
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
hide storage behind an interface.
الموضوعات المخطط لها
- The repository interface says what you can store and find, not how.
- In this phase the implementation is in memory (a
Map); JNR-P4 swaps in a database. - The service depends on the interface, so it does not change when storage does.
@Repositorymarks the implementation.
تفاصيل المخطط المبدئي
عرض عملي
interface ProductRepository {
Optional<Product> findById(long id);
List<Product> findAll();
}اختبر فهمك
Why return Optional?
أظهر الإجابة
A product may not exist; the type says so.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.