It looks like a shower

Now I have a bit more functionality and it is time to do some refactorings again. The todo note that tempts me most is to take care of the asymmetry between the two views, and especially to see if I can introduce a shower for the AddSongView. Here is the code that shows the view, taken from the SongsShower.

public class SongsShower
{
// ...
 
private void OnAddButtonClick()
{
var view = AddSongViewFactory.Create();
view.OnCancelButtonClick += view.CloseView;
view.ShowView();
}
}

From this method, what I should do is create an AddSongShower class and call a Show() method on it, just like I do with the SongsShower in Application.

public class Application : ApplicationContext
{
// ...
 
public void Start()
{
View.OnViewClosed += () => CloseAction( this );
new SongsShower(View, AddSongViewFactory).Show();
}
}

Following this pattern, I ought to change the OnAddButtonClick() method to look like this.

private void OnAddButtonClick()
{
var view = AddSongViewFactory.Create();
new AddSongShower(view).Show();
}

That is, I should first create the view and then pass it into the AddSongShower constructor, since that's what I do when showing the SongsView. However, I wonder if this is correct. Is it really the SongsShower's responsibility to create the AddSongView? That doesn't sound right. The SongsShower should handle things that have to do with the SongsView, not things that have to do with AddSongView.

This argues for that I should pass in the AddSongViewFactory to the AddSongShower and let that shower create the view in the Show() method. But then I would not follow the same pattern as when creating the SongsShower.

So why is SongsShower different? Well, it is becuase Application needs to hook on to the OnViewClosed event on the SongsView to perform the closeAction. I don't know how to solve this in another way right now, so I decide to live with the asymmetry for now, passing a view factory to the AddSongShower and a view to the SongsShower.

public class SongsShower
{
// ...
 
private void OnAddButtonClick()
{
new AddSongShower(AddSongViewFactory).Show();
}
}
 
public class AddSongShower
{
private IAddSongViewFactory AddSongViewFactory { get; set; }
 
public AddSongShower(IAddSongViewFactory addSongViewFactory)
{
AddSongViewFactory = addSongViewFactory;
}
 
public void Show()
{
var view = AddSongViewFactory.Create();
view.OnCancelButtonClick += view.CloseView;
view.ShowView();
}
}

I run the tests and they are all still green. So I check in my changes. Then I throw away my todo note about not having a shower for the AddSongsView, but write another one about the asymmetry between the two showers.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>