Home PHP Libraries Other libraries Factory design pattern PHP classes
Factory design pattern PHP classes
<?php
interface IHuman
{
  function GetName();
}
class ManClass implements IHuman
{
  public function GetName()
  {
    return "I'm man."."<br>";
  }
}
class WomanClass implements IHuman
{
  public function GetName()
  {
    return "I'm Woman."."<br>";
  }
}

In object-oriented programming, the most common method is a new operator to generate an object instance, and the new operator is used to construct an object instance. But in some cases, the new operator directly generating objects will cause some problems. For example, the creation of many types of objects requires a series of steps: you may need to calculate or obtain the object's initial settings; choose which sub-object instance to generate; or you must generate some helper objects before generating the object you need. In these cases, the creation of a new object is a "process", not just an operation, like a gear transmission in a larger machine.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

PHP design pattern: factory pattern PHP design pattern: factory pattern

17 Dec 2016

Factory pattern: The factory class determines which instance of the product class to create based on parameters; a factory class refers to a class that contains a method specifically used to create other objects. The so-called on-demand allocation is to pass in parameters for selection and return a specific class. The main function of the factory pattern is to encapsulate object creation and simplify object creation operations.

PHP design pattern factory pattern_PHP tutorial PHP design pattern factory pattern_PHP tutorial

20 Jul 2016

PHP design pattern factory pattern. Factory pattern: The factory class determines which instance of the production class to create based on parameters. Factory class: A method class specifically used to create other objects. That is, allocate on demand and pass in parameters.

PHP Design Pattern Factory Pattern_PHP Tutorial PHP Design Pattern Factory Pattern_PHP Tutorial

21 Jul 2016

PHP design pattern factory pattern. I often use mysql database, so the program only writes the database operation class of mysql. I hope that all the experts will write down all the other categories, and it is best to send a copy to me. db_mysql.php inherits the db.php interface and has

PHP design pattern Factory (factory pattern)_PHP tutorial PHP design pattern Factory (factory pattern)_PHP tutorial

21 Jul 2016

PHP design pattern Factory (factory pattern). Copy the code The code is as follows: ?php /** * Factory method pattern * * Define an interface for creating objects, let subclasses decide which class to instantiate, and use the instantiation of a class to defer to its subclasses.

PHP pattern design factory pattern, PHP pattern design factory_PHP tutorial PHP pattern design factory pattern, PHP pattern design factory_PHP tutorial

13 Jul 2016

PHP pattern design factory pattern, PHP pattern design factory. PHP Pattern Design Factory Pattern, PHP Pattern Design Factory continues the previous article PHP Pattern Design Singleton Pattern (although it doesn’t seem to have much to do with it). Today we will talk about the second basic pattern design factory

PHP design pattern - simple factory pattern (static factory method pattern), PHP design pattern_PHP tutorial PHP design pattern - simple factory pattern (static factory method pattern), PHP design pattern_PHP tutorial

13 Jul 2016

PHP design pattern - simple factory pattern (static factory method pattern), PHP design pattern. PHP Design Pattern - Simple Factory Pattern (Static Factory Method Pattern), PHP Design Pattern Concept Simple Factory Pattern [Static Factory Method Pattern] (Static Factory Method) is a class creation pattern

See all articles