开发者

Design Pattern For Tracking/Statuses

What is the closest design pattern for something like an issue tracker?

You have an object that can be one of various statuses: open, closed, in production.

Actions can be performed based on the current status.

My initial modeling looks a little like this:

class Status
    - next_status (None or Status)
    - previous_status (None or Status)
    - actions (set of Actions)

class Action
    - name (string)
    - description (string)

With the possibility of grouping actions and assigning the group to a Status. Similar to most permissions models you could say.

Was just looking for input on what pattern this most follows so I can research it some开发者_Python百科 more. Thanks!


You're representing a finite state machine (FSM), really a flowchart, but your class design looks like a doubly-linked list. If Status determines the prior and next Status this is workable, but in most systems this is untrue. Consider a Status of "open" in your example, is it possible that the next could be either "closed" or "in production"?

If both Statuses are possibilities consider changing the Status object and adding a Transition (or perhaps replacing Action?) object to your class hierarchy:

class Status 
    - transitions (Transition[])

class Transition 
    - from (Status)
    - to (Status)

Here Status knows about what Transitions are possible (e.g. "opened" may transition to "closed" or "in production"). In this way you represent the FSM as a directed graph. Also, in my own experience it's usually not important to have the an entity know where it just came from thus the removal of prior_status. Instead the path can be captured through audit logging / database table capturing history.


I am thinking combination of State + Command

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜