digital_hog
digital_hog

Reputation: 202

Ada: Difference between interface and abstract tagged type?

According to Adaic, an interface in Ada is defined as a "tagged type with no components and no concrete operations". It can be used for multiple inheritance. In contrast, an abstract type is a tagged type intended for use as an ancestor of other types, but which is not allowed to have objects of its own.

Is the essential difference between both just the multiple inheritance feature of the interface? Can the types otherwise be used interchangeably?

Upvotes: 2

Views: 451

Answers (2)

Attila Molnár
Attila Molnár

Reputation: 1

I think that there are situations where it is very hard if not impossible to solve problems without interfaces. A very traditional example is dependency injection.

Upvotes: 0

Jeffrey R. Carter
Jeffrey R. Carter

Reputation: 3358

An interface cannot have any components, and all operations for one must be abstract. An abstract tagged type may have components and may have non-abstract operations.

A concrete type may extend multiple interfaces, but may only extend a single tagged type.

"IMHO, Interfaces are worthless." Randy Brukardt, ARG member and ARM editor

Upvotes: 7

Related Questions