Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Sample only for ate charms ^_^
- */
- public class SomeController implements SomeViewActionListener, SomeModelEventListener {
- private SomeModel someModel;
- private SomeView someView;
- public SomeController() {
- someModel = new SomeModel(this);
- someView = new SomeView (this);
- }
- @Override
- public void onDownloadSomethingCommand() {
- someModel.downloadSomething();
- }
- @Override
- public void onDownloadDone(Content content) {
- someView.displaySomeContent(content);
- }
- }
- public class SomeModel {
- private SomeModelEventListener eventListener;
- public SomeModel(SomeModelEventListener eventListener) {
- this.eventListener = eventListener;
- }
- public void downloadSomething() {
- // ... download on a different thread, since this is a different thread, a return is not possible
- // or else the UI will be blocked
- // .. when done: where content is the content downloaded
- eventListener.onDownloadDone(content);
- }
- }
- public class SomeView() {
- private Button bDownloadSomethingButton;
- private SomeViewActionListener actionListener;
- public SomeView(SomeViewActionListener actionListener) {
- this.actionListener = actionListener;
- // This is inversion of control as well
- bDownloadSomethingButton.setOnClickListener(new OnCLickListener() {
- actionListener.onDownloadSomethingCommand();
- });
- }
- public void displaySomeContent(Content content) {
- // display content here
- }
- }
- public interface SomeViewActionListener {
- public void onDownloadSomethingCommand();
- }
- public interface SomeModelEventListener {
- public void onDownloadDone(Content content);
- }
Advertisement
Add Comment
Please, Sign In to add comment