vendredi 1 janvier 2021

What design pattern is the most suitable in this case?

I know there are a lot of questions with this title, but I really have not found what I need, bear with me.

Let’s say that I want to design for 4 objects; all with common fields a and b, two of them have also c in common, and 2 have also d and e in common, and each one have another unique field. What I did was: I split them in 4 classes, added an abstract class with fields a and b, and 2 family abstract classes underneath it, from which I then extended the two classes with common fields. I also designed the classes with a builder pattern to account for the large numbers of fields at constructing; I made an abstract Builder inner static class in the higher class and extended it through every lower level.

My questions is split into two parts:

  1. Does it make sense to have the Builder static inner class extended through inherited classes to get the required behavior?
  2. Does the whole structure make sense? Is it an overkill? Do you have anything in mind that would make it a lot simpler?

Aucun commentaire:

Enregistrer un commentaire