-2

I want to check my knowledge as I have seen a project in my company in different way.

What I know is, if we want to use MVC software design pattern in our project, we separate our project like this:

View part is our design UI, which means ui.xaml file in WPF, ui.designer.cs in WinForms, ui.xml in Android, ui.qml in QtQuick and ui.ui in XCode.

Controller part is the nearest source file connected to designer file with similar names. Which is ui.xaml.cs file in WPF, ui.cs in WinForms, ui.java in Android, ui.h/ui.cpp in QtQuick and ui.swift in XCode.

Model part is any other class that does the main operations. I usually add the suffix Manager (or something like that) to them to say what is its responsibility.

and for MVVM I also use an interface or abstract class that the View is inherited from for its View Model part and consider my former Controller as a part of View.

And one Project is enough for building the whole thing.

But a project in my company has many classes! a folder of separate libraries for designers with the name of UserControl, a folder of another separate libraries with the name of View, and another set of libraries with the name of ViewModel and so is the case for Controller and Model. And they say it is a mixture of MVC and MVVM. The most surprising point is, the whole software has 38 separate projects written by a single programmer and the team is a small one.

Please tell me whether my knowledge is correct? And please tell me if the project in my company is in a right direction?

Matin Lotfaliee
  • 1,745
  • 2
  • 21
  • 43
  • Why downvote? Please let me know to ask better questions. – Matin Lotfaliee Nov 16 '16 at 07:06
  • I'm just wandering, how are you going to determine the correct answer? – Tengiz Nov 18 '16 at 15:22
  • @Tengiz I am going to determine the correct answer based on the style I shared my own knowledge. – Matin Lotfaliee Nov 18 '16 at 16:05
  • Model should not manage anything, it should represent a business entity. `SomethingManager` is a really bad name, especially for a model, but even in general. See [Coding Horror](https://blog.codinghorror.com/i-shall-call-it-somethingmanager/) and [an old question on SO](http://stackoverflow.com/q/1866794/2157640). – Palec Nov 19 '16 at 14:09

2 Answers2

1

Is your knowledge about MVC and MVVM patterns correct? You had a mistake on Controller(ViewModel) and I think the same for Model.

Is your project in right direction? Doesnt seem right.

We use interfaces for all classes of Views and ViewModels (same for Controllers in MVC) just to have a better dependency management. its called IoC(inversion of Control) and the technique most of the times we use is called Dependency Injection, which makes a class, dependent to interface only (not concrete Impl.) using a Service Locator or some kind of service look-up object.

First of all, you can mix Controller with MVVM to handle the logic codes and let ViewModel handle binding and representation of Data Model for view, check out these series on Code project: http://www.codeproject.com/Articles/173618/MVVM-sharp-Episode-1

But I'm not a big fan of MVCVM unless you will use all of its benefits.

Controllers or ViewModels are separate classes from Views, which we put our logic codes in them. so "ui.xaml.cs" is not a Controller for example. that file is just another file for ui.xaml class. they both are same class which we call View. Remember we use presentation patterns to separate logic codes from View's Code Behind codes.

Model is an object of properties grouped together. we just try to not to mix Model class with any logic codes. Models can have Validation functions (.IsNameValid() for example) or some other functions to create another representation of object (.ToString() for example) but not any logic codes (like CRUDs for example). We dont put our main operations in Model. main operations are in Controllers(ViewModels) but the result could be a Model which we bind to some of View fields.

We click "Search User" button, SearchUser command runs a function in Controller and in the result sets a User model object to a property called FoundUser (which is in Controller), and View's TextBox shows FoundUser's Name.

Shahin
  • 302
  • 2
  • 10
0

In each application, when it comes to presentation layer, you can use multiple design patterns, MVC, MVP, MVVM or etc... But, It is best practice to follow one design pattern in Presentation Layer, cause it is consistent, and more maintainable.

Also I think you have some misunderstandings about Model and Controller definitions, that by solving, you can have better understanding of the patterns.

Babak Fakhriloo
  • 2,076
  • 4
  • 44
  • 80