<分区>
我想知道我应该如何在我的应用程序 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