Separating UI and logic in C#

Andy picture Andy · Jun 25, 2010 · Viewed 21.1k times · Source

Does anyone have any advice on keeping logic out of my GUI classes? I try to use good class design and keep as much separated as possible, but my Form classes usually ends up with more non-UI stuff mixed in than I'd like, and it tends to make maintenance a real pain.

(Visual Studio 2008 Professional, C#, Windows apps).

Many thanks.

Answer

ChrisW picture ChrisW · Jun 25, 2010

Put your logic in a separate assembly; and, build that assembly without its referencing any GUI packages (e.g. System.Drawing, System.Windows.Forms, etc.).