T
Techno_Dex
I am using the Enterprise Library, specifically the Logging functionality.
I would like to write a class that has protected methods which perform the
actual logging of methods that are called and possibly raise events. My
problem is I'm struggling with the design. I want to design this
functionality in a fashion that I can be inherited by other classes (mainly
base classes) for both UI contol classes and non UI classes. I have looked
into the decorator pattern but this won't work as the inheritance of UI Base
Classes start to cause problems. Does anyone have any thoughts on solving
this?
public class MethodLogging
{
protected virtual void OnMethodRequestBegin(MethodRequestEventArgs e)
{
//Log the Method Name using verbose logging (i.e. e.MethodName)
//Raise an event to let other classes know a method was called
}
protected virtual void OnMethodRequestEnd (MethodRequestEventArgs e)
{
//Log the Method Name using verbose logging (i.e. e.MethodName)
//Raise an event to let other classes know a method was called
}
}
//Here is the problem, as C# doesn't allow multiple class inheritance
public class BaseUIClass : Form, MethodLogging
{
public void MethodA()
{
OnMethodRequestBegin (new MethodRequestEventArgs ("MethodA"));
//Do Work for Method A
OnMethodRequestEnd (new MethodRequestEventArgs ("MethodA"));
}
}
public class BaseClass : MethodLogging
{
public void MethodB()
{
OnMethodRequestBegin (new MethodRequestEventArgs ("MethodB"));
//Do Work for Method B
OnMethodRequestEnd (new MethodRequestEventArgs ("MethodB"));
}
}
I have thought about using Interfaces, but then I still have to code the
OnMethodRequestBegin and OnMethodRequestEnd for every single UI Control
which duplicates the code all over the place instead of keeping everything
in one nice neat package. I would like to come up with a solution that will
work for both UI and non UI classes alike.
I would like to write a class that has protected methods which perform the
actual logging of methods that are called and possibly raise events. My
problem is I'm struggling with the design. I want to design this
functionality in a fashion that I can be inherited by other classes (mainly
base classes) for both UI contol classes and non UI classes. I have looked
into the decorator pattern but this won't work as the inheritance of UI Base
Classes start to cause problems. Does anyone have any thoughts on solving
this?
public class MethodLogging
{
protected virtual void OnMethodRequestBegin(MethodRequestEventArgs e)
{
//Log the Method Name using verbose logging (i.e. e.MethodName)
//Raise an event to let other classes know a method was called
}
protected virtual void OnMethodRequestEnd (MethodRequestEventArgs e)
{
//Log the Method Name using verbose logging (i.e. e.MethodName)
//Raise an event to let other classes know a method was called
}
}
//Here is the problem, as C# doesn't allow multiple class inheritance
public class BaseUIClass : Form, MethodLogging
{
public void MethodA()
{
OnMethodRequestBegin (new MethodRequestEventArgs ("MethodA"));
//Do Work for Method A
OnMethodRequestEnd (new MethodRequestEventArgs ("MethodA"));
}
}
public class BaseClass : MethodLogging
{
public void MethodB()
{
OnMethodRequestBegin (new MethodRequestEventArgs ("MethodB"));
//Do Work for Method B
OnMethodRequestEnd (new MethodRequestEventArgs ("MethodB"));
}
}
I have thought about using Interfaces, but then I still have to code the
OnMethodRequestBegin and OnMethodRequestEnd for every single UI Control
which duplicates the code all over the place instead of keeping everything
in one nice neat package. I would like to come up with a solution that will
work for both UI and non UI classes alike.