What are the advantages of interfaces and abstract classes? [closed]?

The main advantage of an interface is that it allows you to define a protocol to be implemented for an object to have some behavior. For example, you could have a Comparable interface with a compare method for classes to implement, and every class that implements it would have a standardized method for comparison. Abstract classes allow you to define a common base for several concrete classes.

For example, let's say you wanted to define classes representing animals: abstract class Animal { abstract protected function eat(); abstract protected function sleep(); public function die() { // Do something to indicate dying } } In this case, we define eat() and sleep() as abstract because different types of animals (e.g. Lion, bear, etc. ) that will inherit from Animal eat and sleep in different ways. But all animals die the same way (don't hold me to that), so we can define a common function for that. Using an abstract class helped us 1.

) declare some common methods that all Animals should have, and 2.) define common behavior for Animals. So, when you extend Animal, you won't have to rewrite the code for die().

The conceptual thing is quite independent of the language, you can read about it for here and in tons of sites about OOP.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions