2

In my latest WPF applications I've been using a Singleton class, that I call Model, to contain all my application's logic, such as file reading, information handling, etc..

In the WPF Views or Windows I just call the methods that I need, when I need them: Model.Instance.GetProducts(string category);

Besides having always the same instance, I find this convenient because I can call any method that I want in any window, and I can define the Model in App.xaml to be a StaticResource and then do the bindings that I need. For example, set the Binding of a DataGrid to an ObservableCollection present in the Model.

What do you think of this approach? A few years ago at college, when working with Windows Forms we used to work with the MVC pattern, where the controller would contain some events that called methods from the Model, and those events would later be invoked by the Views.

8
  • en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29 Commented Apr 29, 2015 at 8:57
  • What is your unit-testing strategy? Commented Apr 29, 2015 at 8:57
  • 1
    recommended reading: What is the problem with “Pros and Cons”? Commented Apr 29, 2015 at 9:19
  • @gnat any suggestion on how to improve my question? Commented Apr 29, 2015 at 9:59
  • @Den I'm trying to figure out one :/ Commented Apr 29, 2015 at 9:59

1 Answer 1

3

God object is one of the worst "designs" you can create. Please, put some effort into separating different concerns. Your future self will thank you.

3
  • I was expecting that answer. The hard part how to fix it. Commented Apr 29, 2015 at 8:58
  • @cap7 Refactor it. Slowly and carefully. Commented Apr 29, 2015 at 9:00
  • I've already started. For example, I've a class that only handles the database querying. Since that class has no state and is just a series of related methods that, when given an input, will give you an output, it's is defined as static and once the methods are finished I just forget them. I don't know if that is the best option. Commented Apr 29, 2015 at 9:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.