PHP Design Pattern--Strategy mode

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.