public interface INavigationAware
{
void OnNavigatedTo(object parameter);
void OnNavigatedFrom();
}
Current implementation is not correct from the architecture point of view. It forces us to have both methods, when one of them might be surplus.
public async void OnNavigatedTo(object parameter)
{
if (parameter is long orderId)
{
// Do some stuff
}
}
public void OnNavigatedFrom()
{
// Useless
}
Like SOLID Interface Segregation Principle says: Clients should not be forced to implement any methods they don’t use
That's why it would be better to split INavigationAware into two separate interfaces INavigatedTo and INavigatedFrom.
And as a part of code enhancement, it might be possible to make a parameter in OnNavigatedTo(object parameter) strongly typed for the cases, where we have only one possible navigation scenario.
public interface INavigatedTo<T>
{
void OnNavigatedTo(T parameter);
}
public interface INavigatedTo : INavigatedTo<object>
{
}
public interface INavigatedFrom
{
void OnNavigatedFrom();
}
Now
INavigationAware
interface looks like this:Current implementation is not correct from the architecture point of view. It forces us to have both methods, when one of them might be surplus.
Like SOLID Interface Segregation Principle says:
Clients should not be forced to implement any methods they don’t use
That's why it would be better to splitINavigationAware
into two separate interfacesINavigatedTo
andINavigatedFrom
. And as a part of code enhancement, it might be possible to make a parameter inOnNavigatedTo(object parameter)
strongly typed for the cases, where we have only one possible navigation scenario.