mardi 22 décembre 2020

How to determine the right design pattern in combination with business logic

yes I know this question has been asked many times, but i need help with a 'concrete' example. However, I usually have the problem that it is not clear to me where the business logic comes into play.

The following example I have a list of object A. Based on object A an object B has to be calculated. Several complicated rules from the business logic apply here.

What is the appropriate design pattern? I thought of a (simple) factory.

Example:

public interface BFactory {
  public B createB();
}

public class BFactoryImpl implements BFactory { 

   public B createB() {
      return B.builder().exampleField(
      // methods fors business logic
      ).build();
   }

}

What do you think? I had also briefly considered using only the builder pattern, but I didn't think it would be nice to include the business logic there.

  1. Is that too much effort with the factory?
  2. Does the interface make sense?
  3. Or should I just use the builder with business logic?
  4. If this case is too simple for a design pattern, should I just write a method for it?

Thank you for your answers, unfortunately I am still a little inexperienced in the use of design patterns and would love to hear your thoughts on this

Aucun commentaire:

Enregistrer un commentaire