By
G.KARTHIGA MSC IT
NADAR SARASWATHI COLLEGE OF
ARTS AND SCIENCE
THENI
 Definition:-
"Manipulated the object of various classes and invoke method on
one object without knowing the object type".
 Polymorphism can be divide in to two parts, that are given bellow:
1) Compile time polymorphism
2) Run time polymorphism
Compile time polymorphism:-
compile time polymorphism achieved by "Method
Overloading", means that same name function with deferent
parameters in same class called compile time polymorphism.
 Interfaces allow us to create definitions for
component interaction.
 They also provide another way of
implementing polymorphism.
 The public members are thought of as
comprising the class's interface because they
are the only way that code outside of the
class can interact (i.e., interface) with objects
of that class.
 In software development, the interface is the faculty
of abstraction, coupling (loose or tight), and
polymorphism.
 The formal interface class provides an important
facility for polymorphism in .NET.
 The implementation of the IClonable, IComparable,
and IEnumerable interfaces.
 This factoring is the process of deciding what
properties, events, and methods are to be included in
a certain interface.
 When you start cluttering up the interface with
unrelated methods and properties.
 For example:
 splitting a collection of ten financial methods for
an accounting interface into two interfaces, one for
debits and one for credits,
 The Implements keyword as demonstrated earlier to
signify that a class implements a specific interface.
 This is achieved by providing a comma−separated list
behind the Implements keyword, as follows:
Public Class SeaFood
Implements IShrimps, IScallops,
IOysters, ICrabs
 Building component-based solutions has a number of
unique problems and benefits.
 The completed implementation can be used, and
finally some time later, a completely new
implementation can be used to replace the initial
implementation.
 Interfaces make the complete software development
process easier.
 A few enhancements have been made to interfaces in
Visual Basic.NET. The most important of these is that
events can now be part of an interface.
 The mechanism for defining an interface has also
been changed.
 This technique allows a developer to continually
change which component he actually uses.
 Interfaces are better suited to situations in which your
applications require many possibly unrelated object
types to provide certain functionality.
 Interfaces are more flexible than base classes because
you can define a single implementation that can
implement multiple interfaces.
 Interfaces are better in situations in which you do not
have to inherit implementation from a base class.
 In a namespace, interface statements are Friend by
default, but they can also be explicitly declared
as Public or Friend. Interfaces defined within classes,
modules, interfaces, and structures are Public by
default, but they can also be explicitly declared
as Public, Friend, Protected, or Private.
 Interfaces cannot contain any implementation code or
statements associated with implementation code, such
as End Sub or End Property.
 The Visual Basic reserved word Implements is used
in two ways.
 The Implements statement signifies that a class or
structure implements an interface.
 The Implements keyword signifies that a class
member or structure member implements a specific
interface member.
 The Implements keyword requires a comma-
separated list of interface members to be
implemented.
 The specification of an interface member consists of
the interface name, which must be specified in an
implements statement within the class; a period; and
the name of the member function, property, or event
to be implemented.
 The name of a member that implements an interface
member can use any legal identifier.
Class Class1
Implements interfaceclass.interface2
Sub Sub1(ByVal i AsInteger)
Implements interfaceclass.interface2.Sub1
EndSub
EndClass
 Polymorphism implies that you can have many
different implementations (code) of a method behind
a single interface.
 Methods are defined in interfaces by providing only
the signature, which consists of the method's
identifier ( and formal parameter list.
 The interface and the definition become part of a
contract between the implement and the interface
provider for the purpose of enabling polymorphism at
the method level.
 In interface-based polymorphism, the interface
defines the properties, methods, and events to be
implemented similar to the definition of abstract
members in a class.
 The syntax to define the interface appears as follows:
[Public|Friend|Private|Protected] Interface
Name„
Interface definition statements
End Interface
 All standard class declarations and member
declarations implicitly expose interfaces so that their
objects can be referenced and their functionality and
data accessed in predefined and regulated ways.
 This implicit, but always present, interface comprises
the standard object's identifier and the encapsulated
method signatures
 In .NET provides a form of reference type that allows
you to explicitly declare an interface and keep it
completely separate from any implementation.
 In other words, the interface class and the class that
implements the interface represent the most loosely
coupled arrangement of classes you can achieve in
the .NET Framework.
 An interface may also extend another interface.
 In that case, the extender is known as the super interface and
the extended is the sub interface.
 Example:
interface AInterface{
int A();
}
interface AInterface2 extends AInterface{
int a2();
}
Interface Interface1
Sub sub1(ByVal i As Integer)
End Interface
‘Demonstrates interface inheritance’.
Interface Interface2
Inherits Interface1
Sub M1(ByVal y As Integer)
ReadOnly Property Num() As Integer
End Interface
 Interfaces define the properties, methods, and events
that classes can implement. Interfaces allow you to
define features as small groups of closely related
properties, methods, and events; this reduces
compatibility problems.
 You can add new features at any time by developing
additional interfaces and implementations.

Polymorphism and interface in vb.net

  • 1.
    By G.KARTHIGA MSC IT NADARSARASWATHI COLLEGE OF ARTS AND SCIENCE THENI
  • 2.
     Definition:- "Manipulated theobject of various classes and invoke method on one object without knowing the object type".  Polymorphism can be divide in to two parts, that are given bellow: 1) Compile time polymorphism 2) Run time polymorphism Compile time polymorphism:- compile time polymorphism achieved by "Method Overloading", means that same name function with deferent parameters in same class called compile time polymorphism.
  • 3.
     Interfaces allowus to create definitions for component interaction.  They also provide another way of implementing polymorphism.  The public members are thought of as comprising the class's interface because they are the only way that code outside of the class can interact (i.e., interface) with objects of that class.
  • 4.
     In softwaredevelopment, the interface is the faculty of abstraction, coupling (loose or tight), and polymorphism.  The formal interface class provides an important facility for polymorphism in .NET.  The implementation of the IClonable, IComparable, and IEnumerable interfaces.
  • 5.
     This factoringis the process of deciding what properties, events, and methods are to be included in a certain interface.  When you start cluttering up the interface with unrelated methods and properties.  For example:  splitting a collection of ten financial methods for an accounting interface into two interfaces, one for debits and one for credits,
  • 6.
     The Implementskeyword as demonstrated earlier to signify that a class implements a specific interface.  This is achieved by providing a comma−separated list behind the Implements keyword, as follows: Public Class SeaFood Implements IShrimps, IScallops, IOysters, ICrabs
  • 7.
     Building component-basedsolutions has a number of unique problems and benefits.  The completed implementation can be used, and finally some time later, a completely new implementation can be used to replace the initial implementation.  Interfaces make the complete software development process easier.
  • 8.
     A fewenhancements have been made to interfaces in Visual Basic.NET. The most important of these is that events can now be part of an interface.  The mechanism for defining an interface has also been changed.  This technique allows a developer to continually change which component he actually uses.
  • 9.
     Interfaces arebetter suited to situations in which your applications require many possibly unrelated object types to provide certain functionality.  Interfaces are more flexible than base classes because you can define a single implementation that can implement multiple interfaces.  Interfaces are better in situations in which you do not have to inherit implementation from a base class.
  • 10.
     In anamespace, interface statements are Friend by default, but they can also be explicitly declared as Public or Friend. Interfaces defined within classes, modules, interfaces, and structures are Public by default, but they can also be explicitly declared as Public, Friend, Protected, or Private.  Interfaces cannot contain any implementation code or statements associated with implementation code, such as End Sub or End Property.
  • 11.
     The VisualBasic reserved word Implements is used in two ways.  The Implements statement signifies that a class or structure implements an interface.  The Implements keyword signifies that a class member or structure member implements a specific interface member.
  • 12.
     The Implementskeyword requires a comma- separated list of interface members to be implemented.  The specification of an interface member consists of the interface name, which must be specified in an implements statement within the class; a period; and the name of the member function, property, or event to be implemented.  The name of a member that implements an interface member can use any legal identifier.
  • 13.
    Class Class1 Implements interfaceclass.interface2 SubSub1(ByVal i AsInteger) Implements interfaceclass.interface2.Sub1 EndSub EndClass
  • 14.
     Polymorphism impliesthat you can have many different implementations (code) of a method behind a single interface.  Methods are defined in interfaces by providing only the signature, which consists of the method's identifier ( and formal parameter list.  The interface and the definition become part of a contract between the implement and the interface provider for the purpose of enabling polymorphism at the method level.
  • 15.
     In interface-basedpolymorphism, the interface defines the properties, methods, and events to be implemented similar to the definition of abstract members in a class.  The syntax to define the interface appears as follows: [Public|Friend|Private|Protected] Interface Name„ Interface definition statements End Interface
  • 16.
     All standardclass declarations and member declarations implicitly expose interfaces so that their objects can be referenced and their functionality and data accessed in predefined and regulated ways.  This implicit, but always present, interface comprises the standard object's identifier and the encapsulated method signatures
  • 17.
     In .NETprovides a form of reference type that allows you to explicitly declare an interface and keep it completely separate from any implementation.  In other words, the interface class and the class that implements the interface represent the most loosely coupled arrangement of classes you can achieve in the .NET Framework.
  • 18.
     An interfacemay also extend another interface.  In that case, the extender is known as the super interface and the extended is the sub interface.  Example: interface AInterface{ int A(); } interface AInterface2 extends AInterface{ int a2(); }
  • 19.
    Interface Interface1 Sub sub1(ByVali As Integer) End Interface ‘Demonstrates interface inheritance’. Interface Interface2 Inherits Interface1 Sub M1(ByVal y As Integer) ReadOnly Property Num() As Integer End Interface
  • 20.
     Interfaces definethe properties, methods, and events that classes can implement. Interfaces allow you to define features as small groups of closely related properties, methods, and events; this reduces compatibility problems.  You can add new features at any time by developing additional interfaces and implementations.