Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey fellow CP'ians,

thinking about my SW Architecture again i just came to the question if decoupling both ways by interfaces makes sense for the sake of decoupling.

Here is the spoken idea:
I create a controler for the UI so that the controler can do all the business stuff and the UI stays mostly dumb. I have a reference on the controler in the UI to access it's public functions. The controler implements the controlerspecific interface.

The controler on the other hand has a reference to the ui via the interface. With this i guarantee that the functions called by the controler are "implemented" in any UI that implements the interface.

Long story in code

C#
public class UcProjectProperties : IProjectPropertiesView
{
    ProjectPropertiesControler _projPropContr = new ProjectPropertiesControler(this);

    public void UpdateUi()
    {
        //Do the update
    }

    private void ProcessUserInput()
    {
        //Get input and hand to Controler
        _projPropContr.GenerateUpdateData();
    }
}

The Interface of the Uc
C#
public interface IProjectPropertiesView
{
    void UpdateUi();
}

The controler
C#
public class ProjectPropertiesControler : IProjectPropertiesControler
{
    IProjectPropertiesView _view;

    public void ProjectPropertiesControler(IProjectPropertiesView InView)
    {
        _view = InView;
    }

    public void GenerateUpdateData()
    {
        //Generate the data and update the Ui
        _view.UpdateUi();
    }
}

The Interface of the Controler
C#
public interface IProjectPropertiesView
{
    void GenerateUpdateData();
}


I thought it to be a good idea because now i can unit test very easily but i am afraid it is a bit over the top?

You guys think that's a correct way or should i reduce to only one interface?

Thanks in advance

What I have tried:

Code written above and explained :)
Posted
Comments
FranzBe 16-Oct-17 7:58am    
The view interface makes the controller/presenter testable. That's the valuable part. I don't have the controller interface in my projects. I don't see what the controller interface might add to the story. So the creator of the controller know's the actual controllers type an there is a tight coupling at this point. So far I did not run into problems about this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900