If I change the access modifier of the setter of a public property from private to public, is that causes any breaking change in the other assemblies that refer it?
UPDATE: This question was the topic of my blog in January 2012. Thanks for the great question!
I assume that by "breaking change" you mean "when I recompile code that depended on this assembly, does code that used to compile still compile?"
By that definition, strictly speaking, yes, making a property setter public that used to be private is a breaking change. Suppose you have this code:
// Assembly Alpha public class Charlie { public int P { get; private set; } } public class Delta { public int P { get; set; } }
And then in another assembly that references Alpha:
// Assembly Echo class Foxtrot { static void M(Action<Charlie> f) {} static void M(Action<Delta> f) {} static void Golf() { M(y=>{y.P = 123;}); } }
You compile assembly Echo. Class Foxtrot has a method Golf which does overload resolution on M. M has two overloads; one that takes a action on Charlie and one that takes an action on Delta. If lambda parameter y is of type Charlie then the lambda body produces an accessibility error, and therefore that overload of M is not an applicable candidate. Overload resolution chooses the second overload and compilation succeeds.
Now you change assembly Alpha so that Charlie.P's setter is public. You recompile Echo. Now you get an overload resolution error because both overloads of M are equally valid and neither is better than the other. Compilation of Echo fails due to the change in Alpha. Your change to Alpha was a breaking change.
The question is not "is this a breaking change?" It clearly is; almost every change is some kind of breaking change. The question should be whether the breaking change will actually in practice break anyone, and if so, what is the cost of fixing the break compared to the benefit of the new feature?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With