Suppose I have two classes with downstream subscriptions (subscribers)
class A {
SubscriptionManager<A> subscriptionManager; // downstream subscriptions
void addSub(Subscription<A> sub){
subscriptionManager.addSub(sub);
}
}
class B {
SubscriptionManager<B> subscriptionManager; // downstream subscriptions
void addSub(Subscription<B> sub){
subscriptionManager.addSub(sub);
}
}
Here is the issue I am dealing with, and its a design problem. I've heard several times of composition over inheritance, in an example like this I could create an abstract class which holds the subscription manager and has functions for adding and removing subscribers.
However, compoisiton over inheritance is making me not use the abstract class. I'm wondering whats correct here? clearly you see that theres code duplication with the whole add method for either of A, B classes (and perhaps more in the future).