> [...]
> this becouse i would use common methods of DbConverter class for
[quoted text clipped - 3 lines]
> now, c# implements multiple interface inheritance but i think it not
> solve my problem...
If you want your OracleDbConverter class to itself expose the interface
defined by OracleDb and DbConverter class, in a way that allows it to be
treated as either class, that's not possible in C#.
However, using interfaces certainly is one possible work-around, depending
on what you really need to accomplish. If you can create an interface
that describes either the Db or DbConverter class (or both), then your
OracleDbConverter class can then implement that interface (or interfaces)
using composition. That is, inside the OracleDbConverter it would have an
instance of the class implementing the interface, which is uses to
delegate the handling of the interface to.
Then where you would have required the "Db" or "DbConverter" class,
instead you can require the relevant interface. Since your
OracleDbConverter class would implement the interface, it would be usable
there.
It's not quite as convenient as true multiple inheritance, but it does
avoid some of the complexity that true MI can introduce.
Pete
Gambero - 21 Mar 2008 20:23 GMT
> [...]
> However, using interfaces certainly is one possible work-around, depending
[quoted text clipped - 9 lines]
> OracleDbConverter class would implement the interface, it would be usable
> there.
but with interfaces i have to IMPLEMENT ALL the code also for common
methods...
my goal is to derive from a common classes and implement only specialized
methods.
so that
SqlDb and OracleDb can use Db methods and SqlDbConverter and
OracleDbConverter can use Db and DbConverter methods.
there is a work-around for this?
Thanks
Peter Duniho - 21 Mar 2008 20:40 GMT
> but with interfaces i have to IMPLEMENT ALL the code also for common
> methods...
Yes, you do. I did say it's less convenient. The VS IDE will
auto-generate the interface stubs for you if you ask it to, but
yes...you'll have to go through each one and add the appropriate calls
within each stub.
> my goal is to derive from a common classes and implement only
> specialized methods.
> so that
>
> SqlDb and OracleDb can use Db methods and SqlDbConverter and
> OracleDbConverter can use Db and DbConverter methods.
I do understand how inheritance of concrete classes works, thank you.
I've already explained that C# doesn't support multiple inheritance of
classes, and I've already described the alternative. As long as you can
restructure your design so that interfaces can be used for your
references, rather than actual classes, it will work, albeit with more
typing effort on your part.
> there is a work-around for this?
See above.
Pete
On Mar 21, 2:50 pm, "Gambero" <cgamberiniNON_VOGLIO_S...@libero.it>
wrote:
> Hi, i have this classes:
>
[quoted text clipped - 22 lines]
>
> any help? Thanks!
Can you use composition?
SqlDbConverter can instantiate an instance of SqlDb
Otherwise you have to rethink your structure
Gambero - 21 Mar 2008 21:02 GMT
>Can you use composition?
>SqlDbConverter can instantiate an instance of SqlDb
incapsulate a Db object in DbConverter class is a good alternative,
but in this way i have to change access modifiers of low-level methods
implemented in Db class to public for use in DbConverter methods,
and i would like that low-level methods remain private usable only within
the class or in derived classes..
thanks for suggestion!
any other idea?
Thanks
Ben Voigt [C++ MVP] - 21 Mar 2008 22:55 GMT
>> Can you use composition?
>> SqlDbConverter can instantiate an instance of SqlDb
[quoted text clipped - 4 lines]
> and i would like that low-level methods remain private usable only
> within the class or in derived classes..
That's what the "internal" access modifier is for...
> thanks for suggestion!
>
> any other idea?
>
> Thanks
Gambero - 22 Mar 2008 10:52 GMT
>> incapsulate a Db object in DbConverter class is a good alternative,
>> but in this way i have to change access modifiers of low-level methods
[quoted text clipped - 3 lines]
>
> That's what the "internal" access modifier is for...
good suggestion, but i have Db, SqlDb and OracleDb in one assembly, and
DbConverter, SqlDbConverter and OracleDbConverter in another assembly.
internal restrict the visibility only within the current assembly... is not
my solution..
Thanks
other suggestions?
Ben Voigt [C++ MVP] - 24 Mar 2008 14:57 GMT
>>> incapsulate a Db object in DbConverter class is a good alternative,
>>> but in this way i have to change access modifiers of low-level
[quoted text clipped - 12 lines]
>
> other suggestions?
InternalsVisibleToAttribute ?