Hi all - I'm sure I'm being brain-dead here - and I think the answer is 'you
can't do that', but I thought I would try.
I have an interface that is Generic, with two type arguments. I want to
create a second interface that specifices the second type argument. I also
want to have objects implement that second interface without having to
implement the more generic methods that are inherited from the first. This
is especially evident when I implement multiple interfaces:
Some code will illustrate the problem:
// Base Type
interface I
{}
// 'Base' manager
interface IBase<T1, T2> where T2 : ICollection<T1>
{
T2 GetT1s();
}
// Base type collection
interface ICol<T1> : ICollection<T1> where T1 : I {}
// Derived type
interface IDerived<T1> : IBase<T1, ICol<T1>> where T1 : I {}
// Actual entities to manage
class A : I {}
class B : I {}
// Manager
class Mgr : IDerived<A>, IDerived<B>
{
public ICol<A> GetT1s()
{...}
// Note the explicit implementation here
ICol<B> IBase<B, ICol<B>>.GetT1s ()
{...}
}
I would really like to get rid of the 'IBase<B, ICol<B>>' - I would like to
use IDerived<B>, but this doesn't work. if I change IDerived to look like
this:
interface IDerived<T1> : IBase<T1, ICol<T1>> where T1 : I
{ new ICol<T1> GetT1s();}
Then I need to implement two forms of the method in the manager:
class Mgr : IDerived<A>, IDerived<B>
{
public ICol<A> GetT1s()
{...}
// I want the following method...
ICol<B> IDerived<B>.Get T1s()
{...}
// But not this one!
ICol<B> IBase<B, ICol<B>>.GetT1s ()
{...}
}
What am I doing wrong? I would love to only have to implement
IDerived<B>.Get T1s();
Thanks,
Phil 2 1657
When you explicitly implement an interface method, you have to qualify
it with the name of the interface where it was defined. In your
example, that is IBase<B, ICol<B>>. IDerived<B> doesn't define any
methods, so you can't use it in an explicit implementation.
It is annoying, yes, but the VS2005 IDE will help by writing all the
explicit implementations for you with the correct base interface names.
For example, if you add IList<int> to a class's interface list, then
click the little box on the interface name and tell it to explicitly
implement the interface, it'll write some methods for IList<int>, some
for ICollection<int >, one for IEnumerable<int >, and one for
IEnumerable.
Jesse
Thanks Jesse - I was afraid of that. The problem really shows itself when
implement multiple interfaces - like when I use a partial class to define a
data provider (which I happen to be doing). Since some of the methods only
differ by return type, I have to define them explicity.
Thanks again,
Phil
"Jesse McGrew" wrote: When you explicitly implement an interface method, you have to qualify it with the name of the interface where it was defined. In your example, that is IBase<B, ICol<B>>. IDerived<B> doesn't define any methods, so you can't use it in an explicit implementation.
It is annoying, yes, but the VS2005 IDE will help by writing all the explicit implementations for you with the correct base interface names. For example, if you add IList<int> to a class's interface list, then click the little box on the interface name and tell it to explicitly implement the interface, it'll write some methods for IList<int>, some for ICollection<int >, one for IEnumerable<int >, and one for IEnumerable.
Jesse
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JustSomeGuy |
last post by:
I need to write an new class derived from the list class.
This class stores data in the list to the disk if an object
that is added to the list is over 1K in size.
What methods of the std stl list class must Ioverride in order for this
to work?
|
by: Vivek |
last post by:
Hi,
I am trying to get as much information on void pointers. How do we take help
of void pointers in writing generic functions.
I have seen this kind of code for many years, but now I have got a chance to
write some myself.
Could anybody point me to a link where I can get more info for the same, or
refer me a book having more detail info.
|
by: Samuel R. Neff |
last post by:
What options are available for doing full-text searches of database
data without using a database-specific full-text engine?
The only option I've found is Google's Search Appliance but it's an
expensive hardware solution and we prefer a software solution.
In the past I've used development languages that had OEM Verity
support which was wonderful but as far as I can tell the only
out-of-the-box search available in ASP.NET is Index...
|
by: HC |
last post by:
I've stripped down my code to barebones to demonstrate (below).
I have interfaces and classes which implement them. I force my generic
collection to accept only the interface type. If I create an instance
of the generic class using the class implemention of the interface I
find it can't be converted to the interface version, and vice versa.
This a pain with my current design.
Can someone please advise on what best practice might be in...
|
by: Jon Davis |
last post by:
I am working with an application that is compiled as a COM EXE (written in
Delphi 7). I don't know if it's the nature of COM EXE or if it's implemented
in the COM EXE, but when I create a new object based on the COM interface
using C#, it references the first process/instance it finds of this
interface. This is not ideal for me; I would like to create a modal dialog
box that makes the user select which process to "attach" to. Getting a list...
| |
by: Brett Romero |
last post by:
I'd like to design a class that is runtime typed (generic) and the
types will always have a specific member. For example:
public T MyClass
{
T temp = default(T);
Void Fill
{
T.PopulateMe();
|
by: Don |
last post by:
When using Visual Basic .NET with a reference to Interop.Outlook, is there a
way to get more detailed information about an error other than
Exception.Message or Exception.ToString? For example, Outlook's
MailItem.SaveAs method can return an error message of "The operation
failed", but I have no idea what that means. As a test, I tried SaveAs using
a filename that contained illegal characters and got the error message
"Internal Application...
|
by: Bob Jones |
last post by:
I have an odd business requirement and I think that the implementation
is not correct in the terms of OOP development. Any help on the
concepts would be very appreciated!
We currently have a custom Page object which is derived from the base
Page object. We also have custom controls that derive from a base
class that performs custom drawing and inherits from our own
IOurControl interface. There is also a special caching layer in the
mix...
|
by: Dan Smithers |
last post by:
I want to write my own class derived from the ostream class.
I have been getting errors with my templates:
First, I get an error writing a nested template. If I leave the function
definition inside template class definition (commented out at //1) then
it compiles and runs fine, but if I declare and define the function
separately (at //2).
Is the following syntax supported by g++?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |