Method hiding with interfaces

Posted by fearofawhackplanet on Stack Overflow See other posts from Stack Overflow or by fearofawhackplanet
Published on 2010-06-18T10:16:06Z Indexed on 2010/06/18 10:23 UTC
Read the original article Hit count: 299

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?

© Stack Overflow or respective owner

Related posts about design-patterns

Related posts about interfaces