有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java和C如何模拟头文件构造?

Programming Language Pragmatics 4ed by Michael Scott说Java和C#可以模拟C和C++中的头文件:

To mimic the software engineering practice of early header file construction, a Java or C# design team can create skeleton versions of (the public classes of) its packages or namespaces, which can then be used, concurrently and independently, by the programmers responsible for the full versions.

这意味着什么:

  • “创建(的公共类)的骨架版本” 它的包或名称空间“

  • “由负责完整版本的程序员同时独立使用”

谢谢


共 (2) 个答案

  1. # 1 楼答案

    这意味着创建没有实现的类的版本。在C#中,通常的方法是让所有成员抛出^{。例如:

    public class Database
    {
        public IEnumerable<Employee> GetAllEmployees() => throw new NotImplementedException();
    }
    

    类似的方法是只创建接口,而不创建实现接口的类,例如:

    public interface IDatabase
    {
        IEnumerable<Employee> GetAllEmployees();
    }
    

    尽管这种方法在某些方面限制了您的设计,例如,您不能将其用于具有公共静态成员的类型

    使用这两种方法,其他程序员可以开始编写使用Database/IDatabase的代码,即使实现尚未完成。这种做法的一个问题是,这些程序员不能测试他们的代码,除非他们创建自己的测试实现(例如使用模拟)

  2. # 2 楼答案

    "create skeleton versions of (the public classes of) its packages or namespaces"

    这意味着设计人员在编写Java或C源代码时,遗漏了部分或全部实现细节;e、 g.接口

    "used, concurrently and independently, by the programmers responsible for the full versions"?

    这意味着程序员编写其余的代码