Monday, May 30, 2011

How to use interface without implementing methods...?


public interface IPerson{


       public void savePerson(Contact contact);
}


public class HulkHogan { 


       private IPerson person;


       public HulkHogan(IPerson person){
    
             this.person = person;
       }


        public void doSomething(Contant contact){
    
              person.savePerson(contact);          //call your method here
        }
}

Statically, you can declare it to be called.  You don't necessarily have to implement the interface inside the calling class.  But in order to execute it, you will need to implement it somewhere, because interface just describes how something behaves but does not provide the actual behaviour (i.e. does not implement it).