interface IFoo
{
int MyReadOnlyVar { get; }
}
class Foo : IFoo
{
int MyReadOnlyVar { get; set; }
}
public IFoo GetFoo()
{
return new Foo { MyReadOnlyVar = 1 };
}
Is the above an acceptable way of implementing a readonly/immutable object? The immutability of IFoo can be broken with a temporary cast to Foo.
In general (non-critical) cases, is hiding functionality through interfaces a common pattern? Or is it considered lazy coding? Or even an anti-pattern?