在Composition模式java中避免冗余(Avoiding redundancy in Composition pattern java)
我有两个A和B类。现在,我有
B "has a" A
关系。 所以,这里最重要的是组合模式。 现在,B的一个领域是A的一个对象。问题是A和B的一些领域是常见的。 因此,在这种情况下,这些字段将是多余的。 我无法从公共字段创建抽象类,并使A和B继承它,因为它们已经扩展了一些抽象类。 在这种情况下,最佳做法是什么?I have two classes A and B. Now, I have
B "has a" A
relationship. So, the most trivial thing to follow here is the Composition pattern. Now, one of the field of B is an object of A. The problem is some of the fields of A and B are common. So, in this case, those fields will be redundant. I can't create an abstract class out of the common fields and make A and B inherit it because they are already extending some abstract class. What would be the best practice in this case?
原文:https://stackoverflow.com/questions/31020432