Abstract classes in php instantiate their subclasses in their methods to complete the call to their own methods

WBOY
Release: 2016-07-28 08:28:19
Original
1138 people have browsed it

I am a newbie, if I encounter this, I can’t understand the beauty of it, record it;
The general logic is as follows

<code><span>abstract</span><span><span>class</span><span>A</span>
{</span><span>private</span><span>static</span><span>$c</span>;
    <span>final</span><span><span>function</span><span>todo</span><span>()</span>
    {</span><span>//do something</span>
    }
    <span>public</span><span><span>function</span><span>init</span><span>()</span>
    {</span><span>$c</span> = <span>new</span> B;
    }
    <span>public</span><span><span>function</span><span>get</span><span>()</span>
    {</span><span>$c</span>->todo();
    }
}
<span><span>class</span><span>B</span><span>extends</span><span>A</span>
{</span>}
....
A::get();</code>
Copy after login

Several questions arise here:
1. Can I create a new subclass in a parent class?
2. What are the considerations for doing this? Or what kind of problems is this design pattern avoiding?

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced the abstract class in PHP that instantiates its subclass in its method to complete the call of its own method, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template