Ada:包装概念 [英] Ada: packaging concepts
问题描述
这是我之前的帖子的后续内容:
This is a follow up of my earlier post here:
Rectangular
类型的实现是使用一个实现实现的,即,Rectangular_Method_1
,并且此实现需要规范文件和主体文件.
An implementation for the Rectangular
type was made using one implementation i.e. Rectangular_Method_1
and a specification file and a body file were required for this implementation.
如果我们想为用户提供另一个实现Rectangular_Method_2
,则可以将主文件rectangular_Form.ads
更改为
If we want to have another implementation Rectangular_Method_2
available to the user then the main file rectangular_Form.ads
can be changed to
-- 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
中对其进行调用.
If we create a second implementation Rectangular_Method_2
, Is there a need to create a separate specification file in addition to the compulsory new body for this new implementation? There is the need however to provide the same procedures/functions for Vector_Basis_r
, Set_Horz
, Get_Horz
etc in the new implementation so that we can call them in test_rectangular_form.adb
.
谢谢...
推荐答案
如果使用GNAT,则可以将GPR文件用于项目.您可以在其中更改特定软件包的文件名,例如:
If you use GNAT, you can use GPR files for the project. In there you can change the filename for specific packages, for example:
for Specification (Rectangular_Form) use "Rectangular_Method_1.ads";
for Implementation (Rectangular_Form) use "Rectangular_Method_1.adb";
您甚至可以根据环境变量进行设置.
you can even set this depending on an environment variable.
如果规格文件的外观都相同,则可以使用Rectangular_Form.ads
,并且只能使用上方的实施"行.
If your spec files all should look the same, you can use a Rectangular_Form.ads
and only use the Implementation line from above.
示例GPR文件可能如下所示:
An example GPR file could look like this:
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;
然后,您可以根据您的METHOD
变量使用gnatmake -P example.gpr
对其进行编译,或者对gnatmake使用-XMETHOD=...
参数,或者仅使用提供的默认值.
Then, you can use gnatmake -P example.gpr
to compile it depending on your METHOD
variable, or using a -XMETHOD=...
parameter for gnatmake or just use the provided default value.
example_*.adb
都应包含软件包Example
的主体,而不是Example_Normal
等.
The example_*.adb
should all contain the body of the package Example
, not Example_Normal
, etc..
这篇关于Ada:包装概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!