ShittyCQRSPresentation



ShittyCQRSPresentation

0 10


ShittyCQRSPresentation

A shitty presentation for a shitty talk

On Github Ocramius / ShittyCQRSPresentation

I'm Marco!

@Ocramius

Final Classes

There is a blogpost:

http://bit.do/final-classes

Read it!

The end

I will not talk about it

Something important instead:

Our

Applications

Suck

We build massive piles of...

CRUD

Why, you ask?

We building behavior around state

class ContractController {
    public function putAction()
    {
        // validation

        $contract = $this->contracts->find($data['id']);

        // update the contract with data

        $this->contractService->save($contract);

        return $renderTemplate($contract);
    }
}
class ContractController {
    public function putAction()
    {
        // validation

        $contract = $this->contracts->find($data['id']);

        // update the contract with data

        $this->contractService->save($contract);

        return $renderTemplate($contract);
    }
}

terminating a contract is not the same as updating it

Our code does not express...

Intent

How do we code intent?

Commands

$command = new TerminateContract($contractId);

execute($command);

execute(new Accio('Beer'));

Commands express intent

Commands are simple

Commands are value objects

Who executes the commands?

Command Bus

$commandBus($command);

Who "returns" the data?

Read Model

$contractsArchive->find($contractId);

CQRS

Command Query Responsibility Segregation

class ContractController {
    public function terminateContractAction()
    {
        $commandBus(new TerminateContract($data['id']));

        return $renderTemplate($contracts->findById($data['id']));
    }
}
$commandHandler = function (TerminateContract $terminate) use (...) {
    $contract = $contracts->find($terminate->contractId);

    $contract->terminate();

    $registerEvent(new ContractWasTerminated($contract->id));
    $save($contract);

    $commandBus(new SendCancellationNotifications($contract->id));
};

CQRS has many advantages...

...I like the explicit intent

OH!

I also wrote a thing...

With @malukenho

Demo time!