dimanche 18 décembre 2022

Best way to decouple project from packages that I use as trait

I have a model in my project called Employee and it has a hierarchical structure(each employee may has some superior or inferior employees).

So I use a package that implement this hierarchical structure by utilizing nested set model.

The Employee model must use this package as trait(NodeTrait). But it may be needed to change the algorithm and so the package I currently use, in the future.

What's the best way to decouple this model from the package I use for implementing hierarchical structure?

This is current code:

class Employee
{
    use NodeTrait;

    public function addChild(Employee $child){
        $this->appendNode($child);
    }

}

In this code appendNode is a method of NodeTrait but I want to write a code that doesnt depend on NodeTrait methods, instead have an interface with some methods such as addChild and call those methods in methods of Employee class.

Aucun commentaire:

Enregistrer un commentaire