Upload
hung-nguyen
View
135
Download
0
Embed Size (px)
Citation preview
Finternet-GroupThe Tao of LaravelCreated by / Hung Nguyen @hungnq1989
AgendaS.O.L.I.D princibleDependency injectionIoC containerHow to use IoC container in LaravelRepository & Unit of work pattern
S Single responsibility principle
O Open/closed principle
L Liskov substitution principle
I Interface segregation principle
D Dependency inversion principle
Single responsibility principleA class (method) should have only a single
responsibility (i.e. only one potential change inthe software's speci�cation should be able to
affect the speci�cation of the class)
Liskov substitution principleObjects in a program should be replaceable
with instances of their subtypes withoutaltering the correctness of that program.
That was initially introduced by Barbara Liskov in a 1987 conference keynote address entitled Dataabstraction and hierarchy.
Interface segregation principleMany client-speci�c interfaces are better than
one general-purpose interface.
Dependency inversion principleOne should “Depend upon Abstractions. Do
not depend upon concretions.”
“Dependency Injection” is a 25-dollar term fora 5-cent concept. […] Dependency injectionmeans giving an object its instance variables.
[…]. (James Shore)
It is not new!Inversion of Control Containersand the Dependency Injectionpattern
Martin Fowler 2004
Designing Reusable Classes Johnson andFoote
1988
Laravel o�cal documenthttps://laravel.com/docs/5.1/container
A deep understanding of the Laravel servicecontainer is essential to building a powerful,
large application, as well as for contributing tothe Laravel core itself.
Repository pattern & Unit ofwork
Repository Mediates between the domain and datamapping layers using a collection-likeinterface for accessing domain objects.
Unit ofWork
Maintains a list of objects affected by abusiness transaction and coordinates thewriting out of changes and the resolution ofconcurrency problems.
Repository patternMinimise duplicate query logic
Easier to cache data
Decouple your application with your persistenceframework
Clean architecture should be independent from framework
Unit of work patternA Unit of Work keeps track of everything you
do during a business transaction that canaffect the database. When you're done, it
�gures out everything that needs to be doneto alter the database as a result of your work.