[Testdome] Alert Service

whitehousechef·2023년 12월 5일

1) no need public abstract keywords in interface they are implicit
2) if question gave as AlertDAO the naming has to be exact, AlertDao is wrong

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

class AlertService {
    private AlertDAO storage;
    public AlertService(AlertDAO alertDao){
      this.storage = alertDao;
    }
    
		
    public UUID raiseAlert() {
        return this.storage.addAlert(new Date());
    }
	
    public Date getAlertTime(UUID id) {
        return this.storage.getAlert(id);
    }	
}

class MapAlertDAO implements AlertDAO{
    private final Map<UUID, Date> alerts = new HashMap<UUID, Date>();
	
    public UUID addAlert(Date time) {
    	UUID id = UUID.randomUUID();
        this.alerts.put(id, time);
        return id;
    }
	
    public Date getAlert(UUID id) {
        return this.alerts.get(id);
    }	
}

interface AlertDAO {
   UUID addAlert(Date time);
   Date getAlert(UUID id); 
}

0개의 댓글