Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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
Question ajoutée par Firoz Ahmad , Software Engineer , Tata Consultancy Service Limited
Date de publication: 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.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?