Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Do I need to define all the methods when an Interface is implemented ?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 24-01-2011
 
Posts: n/a
Do I need to define all the methods when an Interface is implemented ?
  

I am a free lancer, just started to develop application based on the Java language and the .NET platform , although I am not a professional in it , I am in the learning phase , before this I used to develop web sites using the PHP language. I was designing a GUI in one of the project , in which I had to add certain number of controls and buttons and in had to associate those controls with a few events . I know that I need to implement certain interfaces for that . So I have done that . Apart from the implementing the interfaces I am also including a abstract classes in my program . I cannot actually differentiate that do need to define all the methods in the interface . I will recommend programmers and developers to comment on this .

Reply With Quote
  #2  
Old 24-01-2011
Member
 
Join Date: May 2009
Posts: 501
Re: Do I need to define all the methods when an Interface is implemented ?

An abstract class may include complete or unfinished methods. Interfaces can enclose only the declaration of a method but no body. Thus an abstract class .Is allowed to implement any method but an interface is not permitted to do so. implement methods but an interface can not implement methods.An abstract class can enclose fields, constructors, or destructors and implement it’s behaviors . An interface can not enclose fields, constructors, or destructors and it contains only the property's declaration but not regarding how the properties is being implemented . If not implemented accurately the Abstract class may throw exception.
Reply With Quote
  #3  
Old 24-01-2011
Member
 
Join Date: May 2009
Posts: 523
Re: Do I need to define all the methods when an Interface is implemented ?

Java actually combines the two ideas together a bit. Java interfaces are good and clean while you "implement" an interface, you are instructing that your class remains to the "contract" of the interface that you mention. Java class inheritance is not so precise - when you derive an class from an existing class in the Java programming language in Java you are getting both the code inheritance but you are also implying that that your child class belongs to the "contract" of the interface of the base class.
Reply With Quote
  #4  
Old 24-01-2011
Member
 
Join Date: May 2009
Posts: 614
Re: Do I need to define all the methods when an Interface is implemented ?

Abstract classes in Java are just similar to standard Java classes but with the additional restraint that you cannot create an object of them straight away. In terms of that additional constraint, they are essentially classes which do not in fact implement all of the code mentioned by their "contract".So, it's usually considered good Object oriented practice to mention the "contract" which you desire to stick to through Java interfaces. Then make use of standard Java class inheritance mainly for code reuse point. Make use of abstract Java classes when you wish to render some typical base code but wish/require to oblige the user's of your class to finish the implementation .
Reply With Quote
  #5  
Old 25-01-2011
Member
 
Join Date: May 2009
Posts: 532
Re: Do I need to define all the methods when an Interface is implemented ?

To declare a class that uses an interface, you take in an implements clause in the declaration of a class . Your class is permitted to implement multiple interfaces, so the implements keyword is followed by a comma-separated catalog of the interfaces implemented by the class.
Take an example of interface that describes how to evaluate the size of objects.

Code:
public interface Relatable {

       

   // this (object invoking isLargerThan) and

   // other should be object of the same class

   //   public int isLargerThan(Relatable other);

}
If you want to be capable to contrast the size of related objects, no issue what they are, the class that instantiates them must implement Relatable. Once you are aware that a class implements Relatable, then you are quite familiar that you can contrast the size of the objects created from that class.
Reply With Quote
  #6  
Old 25-01-2011
Member
 
Join Date: May 2009
Posts: 531
Re: Do I need to define all the methods when an Interface is implemented ?

For instance, take the Collection interface introduced on the preceding page. Now, presume that you were writing a class that implemented a FIFO (first in, first out) queue. Since a FIFO queue object include other instances it makes sensible for the class to put into practice the Collectioninterface. The FIFOQueue class would declare that it implements the Collection interface like this:

class FIFOQueue implements Collection {

Statement. . .

void add(Object ob) {

. . .

}

void delete(Object ob) {

Statements. . .

}

Object find(Object ob) {

Statement . . .

}

int curCnt() {

Statement . . .

}

}
Reply With Quote
  #7  
Old 25-01-2011
Member
 
Join Date: Apr 2009
Posts: 479
Re: Do I need to define all the methods when an Interface is implemented ?

By declaring that it implements the Collection interface, the FIFOQueue class ascertains that it renders implementations for the mentioned methods and statements on . An interface just contains the declaration part , it does not contain any body of the method. When any class implements an interface the body of the methods presented that are defined in that particular class . So I know that what you are asking actually , you want to ask that if you are implementing any particular interface , is it mandate to define all the methods present in that interface ? Well it is not mandatory at all that you define all the methods. This situation occurs when you are using an Abstract Class . So it is always preferred and recommended to use the interface instead of an abstract class . I think this post was a bit of assistance to you but in case if you find the language difficult then please revert back I will try to make my language more simpler.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Do I need to define all the methods when an Interface is implemented ?"
Thread Thread Starter Forum Replies Last Post
When is the Windows Live Achievements for The Darkness II implemented. Chinye Video Games 9 16-03-2012 10:33 AM
Is TRIM firmware is implemented in 128 GB Samsung SSD? AliaShaikh Hardware Peripherals 3 11-02-2012 07:56 AM
Windows Developer had Build 8102 Classic Interface and Disabled Metro Interface Garsen's Operating Systems 7 22-10-2011 10:35 PM
Windows Movie Maker Error: "Not implemented” Operatorr Windows Software 3 15-12-2010 04:16 PM
What is Post and Get Method in PHP? How it has been implemented? Rover Software Development 3 05-09-2009 08:23 AM


All times are GMT +5.5. The time now is 11:13 PM.