1

This may be a bit of a general question.
I'm looking for suggestions on how to design (from an architecture, I think thats the right word, perspective).

I'm building an application that will include the following:

1) WPF Windows (Currently have this set as the main entry point)

2) SQL Server transactions (considering using CLR SP as suggested in that link)

3) And a whack of background math

I'm trying to figure out if should do all of this logic in a number of partial classes:

public partial class MainWindow : Window

or if I should code the SQL material in a separate class... etc.

Any thoughts, suggestions are much appreciated!

P.S. The SQL connection will have be kept open the entire time, if that makes a difference

Community
  • 1
  • 1
keynesiancross
  • 3,441
  • 15
  • 47
  • 87
  • @yms I am looking through meta, is there anything specific about not asking so called "pool" questions? I can't find anything specifically about avoiding doing this :/. – Derrick H Jan 23 '12 at 18:45
  • 1
    I think he meant poor question, and this is an example of muphry's law: http://en.wikipedia.org/wiki/Muphry's_law – Chris Shain Jan 23 '12 at 18:46
  • @ChrisShain ah, that makes much more sense heh. – Derrick H Jan 23 '12 at 18:52
  • 1
    Use MVVM and i would suggest you to look around before you ask a question like that. :) – BigL Jan 23 '12 at 19:40
  • Eternal September strikes again. – Nate Noonen Jan 23 '12 at 21:13
  • Lately I've been reading about Prism http://msdn.microsoft.com/en-us/library/gg430865(PandP.40).aspx I still don't know much, but it looks like a really good architecture. I think you should consider it too. – Carlo Jan 24 '12 at 01:42

1 Answers1

2

Generally speaking, the Single Responsibility Principle (SRP) is an excellent practice to follow. The general idea here is that each class that you write has a single reason to change.

In your case, you're talking about a series of classes with at least two responsibilities: presenting information to the user and querying the database. Now, let's say that something about querying the database needs to change as you maintain your application. You open up your Window partial and change code, introducing the possibility of a regression in that class.

Now, you have an unfortunate situation where changing your database access logic might break your GUI. Conceptually, that makes no sense, and it makes your application brittle. If you had broken your responsibilities into separate classes, you wouldn't have this worry.

Separate your classes. You won't regret it over the long haul. :)

Erik Dietrich
  • 6,080
  • 6
  • 26
  • 37