M
M
Maxim2015-10-15 14:06:30
symfony
Maxim, 2015-10-15 14:06:30

What are the practical benefits of such an approach?

While studying the framework, the question arose:
What is the use and what is the practical application of this approach, namely, why create interfaces for entities.
For example

<?php
namespace Acme\BlogBundle\Model;
Interface PageInterface
{
    /**
     * Set title
     *
     * @param string $title
     * @return PageInterface
     */
    public function setTitle($title);
    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle();
    /**
     * Set body
     *
     * @param string $body
     * @return PageInterface
     */
    public function setBody($body);
    /**
     * Get body
     *
     * @return string 
     */
    public function getBody();
}

<?php
namespace Acme\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Acme\BlogBundle\Model\PageInterface;
/**
 * Page
 *
 * @ORM\Table()
 * @ORM\Entity()
 */
class Page implements PageInterface
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @var string
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
     */
    private $title;
    /**
     * @var string
     *
     * @ORM\Column(name="body", type="text")
     */
    private $body;
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set title
     *
     * @param string $title
     * @return Page
     */
    public function setTitle($title)
    {
        $this->title = $title;
    
        return $this;
    }
    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }
    /**
     * Set body
     *
     * @param string $body
     * @return Page
     */
    public function setBody($body)
    {
        $this->body = $body;
    
        return $this;
    }
    /**
     * Get body
     *
     * @return string 
     */
    public function getBody()
    {
        return $this->body;
    }
}

What is the salt? Is it necessary to do so?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2015-10-15
@maxpointn2point

https://ru.wikipedia.org/wiki/Interface_(objective-...
although it is written in relation to other languages, but much is true in relation to php.
php.net/manual/en/language.oop5.interfaces.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question