यह नहीं पता कि इस ओप पैटर्न को क्या कहा जाता है लेकिन मैं एडा में एक ही पैटर्न कैसे कर सकता हूं? उदाहरण के लिए इस कोड:एडीए में इंटरफ़ेस को कैसे कार्यान्वित करें?
interface Vehicle{
string function start();
}
class Tractor implements Vehicle{
string function start(){
return "Tractor starting";
}
}
class Car implements Vehicle{
string function start(){
return "Car starting";
}
}
class TestVehicle{
function TestVehicle(Vehicle vehicle){
print(vehicle.start());
}
}
new TestVehicle(new Tractor);
new TestVehicle(new Car);
मेरी एडीए में असफल प्रयास: कैसे इसे ठीक तरह से ठीक करने के लिए?
with Ada.Text_IO;
procedure Main is
package packageVehicle is
type Vehicle is interface;
function Start(Self : Vehicle) return String is abstract;
end packageVehicle;
type Tractor is new packageVehicle.Vehicle with null record;
overriding -- optional
function Start(Self : Tractor) return string is
begin
return "Tractor starting!";
end Start;
type Car is new packageVehicle.Vehicle with null record;
overriding -- optional
function Start(Self : Car) return string is
begin
return "Car starting!";
end Start;
procedure TestVehicle(Vehicle : packageVehicle.Vehicle) is
begin
Ada.Text_IO.Put_Line("Testing a vehicle");
Ada.Text_IO.Put_Line(Start(Vehicle));
end;
Tractor0 : Tractor;
Car0 : Car;
begin
Ada.Text_IO.Put_Line(TestVehicle(Tractor0));
Ada.Text_IO.Put_Line(TestVehicle(Car0));
end Main;
संकलक का कहना है: बिल्डर परिणाम चेतावनी: "TestVehicle" की घोषणा बहुत देर हो चुकी है बिल्डर परिणाम चेतावनी: कल्पना "वाहन" की घोषणा
मुझे इंटरफेस के बारे में निश्चित नहीं है, लेकिन मुझे पता है कि आधार/पैरेंट पैकेज को गतिशील प्रेषण के साथ एक अलग पैकेज फ़ाइल में होना आवश्यक है। –