dddshelf / last-wishes

Last Wishes is a PHP application written following Domain-Driven Design approach. It's one of the sample applications where you can check the concepts explained in the "Domain-Driven Design in PHP" book.
https://leanpub.com/ddd-in-php
660 stars 120 forks source link

What is a difference between this two methods? #10

Closed tworzenieweb closed 8 years ago

tworzenieweb commented 8 years ago

In User aggregate there are two different methods for creating wishes. What are the use cases for each?

As I guess the first one is perfect for persisting as a single.

    public function makeWishNotBeingAnAggregate(WishId $wishId, $address, $content)
    {
        $newWish = new Wish(
            $wishId,
            $this->id(),
            $address,
            $content
        );
        DomainEventPublisher::instance()->publish(
            new WishWasMade(
                $newWish->id(),
                $newWish->userId(),
                $newWish->address(),
                $newWish->content()
            )
        );
        return $newWish;
    }
    public function makeWish(WishId $wishId, $address, $content)
    {
        if (count($this->wishes) >= self::MAX_WISHES) {
            throw new NoMoreWishesAllowedException();
        }
        $this->wishes[] = new Wish(
            $wishId,
            $this->id(),
            $address,
            $content
        );
    }
carlosbuenosvinos commented 8 years ago

None, I was trying to add in the same application both examples of User and Wish conforming and not conforming an aggregate in order to explain the design differences. But it's WIP.

2016-04-18 8:36 GMT+02:00 Łukasz Adamczewski notifications@github.com:

In User aggregate there are two different methods for creating wishes. What are the use cases for each?

As I guess the first one is perfect for persisting as a single.

public function makeWishNotBeingAnAggregate(WishId $wishId, $address, $content)    {        $newWish = new Wish(            $wishId,            $this->id(),            $address,            $content        );        DomainEventPublisher::instance()->publish(            new WishWasMade(                $newWish->id(),                $newWish->userId(),                $newWish->address(),                $newWish->content()            )        );        return $newWish;    }    public function makeWish(WishId $wishId, $address, $content)    {        if (count($this->wishes) >= self::MAX_WISHES) {            throw new NoMoreWishesAllowedException();        }        $this->wishes[] = new Wish(            $wishId,            $this->id(),            $address,            $content        );    }

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/dddinphp/last-wishes/issues/10

Carlos Buenosvinos Zamora carlos.buenosvinos@gmail.com 659730605

url: http://carlosbuenosvinos.com twitter: buenosvinos skype: carlos.buenosvinos gtalk: carlos.buenosvinos@gmail.com