dimanche 8 mai 2016

Object uses itself (this) as a dependency when instantiating another object -- is there a name for this pattern?

I would call it an anti-pattern, actually, but I see it everywhere in a library I've taken over, and I'm finding it makes refactoring incredibly difficult.

The simplest form looks like this:

var evaluator = new Evaluator(this);
evaluator.Evaluate();

Inside Evaluate:

var dataProviderThing = new DataProviderThing(this);
dataProviderThing.GetSomeData();

Often the types have circular dependencies, which also make refactoring very difficult, but that's a separate issue.

What's the name of this pattern?

Aucun commentaire:

Enregistrer un commentaire