G
Guthrie Phalanx
HI all
Bit of a newbie on interfaces, I hope this is not a silly question.
I am stuck on a problem where I want to create a custom collection of
objects, all of whom implement the same interface.
The following code probably explains my situation better than words do :
interface IEvent {
string Title {get; set;}
string Description {get; set;}
string URL {get;}
void Delete();
void Update(int updateID);
}
public class EventType1 :IEvent {
... implementation code for EventType1
}
public class EventType2 : IEvent {
... impleentation code for EventType2
}
public class EventCollection : System.Collections.CollectionBase {
public void Add(IEvent theEvent) {
List.Add(theEvent); //<------------------- this line causes the
error
}
}
On the line indicated, I get the follopwing error :
Event.cs(49): Inconsistent accessibility: parameter type
'Chamber.Components.IEvent' is less accessible than method
'Chamber.Components.EventCollection.Add(Chamber.Components.IEvent)'
What I am trying to do is create a custom collection class that holds any
object that implements IEvent. So, EventType 1 and EventType2 types could be
added to this collection.
Where have I gone wrong? Do I need to have an EventBase class that
implements IEvent, and then make EventType1 and EventType2 inherit from
that? If so, what is the point of having an interface defined in the first
place, when I can define everything I want in the EventBase class?
TIA for any help
- Guthrie
Bit of a newbie on interfaces, I hope this is not a silly question.
I am stuck on a problem where I want to create a custom collection of
objects, all of whom implement the same interface.
The following code probably explains my situation better than words do :
interface IEvent {
string Title {get; set;}
string Description {get; set;}
string URL {get;}
void Delete();
void Update(int updateID);
}
public class EventType1 :IEvent {
... implementation code for EventType1
}
public class EventType2 : IEvent {
... impleentation code for EventType2
}
public class EventCollection : System.Collections.CollectionBase {
public void Add(IEvent theEvent) {
List.Add(theEvent); //<------------------- this line causes the
error
}
}
On the line indicated, I get the follopwing error :
Event.cs(49): Inconsistent accessibility: parameter type
'Chamber.Components.IEvent' is less accessible than method
'Chamber.Components.EventCollection.Add(Chamber.Components.IEvent)'
What I am trying to do is create a custom collection class that holds any
object that implements IEvent. So, EventType 1 and EventType2 types could be
added to this collection.
Where have I gone wrong? Do I need to have an EventBase class that
implements IEvent, and then make EventType1 and EventType2 inherit from
that? If so, what is the point of having an interface defined in the first
place, when I can define everything I want in the EventBase class?
TIA for any help
- Guthrie