I have a main window and I amgetting data from http client service while form load.
public class MainWindow: Window
{
private IClientService service;
public MainWindow(IClientService service)
{
this.service = service;
GetClient();
}
public async Task<Client> GetClient()
{
try
{
IsDownloading = true;
var client = await service.GetClient();
if(client!=null)
{
if (client.Status)
Visibility = Visibility.Collapsed;
else
Visibility = Visibility.Visible;
ShowClientRegistrationForm();
}else{
HideClientRegistrationForm();
}
}
catch
{
MessageBox.Show("Access error.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
throw;
}
finally
{
IsDownloading = false;
}
}
}
My GetClient()
method does 3 operations.
- Gettting client using service
- Changes the visibility if client status is true or false
- Shows the registration form to user, if client object is null.
I think this is an antipattern. And violates the single responsibility principle. How can I get rid of it?