Created
August 4, 2010 15:33
-
-
Save thedersen/508315 to your computer and use it in GitHub Desktop.
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 IPresenter | |
{ | |
void Initialize(); | |
object UI { get; } | |
} |
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 IMyPresenter : IPresenter | |
{ | |
} |
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 IMyPresenterCallbacks | |
{ | |
void OnSave(); | |
void OnMyTextChanged(); | |
} |
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 MyPresenter : IMyPresenter, IMyPresenterCallbacks | |
{ | |
private IMyView _view; | |
public MyPresenter(IMyView view) | |
{ | |
_view = view; | |
} | |
public object UI | |
{ | |
get { return _view; } | |
} | |
public void Initialize() | |
{ | |
_view.Attach(this); | |
_view.SaveButtonText = "Save"; | |
_view.SaveButtonEnabled = false; | |
} | |
public void OnSave() | |
{ | |
// Save _view.MyText | |
} | |
public void OnMyTextChanged() | |
{ | |
_view.SaveButtonEnabled = !string.IsNullOrEmpty(_view.MyText); | |
} | |
} |
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 IView<TCallbacks> | |
{ | |
void Attach(TCallbacks presenter); | |
} |
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 IMyView : IView<IMyPresenterCallbacks> | |
{ | |
string MyText { get; set; } | |
string SaveButtonText { get; set; } | |
bool SaveButtonEnabled { get; set; } | |
} |
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 MyView : Form, IMyView | |
{ | |
private Button _saveButton; | |
private TextBox _myTextBox; | |
public void Attach(IMyPresenterCallbacks callback) | |
{ | |
_saveButton.Click += (sender, e) => callback.OnSave(); | |
_myTextBox.TextChanged += (sender, e) => callback.OnMyTextChanged(); | |
} | |
public string MyText | |
{ | |
get { return _myTextBox.Text; } | |
set { _myTextBox.Text = value; } | |
} | |
public string SaveButtonText | |
{ | |
get { return _saveButton.Text; } | |
set { _saveButton.Text = value; } | |
} | |
public bool SaveButtonEnabled | |
{ | |
get { return _saveButton.Enabled; } | |
set { _saveButton.Enabled = value; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment