开发者

How to design a robust Status class for an API or framework in OOP?

I'm currently working on generating an API from an ad-hoc enterprise solution and I'm stuck in the process of generating a both generic and expressive class for handling the status for operations in related classes.

In a nutshell, what I want to know is which are the standards (or best practices) on designing a Status handler. What I want to achieve is that methods and classes that belong to a common 'module', all of them return and handle status messages that belong to a defined status structure, so the different status messages are not that dependent of implementation.

A possible solution would be: - Create a Status Class in the module that defines a series of status numbers as Constants - The Status class would manage onl开发者_如何学JAVAy those defined status numbers and would define status messages for each one. - The methods of the module that require status handling return an instance of Status, that is handled in higher layers of the module, and not hard coded in each method.

Any suggestions for better models? How does good API's manage this?


Use a Status enum, not a class of constants. It will provide you with a well defined and properly constrained set of status values. It can also have a getMessage() as well as any other status related functionality.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜