Abstract Factory
This commit is contained in:
parent
0f4618edf5
commit
7fe2402ff3
113
.gitignore
vendored
113
.gitignore
vendored
@ -28,19 +28,6 @@
|
|||||||
.idea/**/gradle.xml
|
.idea/**/gradle.xml
|
||||||
.idea/**/libraries
|
.idea/**/libraries
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
||||||
# since they will be recreated, and may cause churn. Uncomment if using
|
|
||||||
# auto-import.
|
|
||||||
# .idea/artifacts
|
|
||||||
# .idea/compiler.xml
|
|
||||||
# .idea/jarRepositories.xml
|
|
||||||
# .idea/modules.xml
|
|
||||||
# .idea/*.iml
|
|
||||||
# .idea/modules
|
|
||||||
# *.iml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# CMake
|
# CMake
|
||||||
cmake-build-*/
|
cmake-build-*/
|
||||||
|
|
||||||
@ -77,104 +64,8 @@ fabric.properties
|
|||||||
# Android studio 3.1+ serialized cache file
|
# Android studio 3.1+ serialized cache file
|
||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
### PhpStorm+iml template
|
### This project
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
||||||
|
|
||||||
# User-specific stuff
|
|
||||||
|
|
||||||
# AWS User-specific
|
|
||||||
|
|
||||||
# Generated files
|
|
||||||
|
|
||||||
# Sensitive or high-churn files
|
|
||||||
|
|
||||||
# Gradle
|
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
||||||
# since they will be recreated, and may cause churn. Uncomment if using
|
|
||||||
# auto-import.
|
|
||||||
# .idea/artifacts
|
|
||||||
# .idea/compiler.xml
|
|
||||||
# .idea/jarRepositories.xml
|
|
||||||
# .idea/modules.xml
|
|
||||||
# .idea/*.iml
|
|
||||||
# .idea/modules
|
|
||||||
# *.iml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# CMake
|
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
|
||||||
|
|
||||||
# File-based project format
|
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
|
|
||||||
# Cursive Clojure plugin
|
|
||||||
|
|
||||||
# SonarLint plugin
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
||||||
|
|
||||||
# Editor-based Rest Client
|
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
|
||||||
|
|
||||||
### PhpStorm template
|
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
|
||||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
||||||
|
|
||||||
# User-specific stuff
|
|
||||||
|
|
||||||
# AWS User-specific
|
|
||||||
|
|
||||||
# Generated files
|
|
||||||
|
|
||||||
# Sensitive or high-churn files
|
|
||||||
|
|
||||||
# Gradle
|
|
||||||
|
|
||||||
# Gradle and Maven with auto-import
|
|
||||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
||||||
# since they will be recreated, and may cause churn. Uncomment if using
|
|
||||||
# auto-import.
|
|
||||||
# .idea/artifacts
|
|
||||||
# .idea/compiler.xml
|
|
||||||
# .idea/jarRepositories.xml
|
|
||||||
# .idea/modules.xml
|
|
||||||
# .idea/*.iml
|
|
||||||
# .idea/modules
|
|
||||||
# *.iml
|
|
||||||
# *.ipr
|
|
||||||
|
|
||||||
# CMake
|
|
||||||
|
|
||||||
# Mongo Explorer plugin
|
|
||||||
|
|
||||||
# File-based project format
|
|
||||||
|
|
||||||
# IntelliJ
|
|
||||||
|
|
||||||
# mpeltonen/sbt-idea plugin
|
|
||||||
|
|
||||||
# JIRA plugin
|
|
||||||
|
|
||||||
# Cursive Clojure plugin
|
|
||||||
|
|
||||||
# SonarLint plugin
|
|
||||||
|
|
||||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
||||||
|
|
||||||
# Editor-based Rest Client
|
|
||||||
|
|
||||||
# Android studio 3.1+ serialized cache file
|
|
||||||
|
|
||||||
/vendor/
|
/vendor/
|
||||||
/storage/**/*.zip
|
/storage/**/*.zip
|
||||||
/storage/logs/**/*.*
|
/storage/logs/**/*.*
|
||||||
|
.php-cs-fixer.cache
|
||||||
|
File diff suppressed because one or more lines are too long
42
code/abstract_factory.php
Normal file
42
code/abstract_factory.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:20
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
use Pattern\Creational\AbstractFactory\{NovapostDeliveryFactory, UkrpostDeliveryFactory};
|
||||||
|
use Pattern\Creational\AbstractFactory\{JustinDeliveryFactory, MeestDeliveryFactory};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $factories
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function delivery(array $factories): void
|
||||||
|
{
|
||||||
|
foreach ($factories as $factory) {
|
||||||
|
// getting the delivery service
|
||||||
|
$deliveryService = $factory->createDeliveryService();
|
||||||
|
// getting the parcel
|
||||||
|
$package = $factory->createPackage();
|
||||||
|
// checking the parcel
|
||||||
|
$package->getConsist();
|
||||||
|
// sending the parcel
|
||||||
|
$deliveryService->sendPackage($package);
|
||||||
|
echo '<hr/>' . PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$factories = [
|
||||||
|
new MeestDeliveryFactory(),
|
||||||
|
new NovapostDeliveryFactory(),
|
||||||
|
new JustinDeliveryFactory(),
|
||||||
|
new UkrpostDeliveryFactory(),
|
||||||
|
];
|
||||||
|
|
||||||
|
delivery($factories);
|
@ -52,7 +52,8 @@ require '../src/helpers.php';
|
|||||||
/** Creational patterns **/
|
/** Creational patterns **/
|
||||||
|
|
||||||
// require '../code/singleton.php';
|
// require '../code/singleton.php';
|
||||||
require '../code/factory_method.php';
|
// require '../code/factory_method.php';
|
||||||
|
require '../code/abstract_factory.php';
|
||||||
?>
|
?>
|
||||||
</main>
|
</main>
|
||||||
<script>hljs.highlightAll()</script>
|
<script>hljs.highlightAll()</script>
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:07
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
interface AbstractFactoryInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return DeliveryServiceInterface
|
||||||
|
*/
|
||||||
|
public function createDeliveryService(): DeliveryServiceInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return PackageInterface
|
||||||
|
*/
|
||||||
|
public function createPackage(): PackageInterface;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:02
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
interface DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
public function sendPackage(PackageInterface $package): void;
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:15
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class JustinDeliveryFactory implements AbstractFactoryInterface
|
||||||
|
{
|
||||||
|
public function createDeliveryService(): DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
return new JustinDeliveryService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPackage(): PackageInterface
|
||||||
|
{
|
||||||
|
return new JustinPackage();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 19:57
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class JustinDeliveryService implements DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
public function sendPackage(PackageInterface $package): void
|
||||||
|
{
|
||||||
|
/** @noinspection ForgottenDebugOutputInspection */
|
||||||
|
dump("Sending package via Justin...");
|
||||||
|
}
|
||||||
|
}
|
21
src/Pattern/Creational/AbstractFactory/JustinPackage.php
Normal file
21
src/Pattern/Creational/AbstractFactory/JustinPackage.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:00
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class JustinPackage implements PackageInterface
|
||||||
|
{
|
||||||
|
public function getConsist(): void
|
||||||
|
{
|
||||||
|
/** @noinspection ForgottenDebugOutputInspection */
|
||||||
|
dump('Checking package from Justin...');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:15
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class MeestDeliveryFactory implements AbstractFactoryInterface
|
||||||
|
{
|
||||||
|
public function createDeliveryService(): DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
return new MeestDeliveryService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPackage(): PackageInterface
|
||||||
|
{
|
||||||
|
return new MeestPackage();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 19:57
|
||||||
|
*/
|
||||||
|
|
||||||
|
//phpcs:ignore
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class MeestDeliveryService implements DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
public function sendPackage(PackageInterface $package): void
|
||||||
|
{
|
||||||
|
/** @noinspection ForgottenDebugOutputInspection */
|
||||||
|
dump("Sending package via Meest...");
|
||||||
|
}
|
||||||
|
}
|
21
src/Pattern/Creational/AbstractFactory/MeestPackage.php
Normal file
21
src/Pattern/Creational/AbstractFactory/MeestPackage.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:00
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class MeestPackage implements PackageInterface
|
||||||
|
{
|
||||||
|
public function getConsist(): void
|
||||||
|
{
|
||||||
|
/** @noinspection ForgottenDebugOutputInspection */
|
||||||
|
dump('Checking package from Meest...');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:15
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class NovapostDeliveryFactory implements AbstractFactoryInterface
|
||||||
|
{
|
||||||
|
public function createDeliveryService(): DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
return new NovapostDeliveryService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPackage(): PackageInterface
|
||||||
|
{
|
||||||
|
return new NovapostPackage();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 19:57
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class NovapostDeliveryService implements DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
public function sendPackage(PackageInterface $package): void
|
||||||
|
{
|
||||||
|
/** @noinspection ForgottenDebugOutputInspection */
|
||||||
|
dump("Sending package via Novapost...");
|
||||||
|
}
|
||||||
|
}
|
21
src/Pattern/Creational/AbstractFactory/NovapostPackage.php
Normal file
21
src/Pattern/Creational/AbstractFactory/NovapostPackage.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:00
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class NovapostPackage implements PackageInterface
|
||||||
|
{
|
||||||
|
public function getConsist(): void
|
||||||
|
{
|
||||||
|
/** @noinspection ForgottenDebugOutputInspection */
|
||||||
|
dump('Checking package from Novapost...');
|
||||||
|
}
|
||||||
|
}
|
17
src/Pattern/Creational/AbstractFactory/PackageInterface.php
Normal file
17
src/Pattern/Creational/AbstractFactory/PackageInterface.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 19:59
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
interface PackageInterface
|
||||||
|
{
|
||||||
|
public function getConsist(): void;
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:15
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class UkrpostDeliveryFactory implements AbstractFactoryInterface
|
||||||
|
{
|
||||||
|
public function createDeliveryService(): DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
return new UkrpostDeliveryService();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPackage(): PackageInterface
|
||||||
|
{
|
||||||
|
return new UkrpostPackage();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 19:57
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class UkrpostDeliveryService implements DeliveryServiceInterface
|
||||||
|
{
|
||||||
|
public function sendPackage(PackageInterface $package): void
|
||||||
|
{
|
||||||
|
/** @noinspection ForgottenDebugOutputInspection */
|
||||||
|
dump("Sending package via Ukrpost...");
|
||||||
|
}
|
||||||
|
}
|
21
src/Pattern/Creational/AbstractFactory/UkrpostPackage.php
Normal file
21
src/Pattern/Creational/AbstractFactory/UkrpostPackage.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package: patterns
|
||||||
|
* @author: Yevhen Odynets
|
||||||
|
* @date: 2025-07-03
|
||||||
|
* @time: 20:00
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace Pattern\Creational\AbstractFactory;
|
||||||
|
|
||||||
|
class UkrpostPackage implements PackageInterface
|
||||||
|
{
|
||||||
|
public function getConsist(): void
|
||||||
|
{
|
||||||
|
/** @noinspection ForgottenDebugOutputInspection */
|
||||||
|
dump('Checking package from Ukrpost...');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user