mercredi 12 septembre 2018

Design pattern for similar functions with lambdas

I am trying to figure out a way or a pattern to simplify my Service class and make it very adjustable. My aim would be for the method in Service class to be accessed for example with lambdas or Predicates.

class Client {
  @RequestLine("something/a")
  public A fetchA() {}

  @RequestLine("something/b")
  public B fetchB() {}

  //... lots of similar methods

  @RequestLine("something/z")
  public Z fetchZ() {}
}

class Service {

 Client client;

 public void fixA(){
  client.fetchA();
  method();
 }

 public void fixB(){
  client.fetchB();
  method();
 }

// ... lots of similar methods

 public void fixZ(){
  client.fetchZ();
  method();
 }

 void method() {}

}

So my point how I could change it so it would use lambdas or something that would leave my Service class with one of the "fix" methods but it would know what I need to fetch from my Client.

If this question is bad and does not comply with rules here then please point me in the right direction as I am lost.

Aucun commentaire:

Enregistrer un commentaire