public class TeplomerAdapter implements Senzor { private Teplomer teplomer; public…
- User
public class TeplomerAdapter implements Senzor {
private Teplomer teplomer;
public TeplomerAdapter(Teplomer teplomer) { this.teplomer = teplomer; }
@Override public int stav() { if (teplomer.stav()) { return 1; } else { return 0; } }
@Override public int citaj() throws IllegalStateException { if (!teplomer.stav()) { teplomer.zapni(); }
- Assistant
return teplomer.teplota(); }
@Override public void zapni() { teplomer.zapni(); }
@Override public void vypni() { teplomer.vypni(); } }
This is an adapter class that implements the Senzor interface and adapts the Teplomer class to fit that interface. It has a Teplomer object as a field, and all the methods in the Senzor interface are implemented by delegating the call to the appropriate method in the Teplomer object. The TeplomerAdapter class makes it possible to use a Teplomer object in places where a Senzor object is expected.