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

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

متابعة

You are free to use abstract class or interface. Tell me a scenario where you would use interface or abstract class? How would you decide?

user-image
تم إضافة السؤال من قبل Firoz Ahmad , Software Engineer , Tata Consultancy Service Limited
تاريخ النشر: 2017/05/09

Interface and abstract class are made for different purposes. For the simple example, suppose you are implementing play behaviour in the Football player and cricket player. Then first you will make Class Player, then make FootballPlayer extending Player, similarly CricketPlayer.

But if you are implementing play behaviour in Human and Animal then, for this scenario abstract class is not a good choice, you have to make an Interface EatableInterface which has eat method and Human and Animal class will implement that interface.

for other uses of the interface, you can learn about some design patterns, in design patterns interface is heavily used.

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

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