indiehd / velkart

An extensible shopping cart, order management, and payment processing system built upon clean-coding principles and designed for Laravel.
GNU Affero General Public License v3.0
1 stars 4 forks source link

Is there a way to implement Observer pattern for repository events without introducing tight coupling to Eloquent? #19

Open cbj4074 opened 4 years ago

cbj4074 commented 4 years ago

Rather than modify related models "manually" within the repository methods, like this

https://github.com/indiehd/velkart/blob/7dd235003eecc2ffe05d74c56e3b110e4f1ddf6c/src/Repositories/Eloquent/ProductRepository.php#L56-L58

would it be better to use an Observer pattern with an event-driven approach, more like we do here?

https://github.com/indiehd/web-api/blob/26598927babfa285e013bdf59d0c1628fd98df6f/app/Observers/AlbumObserver.php#L38-L49

cbj4074 commented 4 years ago

After discussing it with other contributors, we should not do what we did in the second link because that implementation calls methods on concrete classes, which results in tight coupling.

Instead, we should always use the related models' repositories.