LeftTwixWand / Inventory

New version of Microsoft Inventory sample, built on WinUI 3, using DDD and Clean Architecture approach
MIT License
71 stars 10 forks source link

Split INavigationAware into separate interfaces #25

Open LeftTwixWand opened 1 year ago

LeftTwixWand commented 1 year ago

Now INavigationAware interface looks like this:

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();
}
LeftTwixWand commented 1 year ago

It would also be good to have a few navigation scenarios with different parameters.

LeftTwixWand commented 1 year ago

Navigation service needs to be refactored, because part of navigation process is handled in NavigatedEventHandler