0

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}
ONYX
  • 5,679
  • 15
  • 83
  • 146

1 Answers1

1

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

Community
  • 1
  • 1
Marko
  • 1,874
  • 1
  • 21
  • 36
  • Do you have a solution to my problem by chance – ONYX Jul 20 '10 at 23:32
  • Multiple inheritance is not valid in C# and VB.NET...that means you can't put inheritance from two or more classes...if you need it anyway it is good idea to extract what you need from that base classes which you want to inherited and create an interface...you can inherit as many interfaces as you need...cheers – Marko Jul 21 '10 at 08:12