Tuesday, November 29, 2011

Why do you create interfaces, and when MUST you use one?

You would create interfaces when you have two or more functionalities talking to each other. Doing it this way help you in creating a protocol between the parties involved.:interfaces are only declarations , for that can change our functionaly with greate extent:Interfaces are mainly used for two purposes:Java does not support multiple inheritance. But it supports multiple implimentations. i.e. A class can implement more than one interfaces.So,we can make muliple inheritances indirectly through the interfaces:Interfaces define only declaration of methods and final data members.We use them when we want different definitions of methods in different classes for different purposes.:Interface is a way to provide loose coupling between the modules of an application . With the advent of frameworks like Spring this is very clear .An interface is also a very suitable way of defining a blueprint of functionality during the initial phases of a project (or more appropriately during design time).JVM and lot of frameworks/appservers use callback methods to provide run time polymorphism (Dynamic method dispatch) by using interfaces:Interface is a tool provided by Java to achieve the multiple inheritance mechanism, which is not possible directly.:Interface class is the class thru which calling function interacts with implementation methods. By using virtual keyword infront of "Implementation methods" declaration, the class can become Interface class. Late(run time) binding,Encapsulation(APIs)and avoid ambiguity between multiple inheritance could be overcome with the Interface classes.:Interface is the class thru which calling class methods can be interacted with "Implementation class" methods. By using "virtual" keyword infront of "implementation methods" declarations in the class, become interface class. Encapsulation(APIs), avoid ambiguity between multi inheritance and late binding can be achieved thru interface class implementation..:INTERFACE is a contract between class and the outside world and this contract is enforced at build time by the computer.:Interface is a way to provide more userfriendly front end envirenmentto work on it.To clubbing many modules in a single frame we need a good interface that provides a good way to access all functionality of the system.:programmer goes for the interfaces when all the features(methods) have different implementations in different objects.we can also achieve multiple inheritance through interfaces.:A programmer writes an interfaces , when all the features have different implementations for different objects. :Its not that we use interfaces as an option for inheritence, because when we inherite something we are including all that methods which are present in a super class, while interface just describes a prototype of the method it does not does not describe its complete body. :Interface is created when there is a need of relating two or more classes, say if we want to create relation of a sub class from two of the super classes(but practically this is not possible in java as it does not support multiple inheritance). so with the help of interfaces we can inherit the super classes.:interface are mainly in place of multiple inheritence and interface act as a common class to all oher classes:Interfaces are used in Java to declare functinalities of entities which may have same functinalities but implemented them in different ways, and in this way conforming them to a standard defined in the interface. For example ( completely illusive ) , :There are two main reason two create an interface : :in java there is no multiple inheritance,so to achieve multiple inheritance in java we must use interface concept:Interface is a way to provide loose coupling between the modules of an application . With the advent of frameworks like Spring this is very clear .An interface is also a very suitable way of defining a blueprint of functionality during the initial phases of a project (or more appropriately during design time).JVM and lot of frameworks/appservers use callback methods to provide run time polymorphism (Dynamic method dispatch) by using interfaces:You would create interfaces when you have two or more functionalities talking to each other. Doing it this way help you in creating a protocol between the parties involved.:Interface is just like special classes. in this is use only declare memeber function not definition. it is use as a templets. when we want to call which function then declare function defination in his class. :it is used to declare abstract classes and symbolic notation like 3.14 we can extend it through implementation.:Mainly we use interfaces for two reasons:iterface is used make the connection between two function and make it easy to implement by class:Interface provides an abstract form of a method that can by further implemented by their implemented Class. Methods in an interface are the generalized methods and implementation is depend upon their subclass behavior. Further to provide a feel of multiple inheritance in terms of Interface which is not possible with Java Classes.:You would create interfaces when you have two or more functionalities talking to each other. Doing it this way help you in creating a protocol between the parties involved.:Only method declaration is possible in interface.But in abstract class it is possible to define methods.:Only method declaration is possible in interface.But in abstract class it is possible to define methods.:Interfaces provide basic behavior for an application/module which can be implemented/improved further by the classes which are going to implement the interface, and an application with interfaces will always have multiple inheritance facility.:In java interface is used for two main purpose:Interface in java used in two purposes.:Interface is the colletion of method declaration.only declaration not defination ,so interface solve the multipul inheritance prob,if you want to inherit multipul method you can use interface.:We can use interfaces to declare a set of methods that will be used in different classes for different purposes.:Incase of using same method for different functionality we have to use interface.:we create interface bcoz ...:encapsulation implies program and codes in single unit:Through interface one class can inherit the properties of multiple classes in multiple inheritence trees.Its also possible through multiple inheritence but complexity increases.thats why java does not allow multiple inheritence but indirectly give the facility through interface.:we create interface :Interface is a blueprint for implementing several types of methods in different classes.In project implementation initially lead people think about the Interfaces and they ll design.and also multiple inheritance is also possible. :Interface is a blue print which has methods declaration and final variables. It is common lass for many other class. Interface is created to implement the multiple inheritance which java doesn&
Category:Java Interview Questions

No comments:

Post a Comment