The Clean Architecture in php



Download 2,26 Mb.
Pdf ko'rish
bet49/179
Sana24.06.2021
Hajmi2,26 Mb.
#100337
1   ...   45   46   47   48   49   50   51   52   ...   179
Bog'liq
The-Clean-Architecture-in-PHP-Kristopher-Wilson

public function
createCar
();
public function
createTruck
();
}
And of course, we’ll need some concrete classes of the
AssemblyLineInterface
to create each
manufacturer’s line. These are our Concrete Factories:
class
ChevyAssemblyLine
implements
AssemblyLineInterface {
public function
createCar
() {
return new
ChevyMalibu();
}
public function
createTruck
() {
return new
ChevySilverado();
}
}
class
FordAssemblyLine
implements
AssemblyLineInterface {
public function
createCar
() {
return new
FordFiesta();
}
public function
createTruck
() {
return new
FordF250();
}
}
Now, our
Building
class can be supplied a specific
AssemblyLineInterface
, and start making
vehicles:


Design Patterns, A Primer
24
class
Building
{
protected
$assemblyLine
;
protected
$inventory
=
[];
public function
__construct
(
AssemblyLineInterface
$assemblyLine
) {
$this
->
assemblyLine
=
$assemblyLine
;
}
public function
createCars
() {
for
(
$i
= 0
;
$i
< 20
;
$i
++
) {
$this
->
inventory
[]
=
$this
->
assemlyLine
->
createCar
();
}
}
public function
createTrucks
() {
for
(
$i
= 0
;
$i
< 15
;
$i
++
) {
$this
->
inventory
[]
=
$this
->
assemlyLine
->
createTruck
();
}
}
}
We could call the code as such:
$building
=
new
Building(
new
FordAssemblyLine());
$building
->
createCars
();
The Abstract Factory pattern is useful when several different objects need to be created
independent from the system that creates them. If we’re only concerned with created one object,
then the Abstract Factory isn’t a very suitable solution.
Abstract Factory uses Factory Methods
You might have noticed that the
create()
methods in the assembly lines above look a
lot like Factory Methods. That’s because they are! The Abstract Factory Pattern actually
uses the Factory Method Pattern.
Repository Pattern
Repository is an object that allows for the retrieval and persisting of data to a data store. The
Repository Pattern is described in great detail in Eric Evan’s Domain-Driven Design: Tackling
Complexity in the Heart of Software:


Design Patterns, A Primer
25
A REPOSITORY represents all objects of a certain type as a conceptual set (usually
emulated). It acts like a collection, except with more elaborate querying capability.
Domain-Driven Design, Eric Evans, p. 151
When working with repositories, one stops thinking of getting data as “querying the database,”
but instead thinks of the process as retrieving data from the repository.
Repositories usually have methods to retrieve data and methods to persist data. They’re usually
called different things depending on the implementation.
Common retrieval methods include:

Download 2,26 Mb.

Do'stlaringiz bilan baham:
1   ...   45   46   47   48   49   50   51   52   ...   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