473,382 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Interfaces design question (w/ multiple inheritence)

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
Nov 16 '05 #1
2 1158
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/<ba**************************@posting.google.com >

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]
Nov 16 '05 #2
"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message news:<ez*************@TK2MSFTNGP14.phx.gbl>...
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
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John | last post by:
Hi, I am trying to create a class heirarchy similar to the following: // base interface class ICar { public: virtual void start() = 0; }; // add members to that interface, but retain base...
2
by: Ian McBride | last post by:
(was: delete() confusion) I have a class with multiple base classes. One of these base classes (base1) has its own new/delete operators and nothing else. Another base class (base 2) has a...
4
by: Michael C. Starkie | last post by:
Car is a class, with four wheel variables. SUV is a class with four wheel variables. Outback is a class that inherits from Car and SUV. How many wheel variables does Outback have? (In general, how...
1
by: Learning SQL Server | last post by:
I have a base class (say, BaseUser) in my class library that 3 other classes derive from: UserTom UserDick UserHarry Additionally, a fourth class that contains some administrative functions...
1
by: Tim Smith | last post by:
Hi, I have been considering how to personalize mini functional applications and I was wondering if there is an easy way to do the following for an client application design a) User runs...
5
by: Bob Rundle | last post by:
I heard that managed C++ in VS 2005 supports multiple inheritence. Is this true? Bob Rundle
5
by: Neelesh Bodas | last post by:
This might be slightly off-topic. Many books on C++ consider multiple inheritence as an "advanced" concept. Bruce Eckel says in TICPP, volume 2 that "there was (and still is) a lot of...
4
by: Mukesh_Singh_Nick | last post by:
Does PHP support multiple inheritence? If not, how would one workaround it when one needs a class to inherit from multiple classes?
1
by: vijay bhaskar | last post by:
hi . why c sharp does not support multiple inheritence
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.