<legend id='UJlQZ'><style id='UJlQZ'><dir id='UJlQZ'><q id='UJlQZ'></q></dir></style></legend>
    • <bdo id='UJlQZ'></bdo><ul id='UJlQZ'></ul>

    <tfoot id='UJlQZ'></tfoot>
    <i id='UJlQZ'><tr id='UJlQZ'><dt id='UJlQZ'><q id='UJlQZ'><span id='UJlQZ'><b id='UJlQZ'><form id='UJlQZ'><ins id='UJlQZ'></ins><ul id='UJlQZ'></ul><sub id='UJlQZ'></sub></form><legend id='UJlQZ'></legend><bdo id='UJlQZ'><pre id='UJlQZ'><center id='UJlQZ'></center></pre></bdo></b><th id='UJlQZ'></th></span></q></dt></tr></i><div id='UJlQZ'><tfoot id='UJlQZ'></tfoot><dl id='UJlQZ'><fieldset id='UJlQZ'></fieldset></dl></div>
  1. <small id='UJlQZ'></small><noframes id='UJlQZ'>

    1. 特性与接口

      时间:2023-07-16
      <legend id='OiPcU'><style id='OiPcU'><dir id='OiPcU'><q id='OiPcU'></q></dir></style></legend>
        <tbody id='OiPcU'></tbody>

          <bdo id='OiPcU'></bdo><ul id='OiPcU'></ul>

          <small id='OiPcU'></small><noframes id='OiPcU'>

            1. <i id='OiPcU'><tr id='OiPcU'><dt id='OiPcU'><q id='OiPcU'><span id='OiPcU'><b id='OiPcU'><form id='OiPcU'><ins id='OiPcU'></ins><ul id='OiPcU'></ul><sub id='OiPcU'></sub></form><legend id='OiPcU'></legend><bdo id='OiPcU'><pre id='OiPcU'><center id='OiPcU'></center></pre></bdo></b><th id='OiPcU'></th></span></q></dt></tr></i><div id='OiPcU'><tfoot id='OiPcU'></tfoot><dl id='OiPcU'><fieldset id='OiPcU'></fieldset></dl></div>

              1. <tfoot id='OiPcU'></tfoot>

                本文介绍了特性与接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我最近一直在努力学习 PHP,但我发现自己沉迷于 trait.我理解水平代码重用的概念,并且不想一定要从抽象类继承.我不明白的是:使用特性和接口之间的关键区别是什么?

                I've been trying to study up on PHP lately, and I find myself getting hung up on traits. I understand the concept of horizontal code reuse and not wanting to necessarily inherit from an abstract class. What I don't understand is: What is the crucial difference between using traits versus interfaces?

                我曾尝试寻找解释何时使用一种或另一种的不错的博客文章或文章,但到目前为止我发现的示例看起来非常相似以至于完全相同.

                I've tried searching for a decent blog post or article explaining when to use one or the other, but the examples I've found so far seem so similar as to be identical.

                推荐答案

                一个接口定义了一组实现类必须实现的方法.

                An interface defines a set of methods that the implementing class must implement.

                当特征被use使用时,方法的实现也会随之而来——这不会发生在Interface中.

                When a trait is use'd the implementations of the methods come along too--which doesn't happen in an Interface.

                这是最大的不同.

                来自 PHP RFC 的水平重用:

                Traits 是一种在 PHP 等单继承语言中重用代码的机制.Trait 旨在通过使开发人员能够在位于不同类层次结构中的多个独立类中自由重用方法集来减少单继承的一些限制.

                Traits is a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

                这篇关于特性与接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 flexbox 获取 pinterest 或 jQuery 砌体布局 下一篇:PHP 7 接口,返回类型提示和自我

                相关文章

                <i id='0xvz9'><tr id='0xvz9'><dt id='0xvz9'><q id='0xvz9'><span id='0xvz9'><b id='0xvz9'><form id='0xvz9'><ins id='0xvz9'></ins><ul id='0xvz9'></ul><sub id='0xvz9'></sub></form><legend id='0xvz9'></legend><bdo id='0xvz9'><pre id='0xvz9'><center id='0xvz9'></center></pre></bdo></b><th id='0xvz9'></th></span></q></dt></tr></i><div id='0xvz9'><tfoot id='0xvz9'></tfoot><dl id='0xvz9'><fieldset id='0xvz9'></fieldset></dl></div>
              2. <legend id='0xvz9'><style id='0xvz9'><dir id='0xvz9'><q id='0xvz9'></q></dir></style></legend>

                    <tfoot id='0xvz9'></tfoot>

                    <small id='0xvz9'></small><noframes id='0xvz9'>

                    • <bdo id='0xvz9'></bdo><ul id='0xvz9'></ul>