java:interface_implementation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
java:interface_implementation [2017/03/31 13:13]
gthanos
java:interface_implementation [2017/03/31 13:14]
gthanos [SimpleTimer]
Line 5: Line 5:
 Σε συνέχεια του προηγούμενου παραδείγματος θα επιχειρήσουμε να δημιουργήσουμε δύο διαφορετικές κλάσεις που υλοποιούν το συγκεκριμένο //​interface//​. Οι κλάσεις αυτές είναι **SimpleTimer** και **StartStopTimer**. Και οι δύο κλάσεις παρέχουν την ίδια λειτουργικότητα. Σε συνέχεια του προηγούμενου παραδείγματος θα επιχειρήσουμε να δημιουργήσουμε δύο διαφορετικές κλάσεις που υλοποιούν το συγκεκριμένο //​interface//​. Οι κλάσεις αυτές είναι **SimpleTimer** και **StartStopTimer**. Και οι δύο κλάσεις παρέχουν την ίδια λειτουργικότητα.
  
-==== SimpleTimer ====+===== SimpleTimer ​=====
  
 <code java SimpleTimer.java>​ <code java SimpleTimer.java>​
Line 18: Line 18:
   public boolean startTimer() {   public boolean startTimer() {
     Date now = new Date();     Date now = new Date();
-    //​System.err.println("​[startTimer] duration: "​+duration);​ 
     if(duration > 0) {     if(duration > 0) {
       start_time = now.getTime();​       start_time = now.getTime();​
       running = true;       running = true;
-      //​System.err.println("​[startTimer] Running again!"​);​ 
     }     }
     else {     else {
-      //​System.err.println("​[startTimer] Failed to start!"​);​ 
       running = false;       running = false;
     }     }
Line 44: Line 41:
   public boolean hasExpired() {   public boolean hasExpired() {
     Date now = new Date();     Date now = new Date();
-    //​System.err.println("​[hasExpired] running: "​+running);​ 
     if( (running && now.getTime() - start_time >= duration) || duration <= 0 ) {      ​     if( (running && now.getTime() - start_time >= duration) || duration <= 0 ) {      ​
       start_time = 0L;       start_time = 0L;
java/interface_implementation.txt · Last modified: 2019/04/05 17:20 by gthanos