Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue in interface versioning

Tags:

c#

.net

interface

My old version of the interface which is exposed to the users is this:

public interface IReporter
{
    void  Write(int site, DateTime start, DateTime end);
} 

Now I want to replace the parameters in the function as below:

public interface IReporter
{
    void  Write(int site, SiteLocalDateTime start, SiteLocalDateTime end);
}

I want the existing customer to use the old method and the new customer to use the new method.

Any idea on how to achieve this by exposing single interface?

Options:

  1. Keeping two interface with IReporter and IReporterNew : IReporter Now all my new implementations require both the methods to be used.

  2. Exposing two interface is not possible.

like image 961
user1581317 Avatar asked Apr 08 '26 08:04

user1581317


1 Answers

You can just combine the interfaces into one if the implementation of the method is on your end. The user can decide then which to use. (Preferably you should mark the old method obsolete, thanks 3dd)

public interface IReporter
{
    [Obsolete]
    void  Write(int site, DateTime start, DateTime end);
    void  Write(int site, SiteLocalDateTime start, SiteLocalDateTime end);
}

If that is not what you are after, you should in fact version your software. One version for new customers, one 'legacy' build for existing customers. Eventually you can migrate old customers to the new version.

You can even create a conversion between the two types if the actual implementing type is known, but I am not sure if that is useful in this case.

Also, did you mean to use DateTimeOffset instead of SiteLocalDateTime?

like image 85
Patrick Hofman Avatar answered Apr 10 '26 02:04

Patrick Hofman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!