I have a class called Comments for articles which implements a base class of BaseArticle that class has a protected object called settings.
The settings object is a web.config section just for articles and I also have one also for blogs.
My problem is that I want to make Comments usable for blog Comments, but the class Comments inherits BaseArticle, which I want it to inhereit it’s own base class BaseBlog with it’s own settings.
I need to make it universal how do I do that. An example would be appreciated.
class Comments : BaseArticle {}
class Comments : BaseBlog { inheritance problem}
From my experience, starting with inheritance and base classes from the early start can cause you some trouble as you already have seen. I’ve learned, it is better to go from a bottom up, which means-creating classes and methods that you need, and then when you’ve noticed similar functionality or duplicated code, you extract it to base type or interface. Anyway, for your example code I would first go and read about Liskov Substitution Principle(LSP).
More info:
LSP in OO programming?
What is the Liskov Substitution Principle?
cheers