MVVM Interview Questions and Answers
Q1. What is MVVM?
Ans: The Model View ViewModel (MVVM) is an architectural sample used in software engineering that originated from Microsoft as a specialization of the presentation version layout pattern delivered through Martin Fowler.Largely based at the model–view–controller pattern (MVC), MVVM is focused at UI improvement structures which support event-driven programming, which includes HTML5,Windows Presentation Foundation (WPF), Silverlight and the ZK framework.
Q2. What are the advantages of MVVM?
Ans: The distinctive layers View,ViewModel and Model are loosely coupled.This offers application advanced the use of MVVM pattern following advantages:
Application is easer to maintain and make bigger
Application is less difficult to unit test
Q3. What are the factors of MVVM?
Ans: Model: as inside the traditional MVC sample, the model refers to either (a) a website model which represents the actual kingdom content material (an item-orientated approach), or (b) the statistics get admission to layer that represents that content (a data-centric approach).
View: as within the classic MVC pattern, the view refers to all elements displayed by using the GUI along with buttons, labels, and other controls
View model: the view version is a “version of the view” which means it is an abstraction of the view that still serves in mediating between the view and the model that's the goal of the view statistics bindings
Q4. What are famous MVVM frameworks?
Q5. What is a information binding?
Ans: Data binding is used to attach records supply with records goal.Data supply presents the statistics to the information target.Data source may be any CLR item.Data goal is normally WPF element including textbox or combobox.With WPF databinding records is automatically synchronized ,this means that the records adjustments in the source are mechanically reflected in the data goal.Similarly the facts adjustments in the facts target are pondered within the records supply.
Q6. What is PRISM?
Ans: PRISM is a hard and fast of hints for developing clean to maintain and flexible computer packages.Applications built using PRISM are simpler to trade.
Q7. What is Delegate Command?
Ans: Delegate Command implements ICommand and IActiveAware interface.So in preference to implementing the ICommand interface we are able to use the Delegate Command to simplify the
command advent in our application.
Q8. What are benefits of MVVM over MVC?
1. Increases the “Blendability” of your perspectives (potential to apply Expression Blend to design views) – This allows a separation of responsibilities on groups which are lucky sufficient to have a clothier and a programmer… each can work independent of the alternative.
2. “Lookless” view logic – Views are agnostic from the code that runs at the back of them, permitting the equal view logic to be reused across more than one perspectives or have a view without difficulty retooled or changed. Seperates concerns among “behavior” and “style”.
Three. No duplicated code to update views – In code-at the back of you may see a variety of calls to update view controls. With MVVM you can be confident the view is up to date appropriately simply by way of setting the underlying property and all view facet-results thereof.
4. Testability – Since your logic is absolutely agnostic of your view, unit trying out is made easy. You can test the behavior of a ViewModel without regarding its view. This also enabled test-driven improvement of view conduct, which is sort of impossible the usage of code-behind.
Five. Designer-Developer Workflow – MVVM helps a separation of UI and presentation common sense concerns from the business layer that makes it smooth to streamline the development technique with the aid of allowing design cycles to show up in parallel with improvement.
Q9. What is dependency assets?
Ans: Dependency belongings adds sure features inside the everyday CLR property machine.Class defining dependency belongings inherits from the DependencyObject class.WPF UI controls are usually inherited from DependencyObject.So UI controls supports dependency homes.
Q10. What is ICommand?
Ans: ICommand defines a command
The ICommand type exposes the following members.
CanExecute :Defines the technique that determines whether or not the command can execute in its current country.
Execute :Defines the approach to be called while the command is invoked.
CanExecutehanged :Occurs while modifications arise that affect whether or not or not the command have to execute.
Q11. What is the important thing feature that differentiates MVVM from different UI separation styles like MVC and MVP?
Ans: Data binding is the key function that differentiates MVVM from different UI separation patterns like MVC and MVP.
Q12. What is validation in MVVM?
Ans: When your application begins accepting records enter from cease users you want to take into account validating that input. To make certain it conforms for your standard necessities.
Q13. What is INotifyPropertyChanged?
Ans: The INotifyPropertyChanged interface is used to notify clients, usually binding customers, that a assets value has modified.
For instance, recall a Stock item with a property called StockCount. To provide regularly occurring assets-alternate notification, the Stock type implements the INotifyPropertyChanged interface and raises a PropertyChanged event when StockCount is modified.
For exchange notification to occur in a binding between a bound purchaser and a statistics supply, your sure type should either:
Implement the INotifyPropertyChanged interface (desired).
Provide a trade event for every property of the certain kind.
Q14. What are the obligations of View?
Ans: The principal reason and obligations of views is to outline the structure of what the person sees on the display. The structure carries static and dynamic elements.
Static components are the XAML hierarchy that defines the controls and format of controls that a view consists of.
Dynamic element is like animations or nation changes which are described as a part of the View.
The primary aim of MVVM is that there should be no code behind within the view.
In view you at the least want the constructor and a call to initialize factor.
The event dealing with, action and statistics manipulation logic code shouldn’t be in the code behind in View.
There also are different kinds of code that should pass within the code behind any code this is required to have a connection with UI element. It is inherently view code
Q15. What is the View First Construction in Code-in the back of?
Ans: Another way is that you could do view first production by means of truly constructing the view version yourself within the code in the back of of your View by way of placing the DataContext belongings there with the instance.
Typically, the DataContext assets is ready in the constructor approach of view, but you can also defer the development till the Load occasion of the view fires.
/// Interaction logic for StudentView.Xaml ///
public partial StudentView : UserControl
this.DataContext = new MVVMDemo.ViewModel.StudentViewModel();
Q16. What is Dependency Injection / IoC Containers?
Ans: Inversion of Control (IoC) and dependency injection are layout patterns which are intently related and the field is largely a chunk of infrastructure code that does both of those styles for you. IoC sample is ready delegating responsibility for production and the dependency injection sample is ready imparting dependencies to an object that's already been built.
Q17. What are the hazards of MVVM?
Some people think that for easy UI, MVVM may be an overkill.
Similarly in larger cases, it may be tough to design the ViewModel.
Debugging would be a bit tough while we've complicated facts bindings.