Using the domain model included in the status template

There is a task associated with changing the state of an object . And I'm pretty confused thinking if this should be an event-based approach that includes something like CQRS , or can I use the State pattern and leave all the logic inside the entities.

I found an article that shows a domain model (or part of it) that uses a state template: http://www.prowareness.com/blog/?p=1448

The ordering system is pretty close to my domain model. So the example is wonderful. But still, I wonder if this is a good practice considering the MVC pattern, and if it can be implemented using RavenDB/NHibernate ?

EDITOR: rethought question

Let's look at an example:

First, here is a domain object called Idea :

 [Serializable] public class Idea : AbstractEntity<Guid> { private static IStateFactory stateFactory; private AbstractState state = new InitiatedState(); [Required, StringLength(150)] public String Title { get; set; } [Required] public String ProblemContext { get; set; } public DateTime CreatedOn { get; set; } public Guid InitiatorId { get; set; } [Required] public Decimal InvestmentAmount { get; set; } public Boolean IsInitiated { get { return this.state.IsInitiated; } } public Boolean IsRejected { get { return this.state.IsRejected; } } public Boolean IsUnderInitialAssessment { get { return this.state.IsUnderInitialAssessment; } } public Boolean IsConfirmedForImplementation { get { return this.state.IsConfirmedForImplementation; } } } 

While AbstractState :

 public abstract class AbstractState { public virtual Boolean IsInitiated { get { return true; } } public virtual Boolean IsRejected { get { return false; } } public virtual Boolean IsUnderInitialAssessment { get { return false; } } public virtual Boolean IsConfirmedForImplementation { get { return false; } } } 

and the state of the factory is defined as follows:

 public interface IStateFactory { AbstractState GetState(String state); } 

The final thought is to put the method:

 public void AlterState(String stateString) { this.state = stateFactory.GetState(stateString); } 
  • Is the design good? what are the pros and cons?
  • How about extensibility? From my point of view, you can expand / implement your own factory state. But if there is a change in AbstractState , everything changes accordingly.

Thanks!

+7
source share
3 answers

You may be interested in statelessness, the hierarchical state machine of Nicholas Bloomhardt. Read here my SO answer here regarding its features. Here is an example of a simple workflow example from my blog , and I'm currently using it with the Pipe and Filter template , and it works pretty well.

Edit

I also have an implementation that uses Stateless with RavenDB if you're interested.

+3
source

CQRS and state template are completely different things. A state template provides a way to implement a set of states or statuses for a single object, while CQRS is an architectural style. MVC has nothing to do with the state template and CQRS and is an architectural style for the presentation layer. You can use the state template in conjunction with NHibernate, however, the mapping will be non-trivial, and you will have to implement a custom IUserType to map to the corresponding field-based state class. RavenDB is very different from NHibernate, and matching with it will be a little easier, but it is a completely different database system.

+2
source

CQRS will be if you use sql to support the administration tool, and RavenDB to start the search. You will need to dump the data in RavenDB from Sql in this fictional CQRS script.

+1
source

All Articles