Polymorphism is the concept that different objects have different implementations of the same characteristic and Interfaces provide early binding to an object, which can greatly improve performance and also provide type protection at compile time
Size: 99.42 KB
Language: en
Added: Jul 02, 2019
Slides: 20 pages
Slide Content
POLYMORPHISM,INTERFACE AND IMPLENTING INTERFACE USING POLYMORPHISM 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. 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. INTERFACE :
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. OVERVIEW
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, DESIGNING AND DEFINING INTERFACES:
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: INTERFACE IMPLEMENTATION SEMANTICS 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. INTERFACE-BASED PROGRAMMING
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. CHANGES TO INTERFACES IN VB.NET
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. INTERFACES INSTEAD OF CLASS INHERITANCE:
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. DECLARING INTERFACES
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. IMPLEMENTING INTERFACES
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. IMPLEMENTS KEYWORD
Class Class1 Implements interfaceclass.interface2 Sub Sub1 (ByVal i AsInteger) Implements interfaceclass.interface2.Sub1 EndSub EndClass IMPLEMENTS A METHOD OF AN INTERFACE
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. CLASSES FOR INTERFACES
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: INTERFACE-BASED POLYMORPHISM [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 IMPLICIT INTERFACES
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. EXPLICIT INTERFACES
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(); } EXTENDING INTERFACES
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 INTERFACE IMPLEMENTATION EXAMPLES
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. CONCLUSION