我们希望在属于类库的类中对接口进行“部分显式实现”。部分显式实现是指隐式实现接口的某些成员,显式实现同一接口的其余成员。请让我们知道我们需要注意的可能问题。
更具体地说,假设我们有IDriver
如下定义的接口。该IDriver
接口定义了所有驱动程序的基本功能。
interface IDriver
{
IDriverIdentity DriverIdentity { get; }
IDriverOperation Operation { get; }
IDriverUtility Utility { get; }
}
public class MyDriver1 : IDriver
{
// Implement the first and second member of IDriver implicitly
public IDriverIdentity DriverIdentity
{
get
{
// return a IDriverIdentity object that user can use to assess Identity operations...
}
}
public IDriverOperation Operation
{
get
{
// return a IDriverOperation object that user can use to access DriverOperation related properties and members..
}
}
// Implement the last member of interface explicitly
IDriverUtility IDriver.Utility
{
get
{
// return a IDriverUtility object that user can use to access fundamental utility operations that is mandated for every "Driver" object...
}
}
public MyDriver1Utility Utility
{
get
{
// return MyDriver1Utility object that user can use to access utility operations available in this driver ...
}
}
}
同样让我们假设我们有MyDriver2
,MyDriver3
等隐式和显式地实现DriverIdentity
and 。Operation
Utility
在所有Driver
类中,我们都希望隐式实现DriverIdentity
,Operation
以便用户在使用不同对象DriverIdentity
时具有一致的视图。但是,我们希望显式实现该成员,并在从驱动程序对象访问时提供特定于该驱动程序的附加实用程序操作。Operation
Driver
Utility
我们希望了解在这种情况下部分显式实现的任何可能的副作用/后果。请让我们知道您的意见。
提前致谢!!