ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

In java which one is recommended to use i,e inheritance or composition ? give the reason.

user-image
تم إضافة السؤال من قبل Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
تاريخ النشر: 2013/11/27
Mohd shahnawaz khan
من قبل Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution

We recommended to use composition , as using extends key word it inheriits all the method from the base class(parent class), which in certain cases increases the complexity and length of the code, while using composition we call only the specific method as the condition  demand.

 

Bassem Zohdy
من قبل Bassem Zohdy , Senior Software Architect , HelpAG

the basic rule for that is:

inheritance = "is a" relationship

composition = "has a" relationship

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟