viewbarcode.com

The Ada 2005 OOP model in Software Creation PDF417 in Software The Ada 2005 OOP model




How to generate, print barcode using .NET, Java sdk library control with example project source code free download:
10.1 The Ada 2005 OOP model use none none integration toconnect none for none .NET Instances of t none none hese are created in the usual way and the subprograms (methods) are called as shown below.. declare My_Obj ect : Object_Type; -- a new instance of the object type My_Parameter : Parameter_Type; begin ...

Op1(My_Object, My_Parameter); -- object passed as a parameter to the subprogram ...

end;. Ada 2005 still allows this style but also supports the following. declare My_Obj ect : Object_Type; My_Parameter : Parameter_Type; begin ...

My_Object.Op1(My_Parameter); -- object name prefixes the subprogram name ..

. end;. This makes the none for none program easier to understand and eases the transition for programmers used to other OOP languages such as C++ and Java. Important The introduction of the pre x notion is more than just syntactic sugar. It eases the naming of methods when complex inheritance hierarnote: chies are used, as there is no need to name all the associated packages in with clauses.

. 10.1.2 Interfa ces An interface is a type that has no state.

In Ada 95, it could be represented as an abstract tagged type without any components. For example, the following abstract type provides the interface needed to print an object. Any types that extend from this type must provide an implementation of the Print subprogram.

Hence objects of all types in the hierarchy rooted in the Printable type can be printed. These can collectively be accessed by the Any Printable type given below..

package Printa none for none ble is type Printable_Interface is abstract tagged null record; procedure Print(X : in Printable_Interface) is abstract; type Any_Printable is access all Printable_Interface Class; end Printable;. Object-oriented programming and tasking Ada 2005 change:. Ada 95 does no t allow multiple inheritance; therefore, it is not possible to have a derived type that can support multiple interfaces via the abstract tagged type mechanism. Ada 2005 has solved this problem by introducing a language construct that is essentially an abstract tagged typed with null components. This is called an interface.

All primitive operations on an interface type must be abstract or null Ada 2005 has also introduced syntax for a null procedure: e.g. procedure X (P: Parameter Type) is null; .

This acts as shorthand for a procedure with a single enclosed null statement.. The above inte none none rface is represented in Ada 2005 as:. package Printa ble is type Printable_Interface is interface; procedure Print(X: in Printable_Interface) is abstract; type Any_Printable is access all Printable_Interface Class; end Printable;. Warning:. Although the i nspiration for Ada interfaces comes from the Java language, they cannot be used in exactly the same way as Java interfaces but should be thought of as abstract types. In particular, it is not possible to de ne an arbitrary method that takes as a parameter an interface (as it is in Java). The equivalent in Ada 2005 is to de ne the parameter type as a class-wide type or class-wide access type rooted at the Ada interface (as illustrated above with access types).

Hence, Ada makes explicit what Java leaves as implicit.. For example, a none none Java-like comparable interface would be represented as:. package Compar able is type Comparable_Interface is interface; type Any_Comparable is access all Comparable_Interface Class; function Compares(This: Comparable_Interface; To_That: in Comparable_Interface Class) return Boolean is abstract; end Comparable;. Here the rst none none parameter to the Compares method is the controlling (dispatching) parameter. The second parameter represents the object to be compared with. The function returns true if the object components are equal in value.

Now consider an object that wants to support the above two interfaces (or implement them, as Java calls it). It simply declares a new tagged type from the two interface types and provides the primitive operations needed to support the interfaces..

10.1 The Ada 2005 OOP model with Printable none none ; use Printable; with Comparable; use Comparable; package Printable_and_Comparable is type Object is new Printable_Interface and Comparable_Interface with private;. overriding pro cedure Print (This : Object); overriding function Compares (This : Object; To_That : Comparable_Interface Class) return Boolean; private type Object is new Printable_Interface and Comparable_Interface with record X : Integer := 0; -- say end record; end Printable_and_Comparable;. The implementa none for none tion is shown below:. with Ada.Text_ IO; use Ada.Text_IO; with Ada.

Tags; use Ada.Tags; package body Printable_and_Comparable is procedure Print (This : Object) is begin Put_Line (This.X Img); end Print; function Compares (This : Object; To_That : Comparable_Interface Class) return Boolean is begin return To_That in Object Class and then This.

X = Object(To_That).X; end Compares; end Printable_and_Comparable;. Of course, if none for none there is a pre-existing type that needs to become printable and comparable:. package My_Obj ects is type My_Object is tagged record X : Integer; end record; end My_Objects;. It is possible none none to create a new tagged type that is derived from the My Object tagged type that can now be printed and compared.. with Printable , Comparable, My_Objects; use Printable, Comparable, My_Objects; package My_Printable_And_Comparable_Objects is type My_Printable_And_Comparable_Object is new My_Object and Printable_Interface and Comparable_Interface with null record;.
Copyright © viewbarcode.com . All rights reserved.