Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will change from abstract class to sealed class break simple client use

Tags:

c#

I'm changing a class from public abstract AwesomeClass, to public sealed AwesomeClass. I've also added a new property. All existing members are unchanged. I know that this is a breaking change. Clients that have implemented AwesomeClass or relied on it being abstract via reflection will be broken.

My question is, will clients that have only used members of instances of AwesomeClass that I've provided, be broken (and if yes how)? None of the clients will have a dependency on any of my types that implemented AwesomeClass as they were all internal. I think not, but...

Here is the class before and after:

public abstract class AwesomeClass
{
    public abstract Guid SuperGuid { get; set; }
    public abstract int SuperInt { get; set; }
}

public sealed class AwesomeClass
{
    public Guid SuperGuid { get; set; }
    public int SuperInt { get; set; }
    public int OtherSuperInt { get; set; }
}
like image 716
bentayloruk Avatar asked Nov 12 '22 19:11

bentayloruk


1 Answers

You mean that when you have this:

public abstract class Foo
{
    public string Bar;
}

void UpdateFooBar(Foo foo)
{
    foo.Bar = "Updated";
}

And you change abstract class Foo to sealed class Foo, will UpdateFooBar(Foo foo) continue to work?

What kept you from trying? But yes, it will.

like image 114
CodeCaster Avatar answered Nov 14 '22 22:11

CodeCaster