mardi 3 mars 2020

Architecture problem : probable solution is injection dependency but I don't know how implement it

I front to an architecture I can't change for now, but I need to resolve on problem about it. This is an code example of the problem:

class A
{
   void f(var ratio) {
      f(ratio);
   }
   abstract void g(ratio);

}

class B : A
{
   void g(var ratio) {
      otherMethod(ratio)
}

class C : A
{
   var _ratio; // defined at the constructor of C
   void g(ratio) {
      if(_ratio != null)  otherMethod(_ratio);
      else otherMethod(ratio);
   }
}

The main function calls indifferently the f method with an input ratio even this last is not used when the ratio is already defined in local.

I want to merge the class B and C and keep the behaviour of using local ratio member if defined or input ratio if not.

I hope I'm quite clear.

Someone has told me I can use the Policy pattern (I understand there is a kind of injection dependency) if I don't want to change all the architecture. Do you know what does it mean? Do you have other solution to remove this and have something more clear than this condition in g method? The main function calls indifferently the f method with an input ratio even this last is not used when the ratio is already defined in local.

Notes : I use c#

Thank you for your help!

Aucun commentaire:

Enregistrer un commentaire