#436 – The Implementation of an Interface Can Be a Subset of the Class

When a class implements an interface, it is declaring that it implements all members of the interface.  Client code can interact with an instance of the class through the members of the interface.  It can also interact with class members that are not part of the interface.

For example, assume that the Cow class implements the IMoo interface, which contains the Moo method.  Client code can invoke the Moo method on instances of the Cow class, since it implements IMoo.

            Cow bossie = new Cow("Bossie", 5);

            // Invoke IMoo.Moo
            bossie.Moo();

Clients can also call methods that are not part of the IMoo interface.

            // Call methods and set properties that are NOT part of IMoo
            bossie.MakeSomeMilk();
            bossie.Motto = "Docile but still a maverick";

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a comment