Skip to content

Instantly share code, notes, and snippets.

@gemmadlou
Last active August 9, 2018 07:52
Show Gist options
  • Select an option

  • Save gemmadlou/3523c4e41467829d614ef8a8edcfa283 to your computer and use it in GitHub Desktop.

Select an option

Save gemmadlou/3523c4e41467829d614ef8a8edcfa283 to your computer and use it in GitHub Desktop.
DDD
  • Model everything as value objects first eg. even customers if that was part your domain. When you realise they need an identity (lifecycle), then turn them into entities.

Resources

https://skillsmatter.com/skillscasts/1981-simple-is-better

http://stackoverflow.com/questions/12584966/where-to-bind-dto-into-domain-model

http://www.wpexplorer.com/wordpress-page-templates-plugin/

https://medium.com/@naveennegi/domain-driven-design-in-elixir-4dc416ac0a36

Hexagonal Architecture

Ports & Adapters

https://youtu.be/u6oTg5oRH24?t=32m43s

https://www.slideshare.net/profpv/hexagonal-architecture-in-php

We're Doing The Repository Pattern Wrong

http://blog.gauffin.org/2013/01/repository-pattern-done-right/

http://how-it-can-in-nodejs.blogspot.co.uk/2016/04/node-js-rest-api-with-unit-of-work-and.html

Best Repo Example

With DAO https://www.slideshare.net/Yaboomaster1/save-repository-from-save

Repos

Hydrating entities

http://mohdhallal.github.io/blog/2013/10/05/entity-hydration-done-right/

https://lostechies.com/gabrielschenker/2015/04/28/ddd-applied/

Unit of Work & The Repository Pattern

http://stackoverflow.com/questions/30066247/updating-records-using-a-repository-pattern-with-entity-framework-6

http://odetocode.com/blogs/scott/archive/2010/06/13/repositories-and-the-save-method.aspx

BDD

BDD is examples you use in conversation to illustrate behaviour - https://www.youtube.com/watch?v=83GbyDpJDI4

Using real numbers and trying to get the same conclusion as the developer and as the client, means the business rules are being accurately translated

Functional DDD

https://youtu.be/Up7LcbGZFuo?t=37m8s

<?php
class Title {
protected $title;
public function __construct($title) {
$this->title = $title;
}
public function string() {
return $this->title;
}
}
class Post {
private $title;
public function __construct(Title $title) {
$this->title = $title;
}
public function title() {
return $this->title;
}
}
echo '<pre>'; print_r(new Post(new Title('Bake')));
<?php
/**
* Before titles could be as long as they like. Now they can only be less than 5 characters
* The problem is when you hydrate the domain object - certain rules were changed. And now
* your invariant has changed, rehydration throws an exception. To get passed that, create new
* class which extends your up-to-date domain variant. Now, this value object is invariant agnostic. It will
* also inherit all the child methods from its parent class.
*/
class Title {
protected $title;
public function __construct($title) {
if (strlen($title) > 5) {
throw new Exception('Title is too long');
}
$this->title = $title;
}
public function string() {
return $this->title;
}
}
final class AgnosticTitle extends Title {
public function __construct($title) {
$this->title = $title;
}
}
class Post {
private $title;
public function __construct(Title $title) {
$this->title = $title;
}
public function title() {
return $this->title;
}
}
echo '<pre>'; print_r(new Post(new AgnosticTitle('My super long title which came out of the database')));
echo '<pre>'; print_r(new Post(new Title('Bake')));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment