This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface MobileShop { | |
public void modelNo(); | |
public void price(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Java; | |
public class TehHijau implements Minuman{ | |
private String namaMinuman = TehHijau.class.getSimpleName(); | |
@Override | |
public void rasa{ | |
//……. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Makanan{ | |
void harga(); | |
} | |
package Java. | |
public interface Minuman{ | |
void rasa(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Package class MinumanFactory extends AbstractFactory { | |
@Override | |
Minuman getMinuman(String minuman) { | |
if (minuman.equals(JenisMinuman.Teh_Tawar)){ | |
return new TehTawar(); | |
} | |
else if (minuman.equals(JenisMinuman.Teh_Manis)){ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Package class MakananFactory extends AbstractFactory { | |
@Override | |
Makanan getMakanan(String makanan) { | |
if (makanan.equals(JenisMakanan.Nasi_Goreng)){ | |
return new NasiGoreng(); | |
} | |
else if (makanan.equals(JenisMakanan.Nasi_Padang)){ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Java; | |
public abstract class AbstractFactory { | |
abstracy Makanan getMakanan(String makanan); | |
abstract Minuman getMinuman(String minuman); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ConcreteState | |
public class StandbyState implements State { | |
public void pressPlay(MP3PlayerContext context) { | |
context.setState(new PlayingState()); | |
} | |
} | |
public class PlayingState implements State { | |
public void pressPlay(MP3PlayerContext context) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//State | |
private interface State { | |
public void pressPlay(MP3PlayerContext context); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Context | |
public class MP3PlayerContext { | |
private State state; | |
private MP3PlayerContext(State state) { | |
this.state= state; | |
} | |
public void play() { | |
state.pressPlay(this); |
NewerOlder