samedi 22 décembre 2018

Which Design Patterns is this?

I am having a problem trying to differentiate between two design patterns. I can understand both and the intent for each one of them and who to implement them. But I can't figure the difference between them code wise, after renaming it to generic names and hiding the intended is it possible to tell which one is this?

interface IA{
      void A1();
    }

    class SubA1 : IA
    {
      public void A1()  {}
    }

    class SubA2 : IA
    {
      public void A1() {  }
    }

    class SubA3  : IA
    {
      public void A1() {  }
    }

public class Context{

  private IA _stateOrAction;

// i could be injecting a strategy algorithm or setting initial state 
  public Context(IA stateOrAction)
  {
    _stateOrAction= stateOrAction;
  }

// i could be changing a strategy algorithm or chaining current state    
  public void Set_IA(IA stateOrAction)
  {
    _stateOrAction= stateOrAction;
  }

  public void DoWorkDependingOnStateOrAlgorithm(object iCouldBeHereOrNot)
  {
    // just ignore that this is not same signature as interface
    _stateOrAction.A1(iCouldBeHereOrNot);
  }

}

Aucun commentaire:

Enregistrer un commentaire