jeudi 1 octobre 2015

Use of Adapter/Facade pattern to anticipate incompatible interfaces and complexity?

Adapter pattern is mentioned in Wikipedia to fix incompatibilities between an expected interface and an actual interface.

Facade pattern is said to obscure complex implementations and present a simplified API.

However, would these patterns be used even in the absence of these issues? Aka, to use these patterns prematurely in anticipation of future incompatibility and complexity?

I have encountered code where a wrapper class was implemented with an exact copy of the interface of the inner class - it had all the public methods of the original with the exact same parameters. The wrapper class and the inner class were also defined in the same assembly.

Like so:

public class ClassifierImplementation
{
    private Classifier classifier_;
    public Wrapper() { classifier_ = new Classifier(); }

    public int[] Classify(double[] values, int seed)
    {
        return classifier_.Classify(values, seed);
    }

    // And other more public methods
}

What would be the rationale behind such an implementation?

Aucun commentaire:

Enregistrer un commentaire