It seems that you are not correctly encoding information into your class hierarchy. It would be wiser to use a different template than a subclass. For example, use only one class (a visitor, or perhaps you can call it a potential subscriber, whatever is appropriate) and encode information about the services that this object subscribes to by moving the dynamically changing behavior behind the "Strategy" template or some of them. There are very few details in your example, but one thing you can do in C # is to create a βsubscriberβ property that would change the behavior of the object when the state of the property changes.
Here's a far-fetched somewhat related example:
class Price { private int priceInCents; private bool displayCents; private Func<string> displayFunction; public Price(int dollars, int cents) { priceInCents = dollars*100 + cents; DisplayCents = true; } public bool DisplayCents { get { return displayCents; } set { displayCents = value; if (displayCents) { this.displayFunction = () => String.Format("{0}.{1}", priceInCents / 100, priceInCents % 100); } else { this.displayFunction = () => (priceInCents / 100).ToString(); } } } public string ToString() { return this.displayFunction(); } }
Wedge
source share