Permalink
Browse files

Introduce Admin_Page_Factory interface.

  • Loading branch information...
felixarntz committed Jan 14, 2018
1 parent f6ef1da commit 255b4d4af50d9f0bc753cd2f8e8cd53f3bc0fec5
Showing with 32 additions and 0 deletions.
  1. +32 −0 src/Admin_Page_Factory.php
@@ -0,0 +1,32 @@
<?php
/**
* Admin_Page_Factory interface
*
* @package Leaves_And_Love\OOP_Admin_Pages
* @since 1.0.0
*/
namespace Leaves_And_Love\OOP_Admin_Pages;
use Leaves_And_Love\OOP_Admin_Pages\Exception\Config_Invalid_Exception;
use BrightNucleus\Config\ConfigInterface as Config;
/**
* Interface to create admin page instances.
*
* @since 1.0.0
*/
interface Admin_Page_Factory {
/**
* Creates a new admin page instance.
*
* @since 1.0.0
*
* @param Config $config Admin page configuration.
* @return Admin_Page Admin page instance.
*
* @throws Config_Invalid_Exception Thrown when the configuration is invalid.
*/
public function create_page( Config $config ) : Admin_Page;

This comment has been minimized.

@felixarntz

felixarntz Jan 19, 2018

Owner

This is basically the same Config object that will then be inserted into the admin page constructor.

}

1 comment on commit 255b4d4

@felixarntz

This comment has been minimized.

Owner

felixarntz commented on 255b4d4 Jan 19, 2018

What is a factory?

By using the factory method pattern, one rids other code from the responsibility of manually instantiating objects - that is the sole responsibility of a factory class. This also looses coupling for the code that would otherwise instantiate the objects (i.e. makes it less dependent), as it doesn't need to know about what the class is named and which parameters it requires. It only needs to worry about the factory method. That allows to potentially change a class constructor, and even a class name, in the future without breaking backward-compatibility, as the factory method can then adapt to it internally.

Implementations of the Admin_Page_Factory will be responsible for creating specific Admin_Page implementation instances.

Please sign in to comment.