Web Development Notes www.chhua.com daily practice PHP design mode--strategy mode
The strategy pattern is very important in the design pattern and may be the most important pattern in the modern object-oriented design.
It is used to create pluggable, replaceable, reusable components.
For a complete and simple description of the policy pattern, the following code shows a very simple example.
Code Demo: The implementation of an example is to implement a class that gets the HTML code,
The structure of the class, divided into two parts, part of the acquisition of HTML, part of the acquisition of related content,
1
2
3
4
5
6
7 8 9 (
29) (a)
|
<?php
class htmldom{
private $STROBJ//Content Object public
function __construct ($STROBJ) {
$this- >strobj= $strObj;
}
Public Function gethtml () {return
' |
The above is a small example of a strategy pattern, and while this example is trivial, this design pattern is useful in more complex situations
Free reprint, reprint please specify: reprinted from the Web Development notes www.chhua.com