The Clean Architecture in php



Download 2,26 Mb.
Pdf ko'rish
bet62/179
Sana24.06.2021
Hajmi2,26 Mb.
#100337
1   ...   58   59   60   61   62   63   64   65   ...   179
Bog'liq
The-Clean-Architecture-in-PHP-Kristopher-Wilson

Breaking up Classes
In order to apply the SRP principle to existing classes, or even when creating new classes, it’s
important to analyze the responsibility of the class. Take for instance a customer invoicing class,
like the one we looked at in the previous chapter:
class
InvoicingService
{
public function
generateAndSendInvoices
() {}
protected function
generateInvoice
(
$customer
) {}
protected function
createInvoiceFile
(
$invoice
) {}
protected function
sendInvoice
(
$invoice
) {}
}
Already it’s plainly obvious that this class has more than one responsibility. Just looking at the
method name of
generateAndSendInvoices()
reveals two. It’s not always readily apparent from


SOLID Design Principles
33
class and method names how many responsibilities there are, though. Sometimes it requires
looking at the actual code within those methods. After all, the method could have simply been
named
generateInvoices()
, hiding the fact that it was also responsible for delivering those
invoices.
There are at least four separate responsibilities of this class:
1. Figuring out which invoices to create
2. Generating invoice records in the database
3. Generating the physical representation of the invoice (i.e.: PDF, Excel, CSV, etc)
4. Sending the invoice to the customer via some means
In order to fix this class to conform to SRP, we’ll want to break it up into smaller, fine
tuned classes, each representing one of the four responsibilities we identified above, plus the
InvoicingService
class that ties this all together.

Download 2,26 Mb.

Do'stlaringiz bilan baham:
1   ...   58   59   60   61   62   63   64   65   ...   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