vendredi 27 mai 2016

Does programming to an interface help get rid of globals?

Or is my interface the new "global"? I'm trying to find a way to get rid of statements like:

function someFunction()
{
    global $var1, $var3, $var4;
    //these are eventually assigned instantiated classes from an include
    ....
}

So far I am only coming up with interfaces. I am thinking my code will only be a little looser, maybe a lot. But if I really wanted to loosely couple after implementing an interface (or extending a class), couldn't I always create another level of abstraction between the interface and the inheriting classes with another abstract class or interface?

How can I start to get rid of globals other than rewriting an entire project?

Aucun commentaire:

Enregistrer un commentaire