The Clean Architecture in php



Download 2,26 Mb.
Pdf ko'rish
bet87/179
Sana24.06.2021
Hajmi2,26 Mb.
#100337
1   ...   83   84   85   86   87   88   89   90   ...   179
Bog'liq
The-Clean-Architecture-in-PHP-Kristopher-Wilson

class
AddressController
extends
AbstractController {
protected
$geocoder
;
public function
__construct
(BillsGeocoder
$geocoder
) {
$this
->
geocoder
=
$geocoder
;
}
public function
validateAddressAction
() {
$address
=
$this
->
vars
()
->
fromPost
(
'address'
);
$isValid
=
$this
->
geocoder
->
geocode
(
$address
)
!==
false
;
}
}
We’re using some dependency injection into the controller, which is great. This is a step in the
right direction and solves some problems for us, but it’s still strongly coupling our controller to
whoever Bill is. What if he goes away? What if you figure out
DavesGeocoder
is so much better
because it supports Zip+4, which
BillsGeocoder
didn’t? And what if you just happen to use
this geocoder all over the place and now you have to go update all those references? What if
DavesGeocoder
doesn’t have a
geocode()
method but instead has
validateAddress()
. You’ve
run into a refactoring nightmare.
Setting up the Adapter
Recall back to our discussion on design patterns, specifically the Adapter Pattern. Adapters are
perfectly suited to solve this problem as they allow us to “wrap” the functionality of the third
party code, and by doing so, make it conform to an interface we define, so that we can inject
that adapter to fulfill the interface.
This is exactly what we did when we discussed the Adapter Pattern. We started by defining our
interface:


Abstracting with Adapters
58

Download 2,26 Mb.

Do'stlaringiz bilan baham:
1   ...   83   84   85   86   87   88   89   90   ...   179




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish