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
@FunctionalInterface | |
public interface Logger { | |
void logMessage(String message); | |
} |
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 class OpenFileHelper { | |
private final Logger myLogger; | |
public OpenFileHelper() { | |
// logs strategies | |
SystemsLogger systemsLogger = new SystemsLoggerImpl(); | |
LogCatLogger logCatLogger = new LogCatLoggerImpl("OpenFileHelper"); | |
// log manager |
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 class LoggerDispatcher implements Logger { | |
private final List<Logger> loggerList = new ArrayList<>(); | |
public LoggerDispatcher(Logger... loggers) { | |
Collections.addAll(loggerList, loggers); | |
} | |
@Override | |
public void logMessage(String message) { |
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 LogCatLogger extends Logger { | |
} |
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 Presenter { | |
void onUpdateAccount(String newName, String newEmail); | |
void onRemoveAccount(); | |
} |
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 class MainActivity extends AppCompatActivity implements ViewContract { | |
private AccountManagerPresenter presenter; | |
private Button updateAccountButton; | |
private Button removeAccountButton; | |
private EditText nameInput; | |
private EditText emailInput; | |
@Override |
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 class AccountManagerPresenterImpl implements AccountManagerPresenter { | |
private final ViewContract viewContract; | |
public MainPresenter(ViewContract viewContract) { | |
this.viewContract = viewContract; | |
} | |
@Override | |
public void onUpdateAccount(String newName, String newEmail) { |
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 class OpenLogFileActivity extends AppCompatActivity { | |
// some Activity code here | |
private void onOpenLogButtonClick() { | |
// Usando uma classe anônima como Callback | |
new OpenFileHelper("home/log.txt", new OpenFileHelperCallback() { | |
@Override | |
public void onFileOpenSuccess(File file) { | |
// do something with file |
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
// Interface usada na herança | |
interface ParentInterface { | |
void firstMethod(); | |
void secondMethod(); | |
} | |
// Interface derivada de ParentInterface | |
interface ChildInterface extends ParentInterface { | |
// Herança | |
// 1.Não é necessário sobrescrever os métodos herdados de |