Interfaces design question (w/ multiple inheritence)

R

raffelm

Bear with my while I try to explain...

I've created these two interfaces:

public interface ILoggingEvents { event LoggingWindowClosing
OnClosing;}
public interface ILogging { ... }

I then created a class that implements them both:

public class WindowLogging : ILogging, ILoggingEvents
{ ... }

However, in my code I cannot access methods implemented for the
ILoggingEvent:
ILogging logger = new WindowLogging();

log.onMyEvent += ... <--- understandably this is not accessible

My thinking was to allow the logger implementation class to fire
events (if subscribed to) but I didnt want to require all
implementions of ILogger to have to implement the events. For example
a logger to a window might want to let known the window is closing but
a text file logger wouldnt need to do that. Hope that makes sense.

Obviously, my design isnt going to work without come changes. I could
just use an base class instead of an interface. My question is: is
it possible to somehow do this with interfaces? (btw, I chose to use
interfaces just so that I could have a chance to explore them).

Thanks
Matt
 
R

Richard Blewett [DevelopMentor]

given

public interface ILoggingEvents { event LoggingWindowClosing
OnClosing;}
public interface ILogging { ... }


in your code

ILogging logger = new WindowLogging();
then do this:

ILoggingEvents ile = logger as ILoggingEvents;

if( ile != null )

{

ile.OnClosing += <blah>;

}

Does this do what you require?

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

Bear with my while I try to explain...

I've created these two interfaces:

public interface ILoggingEvents { event LoggingWindowClosing
OnClosing;}
public interface ILogging { ... }

I then created a class that implements them both:

public class WindowLogging : ILogging, ILoggingEvents
{ ... }

However, in my code I cannot access methods implemented for the
ILoggingEvent:
ILogging logger = new WindowLogging();

log.onMyEvent += ... <--- understandably this is not accessible

My thinking was to allow the logger implementation class to fire
events (if subscribed to) but I didnt want to require all
implementions of ILogger to have to implement the events. For example
a logger to a window might want to let known the window is closing but
a text file logger wouldnt need to do that. Hope that makes sense.

Obviously, my design isnt going to work without come changes. I could
just use an base class instead of an interface. My question is: is
it possible to somehow do this with interfaces? (btw, I chose to use
interfaces just so that I could have a chance to explore them).

Thanks
Matt

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 
R

raffelm

Richard Blewett said:
given

public interface ILoggingEvents { event LoggingWindowClosing
OnClosing;}
public interface ILogging { ... }


in your code

ILogging logger = new WindowLogging();
then do this:

ILoggingEvents ile = logger as ILoggingEvents;

if( ile != null )

{

ile.OnClosing += <blah>;

}

Does this do what you require?

Indeed it does.

Thnx.
Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top