CQS, CQRS, MVC, HTTP

CQS

Command Query Separation
Asking a question should not change the answer

http://en.wikipedia.org/wiki/Command-query_separation


class ProductService
{
    public function getProduct($id)
    {
        if (!$this->_productRepository->has($id)) {
            $this->_productRepository->create($id);
        }
        return $this->_productRepository->get($id);
    }
}

class ProductService
{
    public function getProduct($id)
    {
        if (!$this->_productRepository->has($id)) {
            throw new NotFoundException();
        }
        return $this->_productRepository->get($id);
    }
    
    public function createProduct($id, $data)
    {
        $this->_productRepository->create($id, $data);    
    }
}

CQRS

Command Query Responsibility Segregation

CQRS Definition?

... see CQS

NOT CQRS

CQRS

http://martinfowler.com/bliki/CQRS.html

MVC

MVC

  • Controller is used only for commands
  • View is used only for queries
  • HTTP

    • GET, HEAD - safe; don't change state
    • POST, PUT, DELETE - unsafe; change system state

    Server MVC

    Wrong

    Server MVC 2

    Wrong

    Proper Server MVC + HTTP

    Proper SeRVER MVC + HTTP + CQRS

    CQS, CQRS, MVC, HTTP

    By Anton Kril

    CQS, CQRS, MVC, HTTP

    • 2,632
    Loading comments...

    More from Anton Kril