How to use interfaces in exception handling

Posted by vikp on Stack Overflow See other posts from Stack Overflow or by vikp
Published on 2010-06-09T09:21:39Z Indexed on 2010/06/09 9:32 UTC
Read the original article Hit count: 180

Hi,

I'm working on the exception handling layer for my application.

I have read few articles on interfaces and generics. I have used inheritance before quite a lot and I'm comfortable with in that area.

I have a very brief design that I'm going to implement:

public interface IMyExceptionLogger
{
   public void LogException();

   // Helper methods for writing into files,db, xml
}

I'm slightly confused what I should be doing next.

public class FooClass: IMyExceptionLogger
{

   // Fields
   // Constructors

}

Should I implement LogException() method within FooClass? If yes, than I'm struggling to see how I'm better of using an interface instead of the concrete class...

I have a variety of classes that will make a use of that interface, but I don't want to write an implementation of that interface within each class.

In the same time If I implement an interface in one class, and then use that class in different layers of the application I will be still using concrete classes instead of interfaces, which is a bad OO design...

I hope this makes sense.

Any feedback and suggestions are welcome.

Please notice that I'm not interested in using net4log or its competitors because I'm doing this to learn.

Thank you

Edit:

Wrote some more code. So I will implement variety of loggers with this interface, i.e. DBExceptionLogger, CSVExceptionLogger, XMLExceptionLogger etc. Than I will still end up with concrete classes that I will have to use in different layers of my application.

© Stack Overflow or respective owner

Related posts about c#

Related posts about best-practices