Hot answers tagged

80

If your class has 20 parameters in the constructor, it doesn't sound like your team quite knows what SRP is. If you have a class that does only one thing, how does it have 20 dependencies? That's like going on a fishing trip and bringing along a fishing pole, tackle box, quilting supplies, bowling ball, nunchucks, flame thrower, etc.... If you need all that ...


31

I think it's in Martin Fowler's Refactoring that I once read a counter-rule to SRP, defining where it's going too far. There is a second question, as important as "does every class have only one reason to change?" and that is "does every change only affect one class?" If the answer to the first question is, in every case, "yes" but the second question is "...


22

Just because a system is complex doesn't mean that you have to make it complicated. If you have a class that has too many dependencies (or Collaborators) like this: public class MyAwesomeClass { public class MyAwesomeClass(IDependency1 _d1, IDependency2 _d2, ... , IDependency20 _d20) { // Assign it all } } ...then it got way too complicated ...


21

If the data never changes and is read only, then just put it in a code file as a list of constants. public readonly string AppStartUpData = "MyAppNeedsThis"; If this data is different per deployment, then an external file is fine. .Net comes with built in .config files (App.Config). One should use those as there are standard ways (built in to the ...


20

Several reasons why this is probably not the end of .NET: If you look at the video, all they actually say is that Windows 8 will support some kind of desktop widget-style application type that can be developed in HTML5. Essentially, Microsoft is turning the Windows desktop into a web browser. So this has, at far as we know now, no bearing on anything else ...


19

MVVM is intended to be used where complex user interactions using high-fidelity UI's are needed (i.e. WPF). MVVM is targeted at modern UI development platforms (Windows Presentation Foundation, or WPF, and Silverlight) in which there is a user experience (UXi) developer who has requirements different from those of a more “traditional” developer (e.g. ...


17

Routed events According to MSDN, A routed event is a type of event that can invoke handlers on multiple listeners in an element tree, rather than just on the object that raised the event. The definition is followed by an example of a WPF node with three buttons. The single routed event is listening for three buttons. If you try to write the same code ...


15

Sometimes MVVM can be a trap. From my experience it favors CRUD-like applications (forms over data) versus more task-oriented UIs. I'm not saying that it implies bad architecture for the back end/others layers in the application but I have seen a lot MVVM applications coming with "DDD light" architecture. I don't know why exactly maybe because the binding is ...


15

Consider WPF. If you are unfamiliar with WPF, I recommend Windows Presentation Foundation Unleashed. WPF allows for content in web browsers or standard windows applications. WPF also is resolution independent - the content on a mobile device has the same crisp look as the content on a 50 inch tv. Windows Forms is limited when it comes to a highly ...


15

You know when you are violating MVVM when: The ViewModel is aware of the View. The ViewModel should never know or care if or what is sitting on top of it. It simply is. Sometimes, the ViewModel might need to generate events that should be handled on the View. When I was working with MVVM, we used the Mediator pattern to handle those cases. The Model is ...


15

I have tried CaliburnMicro and MVVMLight and when using Caliburn I really feel what you feel, sure it feel really magical able to bind control to property just by using Name="PropertyName" instead of old Text="{Bind PropertyName}" but in the end Caliburn goes way overboard to do this magical thing, when something goes wrong it really hard to debug, to make ...


15

You can always add a file into your project and set its build type to Embedded Resource so that it is embedded directly into the application itself. Alternatively a file that is encrypted and placed in an accessible location.


14

A binary file would be the obvious answer, but it depends on how you are loading it - you might as well make life easy for yourself if you can. XML might be a good choice as there are built in methods in C# for reading this. You could add a checksum to your data, so that if the user alters it, the checksum will no longer match (you need to add a check to ...


13

MVVM is a band-aid for poorly designed data binding layers. In particular, it has seen a lot of use in the WPF/silverlight/WP7 world because of limitations in data binding in WPF/XAML. From now on, I'm going to assume we're talking about WPF/XAML since this will make things more clear. Lets look at some of the shortcomings that MVVM sets out to solve in WPF/...


13

If you will be doing lots of IO, SQL is your better choice. SQL is designed to work well to get/store data which is why we use it for storing data on something like a website as opposed to XML. XML is good for human readable data that can be shared and interpreted between applications, as was its intention. XML parsing involves LOTS of string manipulation ...


12

It looks like you've found yourself in perfect learning situation. Currently your application works, and I'm sure you're very familiar with all of the 20k lines of code. Making changes isn't that difficult, and, so far, there doesn't seem to be any reason to change your development approach. You are a cowboy! And being a cowboy is a lot of fun! But ...


11

To answer the question, Yes, each view should have its own View Model. But there is no need to model the entire hierarchy. Only what the view needs. The problem I had with most online resources regarding MVVM: In most examples, the View is almost 1-to-1 mapping of the Model. But in my scenario, where there are different views for different facets of the ...


10

Is there any easy step-by-step reference to MVVM? Yes, there is. Take a look at the here. Is MVVM a super-set or a sub-set of MVC? MVVM belongs to the MVC family, so, if you can say that at all, it's a subset. It's a variant to decouple the UI from the business logic underneath. I'd describe it as a sibling of MVC. Since the early days of OOP people ...


10

I'll go the other direction on this one: if your team has linux experience and familiarity, and you run your own servers, outsourcing to a .NET shop will be a disaster. You won't have the experience to rein in the outsourcers when they get crazy, your linux and PHP intuitions will fail you in the Windows environment, you won't easily spot goofy .NET ...


10

I have used ValueConverters in some cases and put the logic in the ViewModel in others. My feeling is that a ValueConverter becomes part of the View layer, so if the logic is really part of the View then put it there, otherwise put it in the ViewModel. Personally I don't see a problem with a ViewModel dealing with View-specific concepts like Brushes ...


10

Both MFC and WPF (along with Windows Forms, VB6 forms, and plenty of other things) contain concepts that come from the Windows UI - the basic set of controls (button, text box, checkbox etc), the idea of properties for those controls (text, contents, checked...) and that some properties are common to all controls while others are just for certain controls. ...


10

Break the problem into two parts. Learn the basics of F# by excluding the use of WPF. Learn how to write functions without using mutables and while statements and using function composition. Once you have this done learn how to make use of mutables to update state. Learn how to use WPF in F# by reading Learning WPF through F#, and vice versa, by John Liao....


10

First off, take a look at the basics of MVVM to get a better understanding of how the pattern is supposed to work. This WPF specific version may be of interest as well. Generally speaking, the pattern looks like this: View <= (bound) => ViewModel <= (function calls + async callbacks) => Model With that diagram in mind, it should be a little more ...


10

It is important to realize what MVVM is. It is not some shared bit of functionality that you do not have to reimplement (parsing a JPEG file or connecting to a given SQL database server), it is a pattern--a pattern for how one may choose to implement a rich GUI. So, if your implementation of the pattern is simple and straightforward, I do not think you need ...


10

Use one DbContext object per data access or transaction. DbContext is a lightweight object; it is designed to be used once per business transaction. Making your DbContext a Singleton and reusing it throughout the application can cause other problems, like concurrency and memory leak issues. DbContext essentially implements a Unit of Work. Treat it ...


9

One way to avoid refreshing too often would be to use a dirty_flag + a Timer; you set the Timer interval to something like 200ms or whatever value you consider optimal. When en event that requires a refresh happens, you just set the dirty_flag to true, and reinitialize the Timer(that way you make sure that Timer.Tick will be raised at "x" milliseconds after ...


9

There are different tools and different patterns. Tools ADO.NET ADO.NET is much more than DataSet and DataTable. I would not use those classes in any project but instead use the IDataReader to populate pocos as I describe here: http://blog.gauffin.org/2013/01/ado-net-the-right-way/ Data mappers The next step is to use a data mapper. What they do is to ...


9

My perspective is from years of experience working with Winforms, the "old fashioned way," with events and code-behind. So I can tell you with absolute certainty that, once you get beyond the simplest of applications, your code quickly becomes a big ball of mud. It was inevitable, because that's the way applications were written back then. Webforms is just ...


8

I really like MVVM and I find its challenges motivating and see the many benefits, but... For application or games that require a lot of UI/interaction code to add a lot of custom behaviors while keeping perf up - it is often better to use a bit dirty MVVM - use it when it is useful or in more data centric as opposed to interaction centric areas of the code....


8

I've been a WPF/Silverlight programmer for years building huge applications, such as trading systems, on MVVM. For me, as the years have gone by, I've learned that strict MVVM eats time and costs money. By strict, I mean rules such as "no code behind". It's impossible in anything but the most basic form/database app, not to have code-behind. Your designer ...


Only top voted, non community-wiki answers of a minimum length are eligible