dimanche 30 septembre 2018

Implications of naming the interfaces like the implementations

I would like to ask you, what are the positive and negative implications of naming the interfaces like the implementations, but storing them in interface-specific folders, like Contract (see Option 2).

Thank you for your time.


Option 1:

enter image description here

tests/Model/Entity/UsersInterface.php

<?php

namespace Test\Model\Entity;

use Test\Model\Entity\UserInterface;

interface UsersInterface {

    public function remove(UserInterface $user);
}

tests/Model/Entity/Users.php

<?php

namespace Test\Model\Entity;

use Test\Model\Entity\UserInterface;
use Test\Model\Entity\UsersInterface;

class Users implements UsersInterface {

    private $users = [];

    public function remove(UserInterface $user) {
        //...
    }

}


Option 2 (desirable):

enter image description here

tests/Model/Contract/Entity/Users.php

<?php

namespace Test\Model\Contract\Entity;

use Test\Model\Contract\Entity\User;

interface Users {

    public function remove(User $user);
}

tests/Model/Entity/Users.php

<?php

namespace Test\Model\Entity;

use Test\Model\Contract\Entity;

class Users implements Entity\Users {

    private $users = [];

    public function remove(Entity\User $user) {
        //...
    }

}

Aucun commentaire:

Enregistrer un commentaire