Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2007, 01:44 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
Rep Power: 0
mew is on a distinguished road
Default Implementing Interface
I have written following interface with 3 abstract methods. Now class implementing this interface have to overwrite all of these 3 methods.

Code:
public interface Mapper {
	public void createSchema();
	public int getNoOfClasses();
        public void setHost(String hostName);
}
I have a situation where one class should implement all of these 3 methods and other should only implement createSchema method. How this is possible using this interface.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-06-2007, 05:10 PM
Member
 
Join Date: Dec 2007
Posts: 4
Rep Power: 0
ldb88 is on a distinguished road
Default
The other class should not implement this interface if it shouldn't implement all the functions. You could just put something like
Code:
public int getNoOfClasses(){
}
depending on what is required. It might be better if you had two interfaces.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-06-2007, 10:09 PM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
You must provide the method declaration for each method defined in the implemented interface. What you do in the method body is up to you.
In pseudo code:
Code:
public interface Mapper {
    public void createSchema();
    public int getNoOfClasses();
    public void setHost(String hostName);
}

class NeedAllMethods implements Mapper {
    public void createSchema() {
        // implementation...
    }

    public int getNoOfClasses() {
        // implementation...
        return intValue;
    }

    public void setHost(String hostName) {
        // implementation...
    }
}

class NeedOnlyOne implements Mapper {
    public void createSchema() {
        // no-op okay
    }

    public int getNoOfClasses() {
        // no-op okay but you must
        // return an int value.
        return 0;
    }

    public void setHost(String hostName) {
        // no-op okay
    }
}
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-16-2010, 03:48 PM
Member
 
Join Date: Mar 2009
Posts: 1
Rep Power: 0
Enlivesnivy is on a distinguished road
Default
Su internet aumentano i siti web di aste al ribasso .

“Si gioca con le aste al ribasso ”, attraverso il meccanismo dell asta al ribasso . È l’ultima intuitiva creazione scovata nell’infinito universo della rete. Sul portale www.bidmouse.com - www.bidsnake.com o ancora www.fourbid.com www.strikebid.com www.goldengavel.it , si può acquistare di tutto al prezzo più basso della rete con un’offerta bassa e soprattutto unica.

Il congegno è lineare e le transazioni sono assolutamente prive di pericoli. Nella vetrina di qualsiasi sito di aste al ribasso andando nelle “Aste Aperte” sono esposte le proposte commerciali, comprensive del reale valore, ed il tempo residuo stimato per lanciare l’offerta, naturalmente con le asta al ribasso .

Dopo aver scelto il prodotto (un week-end distensivo piuttosto che uno scooter, ma anche orologi, cellulari e televisioni), si punta sul prezzo esatto per assicurarselo: vince l’ asta al ribasso , l’utente che ha formulato l’offerta ad un prezzo inferiore e soprattutto unico.

Se infatti il prezzo prescelto è già opzionato aste al ribasso , le due offerte automaticamente decadono. Se due utenti, ad esempio, decidono di offrire dieci euro per un computer portatile asta al ribasso , entrambi vengono eliminati dal gioco, mentre se un terzo ne offre undici, ed è l’unico a presentare l’offerta più bassa, il computer portatile è venduto a soli undici euro.

Un gioco, che s’intreccia con la fortuna ed un software che garantisce efficienza, affidabilità e sicurezza aste al ribasso . Sono questi gli ingredienti principali di quest’ultima innovazione tecnologica: un vaso di terracotta che non vuol rompersi in mezzo a molti vasi di ferro asta al ribasso .

Molti di questi siti sono recensiti sulla directory di aste al ribasso , dove è possibile commentare, votare, cercare spiegazioni e trucchi per vincere in qualsiasi asta al ribasso
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-16-2010, 04:33 PM
Member
 
Join Date: Feb 2010
Posts: 60
Rep Power: 0
m00nchile is on a distinguished road
Default
Originally Posted by hardwired View Post
You must provide the method declaration for each method defined in the implemented interface. What you do in the method body is up to you.
In pseudo code:
Code:
public interface Mapper {
    public void createSchema();
    public int getNoOfClasses();
    public void setHost(String hostName);
}

class NeedAllMethods implements Mapper {
    public void createSchema() {
        // implementation...
    }

    public int getNoOfClasses() {
        // implementation...
        return intValue;
    }

    public void setHost(String hostName) {
        // implementation...
    }
}

class NeedOnlyOne implements Mapper {
    public void createSchema() {
        // no-op okay
    }

    public int getNoOfClasses() {
        // no-op okay but you must
        // return an int value.
        return 0;
    }

    public void setHost(String hostName) {
        // no-op okay
    }
}
This code would compile, but I don't think it's a very good programming practice, the purpose of interfaces is code that runs, even when you change the implementation, as long as it adherres to the interface. So making a class that doesn't make all the methods functional would be counter-intuitive, and possibly create a maintenance nightmare. Like the suggestion above, you should rather use 2 interfaces for this problem.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
An interface extending an interface(II) JavaForums Java Blogs 0 03-12-2008 04:00 PM
Implementing an interface bugger Advanced Java 1 01-09-2008 02:35 PM
Implementing ActionListener interface JavaForums Java Blogs 0 12-19-2007 10:54 PM
Creating a Thread (implementing Java Runnable Interface) JavaForums Java Blogs 0 12-19-2007 10:31 AM
Implementing Serializable interface javaplus Advanced Java 4 12-18-2007 01:29 PM


All times are GMT +2. The time now is 05:18 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org