Closed 。这个问题是基于意见的 。目前不接受答案。
这是我之前的帖子的后续内容:
Ada:了解私有类型并了解包装
一个实现Rectangular
类型是使用一种实现来制作的,即Rectangular_Method_1
此实现需要一个规范文件和一个主体文件。
如果我们想要另一个实现Rectangular_Method_2
然后是主文件可供用户使用rectangular_Form.ads
可以改为
-- with Rectangular_Method_1;
-- package Rectangular_Form renames Rectangular_Method_1;
with Rectangular_Method_2;
package Rectangular_Form renames Rectangular_Method_2;
问题
这是软件工程中允许另一种实现的正确方法吗?test_rectangular_form.adb
对于不同的实现仍然相同吗?
如果我们创建第二个实现Rectangular_Method_2
,除了这个新的实施的强制性新主体之外,是否还需要创建一个单独的规范文件?然而,需要提供相同的过程/功能Vector_Basis_r
, Set_Horz
, Get_Horz
等在新的实现中,以便我们可以调用它们test_rectangular_form.adb
.
谢谢...
如果您使用 GNAT,则可以在项目中使用 GPR 文件。您可以在其中更改特定包的文件名,例如:
for Specification (Rectangular_Form) use "Rectangular_Method_1.ads";
for Implementation (Rectangular_Form) use "Rectangular_Method_1.adb";
您甚至可以根据环境变量进行设置。
如果您的规范文件看起来都应该相同,您可以使用Rectangular_Form.ads
并且仅使用上面的实现行。
GPR 文件示例如下所示:
project Example is
type Methods is ("normal", "something_else");
Method : Methods := external ("METHOD", "normal");
package Naming is
case Method is
when "normal" =>
for Implementation ("Example") use "example_normal.adb";
when "something_else" =>
for Implementation ("Example") use "example_something.adb";
end case;
end Naming;
end Example;
然后,您可以使用gnatmake -P example.gpr
根据你的情况来编译它METHOD
变量,或使用-XMETHOD=...
gnatmake 的参数或仅使用提供的默认值。
The example_*.adb
都应该包含包的主体Example
, not Example_Normal
, etc..
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)