In Ada, we can implement interfaces using abstract types and tagged types. Here’s an example of geometric shapes using Ada’s object-oriented features.
In this Ada example, we define an abstract Geometry type with abstract methods Area and Perim. We then create two concrete types, Rect and Circle, which inherit from Geometry and implement these methods.
The Measure procedure is generic and can work with any type derived from Geometry. This is similar to the concept of interfaces in other languages.
To run this program, save it as interfaces.adb and compile it using an Ada compiler such as GNAT:
The output will show the area and perimeter calculations for both the rectangle and circle.
This example demonstrates how Ada’s object-oriented features can be used to implement interface-like behavior, allowing for polymorphism and code reuse.