Abstract or Interface?
Anyone know what are abstract classes and interfaces?
Not as language construct but conceptually.
In object oriented design matters, we should separate multiple responsibilities classes.
But how do we connect them?
Should we use abstract classes or interfaces?
Why do we use abstract class?
Why do we use interface?
Anyone know please?
Thanks in advance.
An abstract class is generally an interface in C++.
It's good to use abstract classes since they often contain common functionality used by several classes. There is also no sense in being able to create an abstract class, which is why it is marked abstract, thus becoming an interface, something you cannot create an instance of, only derive from.
Actually abstract classes == interface isn't it?
Why do so much language separating "abstract class" and "interface" ?
What I can say for sure is that it's called an abstract class in the language, but an interface conceptually.
So you really call them whichever.
They are called an Interface because these classes main objective is to define a protocol, or a set of rules for other classes deriving from it to use. The abstract class itself is not meant to be instantiated.
An abstract class can define some of it's member functions, but as long as it has at least one pure virtual function (without being defined) then it's an abstract class; an interface has all pure virtual functions (no functions are defined).
In Java they make the distinction easier by having separate 'abstract' & 'interface' keywords.
Google brings up some results.