user3755946
user3755946

Reputation: 804

Interface not having requirement to implement methods

MY main class...

[Serializable]
    public class SVO : Operation, IAddSizeAbility, IRemoveSizeAbility
    {
        public SerializableDictionary<string, SerializableDictionary<string, decimal>> Data = new SerializableDictionary<string, SerializableDictionary<string, decimal>>();



        public SVO() //Default Constructor
        {
            SerializableDictionary<string, decimal> line = new SerializableDictionary<string, decimal>();
            line.Add("Size - 0", 0.00M);
            Data.Add("OP - 0", line);

        }

        public void AddSize()
        {
            throw new NotImplementedException();
        }
    }

My interfaces...

public interface IAddSizeAbility
    {
        void AddSize();
    }

 public interface IRemoveSizeAbility
    {
        void RemoveSize();
    }

The Issue is although I implement the IAddSizeAbility interace correctly I have not implemented the IRemoveSizeAbility but yet it lets me compile is this a bug?

I can't replicate the issue when i create a new set of interfaces classes.

I have included image so you can see there is no red underline under the interface that is not implemented

I have included image so you can see there is no red underline under the interface that is not implemented

And an image of my test which does what you would expect. And an image of my test which does what you would expect.

Upvotes: 2

Views: 284

Answers (1)

haim770
haim770

Reputation: 49095

When you declare a class of certain type as implementing an interface and that type inherits from another type that is already implementing the interface, the compiler would still be satisfied as the type does not break the contract.

In your case, since Operation already implements IRemoveSizeAbility, you're good to go.

Upvotes: 8

Related Questions