c++ - 记录接口(interface)

标签 c++ interface documentation

<分区>

我想知道我应该如何在我的应用程序 IResource 中记录一个接口(interface)。由于我编写的是引擎而不是库,所以我认为文档应该提供有关如何编写接口(interface)实现的指南;可以吗?

还有,你能不能看看我的界面,看看评论是否足够清晰?

/**
    Interface that should be implemented by all resources. Implementing
    this interface is necessary for compatibility with the ResourceManager
    class template.

    \note Documentation of this interface includes guidelines on how
    implementations should be written.

    \see ResourceManager
                                                                              */
class IResource
{
  public:
    /**
        Loads resource data from a file. If data is already loaded,
        the function should return immediately.

        \throw std::exception Should throw on any failure to load the
        resource. If the resource is already loaded, don't throw, just
        return (as previously indicated).

        \note Access to this function should also be provided directly
        from a constructor. That constructor should catch any exceptions
        and throw them further to its caller.
                                                                              */
    virtual void loadFromFile(const std::string& file) = 0 ;
    /**
        All general guidelines from loadFromFile() also apply to this
        function. Additionally, the resource should not take possession of
        the buffer; the buffer should be safe to delete after loading.
                                                                              */
    virtual void loadFromMemory(const char* buffer, std::size_t size) = 0;
    /**
        Frees the data currently held by the resource object. Should
        return immeditelly if no data is loaded.
                                                                              */
    virtual void free() = 0;
    virtual bool isLoaded() const = 0;
};

编辑:打开相关讨论。

主要是在 Johann Gerell's answer 评论部分的对话之后,我在 programmers.stackexchange 上开了一个相当长的线程。你可以在这里查看:
> Single-responsibility and custom data types

最佳答案

您已经很好地记录了意图,这是一个很好的开始。

缺少一些东西:

  • 你没有记录论据。它们是不言自明的,但我可能有点迂腐(doxygen 也是如此)。
  • isLoaded 做什么?
  • 关闭 doxygen 中的继承文档功能。虽然您的评论对接口(interface)类有效,但它们对实现该接口(interface)的某些类无效。

关于c++ - 记录接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6245429/

相关文章:

go - 在 go 函数注释中编写代码块的正确方法是什么?

c++ - 如何解决 Visual C++ 编译器中的错误 C1001?

c++ - 如何在 "this"上调用 operator() ?

c++ - 如何控制后台进程/守护进程

Java 反射 : Call method from Interface name

json - 1 个接口(interface),2 个包,相同的结构变量名称但不同的 json 命名约定

swift - 如何记录可选的闭包函数参数?

Python Wiki 样式文档生成器

c++ - 将对话框过程作为方法绑定(bind)到自定义类

java - Java 8 中的抽象类和接口(interface)有什么区别?