Jump to content

Add a variable to a class instance at runtime: Difference between revisions

m
→‎{{header|Ada}}: Another case problem
No edit summary
m (→‎{{header|Ada}}: Another case problem)
Line 25:
=={{header|Ada}}==
Ada is not a dynamically typed language. Yet it supports mix-in inheritance, run-time inheritance and interfaces. These three allow us to achieve the desired effect, however questionably useful it could be. The example declares an interface of the class (Class). Then a concrete type is created (Base). The object E is an instance of Base. Later, at the run time, a new type Monkey_Patch is created such that it refers to E and implements the class interface per delegation to E. Monkey_Patch has a new integer member Foo and EE is an instance of Monkey_Path. For the user EE appears as E with Foo.
<lang Adaada>
with Ada.Text_IO; use Ada.Text_IO;
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.