An interface is means of making a contract with a class for services that the interface stipulates.
You cannot create an instance of an interface
A class can implement one or more interfaces
A class can inherit from only a single parent, but a class can implement multiple interfaces
Any class that implements an interface must implement all the members of the interface as they are defined.
An interface should not be changed once it has been deployed in your solution.

When it implements a Visual Basic class in effect promises to provide the functionality the interface specirfies.
Visual Basic also supports interfaces

An interface is a contract that guarantees to a client how a class or structure will behave.
When a class implements an interface, it tells the client that they guarantee certain methods, properties, events and indexers of the named interface.
An interface offers an alternative to a MustInherit class for creating contracts amound classes and their clients.
These contracts are made manifest using the Interface keyword which declares a reference type that encapsulates the contract.
Syntactically an interface is like a class that only MustInherit methods.

often used as a way of implementing multiple inheritance
all access modifiers are assumed to be public

Express what is common across classes
Allow classes to share a common design
Allows lose coupling between components
Cannot include any implementation details (or fields)

interface IMyInterface 
   void Draw(); //method
   string Name { get; } //property
   object this[int n] { get; } //indexer

class Instance1 : IMyInterface
   public void Draw() {----}
   public string Name { get { return("one"); } }
   object this[int n] { get { return(---); } }

class Instance2 : IMyInterface
   public void Draw() {----}
   public string Name { get { return("two"); } }
   object this[int n] { get { return(---); } }

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopNext