Ada封装和私有类型 [英] Ada encapsulation and private types

查看:67
本文介绍了Ada封装和私有类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从编译器的角度来看,在程序包规范中声明Ada类型或在主体内部执行Ada类型之间有什么区别?

From the compiler's point of view, what's the difference between declaring an Ada type in a package spec or doing it inside the body?

推荐答案

通常,使声明(类型,以及常量或子程序之类的其他项)尽可能本地化是一种好习惯.在您的情况下,如果仅在主体中使用该类型,而不为包规范的用户使用该类型(即使是私有类型),请将其放入主体中.此外,如果仅在主体的子程序中使用它,则将其放在该子程序中.它减少了名称冲突的可能性,并使事情变得更清楚.总而言之,编译器的优点(在代码中给定点处的标识符集较小)与程序员相同.

Generally it is a good practice to make declarations (of types, but also other items like constants or subprograms) the most local possible. In your case if the type is used only in the body and not for users of your package specification (even as private type), put it in the body. Furthermore, if it is used only in a subprogram of the body, put it in that subprogram. It reduces the odds of name clashes and makes things clearer. To summarize, the advantages for the compiler (smaller identifier sets at given points in the code) are the same as for the programmer.

这篇关于Ada封装和私有类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆