Question

In an application I developed with C#, I use a webbrowser control, it should navigate to some websites, then I would like to extract some contents from the webpages. I do it by manipulation of DOM and removing some nodes. It can be done automatically or manually with the help of user.

Then I have two modes, surfing mode and extraction mode. I think switching between modes and updating related controls and menus and responding to events... has made my program complicated. What is your advice to make it less complicated?

Does Separation of Concerns applies to GUI components too?

Était-ce utile?

La solution

Separation of concerns is just as important in UI as anywhere else, if not more so. Anything that doesn't directly involve user interaction does not belong in the UI. It belongs somewhere else.

Consider what happens when you create a UI having the usual event hooks:

private void Form1_Load(object sender, EventArgs e)
{
    listView1.Items.Add(new ListViewItem("this is a test"));
}

What happens if you put all of your business logic in your form? You wind up with a big ball of mud, that's what. That's why we put business logic in another module, class or DLL.

Whether this is what's happening with your application is an open question. As I see it, there's two possible approaches. You can have a single UI with two modes, or two different UI's. If the modes are dramatically different, I usually prefer two different UI's, as you can avoid all of the if statements that way, and your design is generally cleaner. You can refactor common functionality between the two UI's into a separate module, class or DLL.

Licencié sous: CC-BY-SA avec attribution
scroll top