PC Review


Reply
Thread Tools Rate Thread

contract/interface c# system achitecture

 
 
=?Utf-8?B?RmlyZWZseQ==?=
Guest
Posts: n/a
 
      7th Jul 2006
Hi,

I have a C++ background and am new to C#.
At the moment I'm working on a project where I want to define a contract for
users of my library. I have done this by creating a interface dll project
containing the contract for the clients. To implement the interface I created
a second dll project that contains the implementation. The interface has an
assync design. It also has a factory that, based on configuration data, can
load different implementation assemblies. This is transparent for the client
and the reason for doing so is that the implementation is very computational
heavy and might need to be done on a separate machine e.g. with .NET
remoting. Having the contract defined in this manner means I can easily
replace the implementation without the client knowing.

Is there a better way of doing this in C#?

Filip


 
Reply With Quote
 
 
 
 
Pop Catalin
Guest
Posts: n/a
 
      10th Jul 2006
There might be a better way, from the versioning and upgradability's
point of view, wich is to use an abstract base class instead of an
interface if this is posible. Using an abstract class instead of an
interface allows ading new members (but not abstract, only virt or non
virt) without beaking posible implentations of the class wich you might
not now about(it there will ever be the case).

Firefly wrote:
> Hi,
>
> I have a C++ background and am new to C#.
> At the moment I'm working on a project where I want to define a contract for
> users of my library. I have done this by creating a interface dll project
> containing the contract for the clients. To implement the interface I created
> a second dll project that contains the implementation. The interface has an
> assync design. It also has a factory that, based on configuration data, can
> load different implementation assemblies. This is transparent for the client
> and the reason for doing so is that the implementation is very computational
> heavy and might need to be done on a separate machine e.g. with .NET
> remoting. Having the contract defined in this manner means I can easily
> replace the implementation without the client knowing.
>
> Is there a better way of doing this in C#?
>
> Filip


 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      10th Jul 2006
I wouldn't say this is better, especially in an environment like .NET.
Because you only have single inheritance, using a base class means that you
force the implementer to burn the base, which isn't exactly good design.

When requiring an implementation of a contract from external sources, I
would say you should always take an interface. You can provide an abstract
base class which implements the interface to make things easier, but an
interface should always be preferred.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Pop Catalin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> There might be a better way, from the versioning and upgradability's
> point of view, wich is to use an abstract base class instead of an
> interface if this is posible. Using an abstract class instead of an
> interface allows ading new members (but not abstract, only virt or non
> virt) without beaking posible implentations of the class wich you might
> not now about(it there will ever be the case).
>
> Firefly wrote:
>> Hi,
>>
>> I have a C++ background and am new to C#.
>> At the moment I'm working on a project where I want to define a contract
>> for
>> users of my library. I have done this by creating a interface dll project
>> containing the contract for the clients. To implement the interface I
>> created
>> a second dll project that contains the implementation. The interface has
>> an
>> assync design. It also has a factory that, based on configuration data,
>> can
>> load different implementation assemblies. This is transparent for the
>> client
>> and the reason for doing so is that the implementation is very
>> computational
>> heavy and might need to be done on a separate machine e.g. with .NET
>> remoting. Having the contract defined in this manner means I can easily
>> replace the implementation without the client knowing.
>>
>> Is there a better way of doing this in C#?
>>
>> Filip

>



 
Reply With Quote
 
Wiebe Tijsma
Guest
Posts: n/a
 
      10th Jul 2006
Nicholas Paldino [.NET/C# MVP] wrote:
> I wouldn't say this is better, especially in an environment like .NET.
> Because you only have single inheritance, using a base class means that you
> force the implementer to burn the base, which isn't exactly good design.
>
> When requiring an implementation of a contract from external sources, I
> would say you should always take an interface. You can provide an abstract
> base class which implements the interface to make things easier, but an
> interface should always be preferred.
>
>


I'd prefer a base class for types with many operations, and keep
interfaces clean with a minimal amount of operations.

Like the XPathNavigator base class / IXPathNavigable interface combination.

This forces you to separate your logic, and doesn't require you to
clutter up classes with too many methods for complex interface
implementations.

Regards,

Wiebe Tijsma
 
Reply With Quote
 
Mark Wilden
Guest
Posts: n/a
 
      10th Jul 2006
"Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...

> I wouldn't say this is better, especially in an environment like .NET.
> Because you only have single inheritance, using a base class means that
> you force the implementer to burn the base, which isn't exactly good
> design.


What does "burn the base" mean?

///ark


 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      11th Jul 2006
Mark,

Since .NET only allows for a class to derive from a single base class,
if you provide an abstract class, as opposed to an interface, you force the
user to provide an implementation which derives from the abstract class.
You burn their opportunity to provide their own base class (which might make
their implementation easier/cleaner/easier to maintain/etc/etc).


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Mark Wilden" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Nicholas Paldino [.NET/C# MVP]" <(E-Mail Removed)> wrote
> in message news:(E-Mail Removed)...
>
>> I wouldn't say this is better, especially in an environment like .NET.
>> Because you only have single inheritance, using a base class means that
>> you force the implementer to burn the base, which isn't exactly good
>> design.

>
> What does "burn the base" mean?
>
> ///ark
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WCF - interface from other project as contract myysth@gmail.com Microsoft Dot NET Framework 3 18th Jul 2008 03:53 PM
Re: Why/How does Microsoft not follow the Interface contract Niki Estner Microsoft C# .NET 1 27th Jul 2004 07:48 PM
Re: Why/How does Microsoft not follow their own Interface contract Ignacio Machin \( .NET/ C# MVP \) Microsoft C# .NET 0 27th Jul 2004 07:04 PM
Re: Why/How does Microsoft not follow the Interface contract mikeb Microsoft C# .NET 0 27th Jul 2004 06:26 PM
Interface Contract Question Jeff Gilbert Microsoft Dot NET 1 25th Apr 2004 04:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:26 AM.