MVVM Interview Questions & Answers

MVVM Interview Questions

Are you looking for a bright career in IT sector and to stand up as a software professional? Have an eye into wisdomjobs portal that creating a new era in showering jobs. MVVM jobs roles were to design and code reviews experience in code reusability, modularity, extensibility, and testability. Job givers look forward to talented persons who have the ability to work with minimal supervision in open communication across the team. Job seekers must have efficiency in computer applications and be alert to give their best which job givers expect from you. Explore the details of MVVM jobs interview questions and answers page and become stronger to attend the interview with confidence. Log on to www.wisdomjobs.com to get offers and notified jobs from various reputed companies.

MVVM Interview Questions And Answers

MVVM Interview Questions
    1. Question 1. What Is Mvvm?

      Answer :

      The Model, View, ViewModel (MVVM pattern) is all about guiding you in how to organize and structure your code to write maintainable, testable and extensible applications.

    2. Question 2. What Are The Logical Layers Of Mvvm?

      Answer :

      • Model − It simply holds the data and has nothing to do with any of the business logic.
      • ViewModel − It acts as the link/connection between the Model and ViewModel, and makes stuff look pretty.
      • View − It simply holds the formatted date and essentially delegates everything to the Model.

    3. Question 3. What Are The Benefits Of Mvvm?

      Answer :

      The key benefit is allowing true separation between the View and Model beyond achieving separation and the efficiency that you gain from having that. What it means in real terms is that when your model needs to change, it can be changed easily without the view needing to and vice-versa.

       There are three key things that flow out of applying MVVM:

      1. Maintainability.
      2. Testability.
      3. Extensibility.

    4. Question 4. What Are The Disadvantages Of Mvvm?

      Answer :

      • Some people think that for simple UI, MVVM can be an overkill.
      • Similarly in bigger cases, it can be hard to design the ViewModel.
      • Debugging would be a bit difficult when we have complex data bindings.

    5. Question 5. What Are The Responsibilities Of Model?

      Answer :

      In general, model is the simplest one to understand. It is the client side data model that supports the views in the application.

      • It is composed of objects with properties and some variables to contain data in memory.
      • Some of those properties may have reference to other model objects and create the object graph which as a whole is the model objects.
      • Model objects should raise property change notifications 

    6. Question 6. Which In Wpf Means Data Binding?

      Answer :

      The last responsibility is validation which is optional, but you can embed the validation information on the model objects by using the WPF data binding validation features via interfaces like INotifyDataErrorInfo/IDataErrorInfo.

    7. Question 7. What Are The Responsibilities Of View?

      Answer :

      The main purpose and responsibilities of views is to define the structure of what the user sees on the screen. The structure contains static and dynamic parts.

      • Static parts are the XAML hierarchy that defines the controls and layout of controls that a view is composed of.
      • Dynamic part is like animations or state changes that are defined as part of the View.
      • The primary goal of MVVM is that there should be no code behind in the view.
      • In view you at least need the constructor and a call to initialize component.
      • The event handling, action and data manipulation logic code shouldn’t be in the code behind in View.
      • There are also other kinds of code that have to go in the code behind any code that's required to have a reference to UI element. It is inherently view code.

    8. Question 8. What Are The Responsibilities Of Viewmodel?

      Answer :

      ViewModel is the main point of MVVM application. The primary responsibility of ViewModel is to provide data to the view, so that view can put that data on the screen.

      • It also allows the user to interact with data and change the data.
      • The other key responsibility of ViewModel is to encapsulate the interaction logic for a view, but that does not mean all of the logic of the application should go into ViewModel.
      • It should be able to handle the appropriate sequencing of calls to make the right thing happen based on user or any changes on the view.
      • ViewModel should also manage any navigation logic like deciding when it is time to navigate to a different view.

    9. Question 9. How Many Ways Are Used To Construct Views?

      Answer :

      There are two ways to construct views. You can use any one of them.

      1. View First Construction in XAML
      2. View First Construction in Code-behind

    10. Question 10. What Is View First Construction In Xaml?

      Answer :

      One way is to simply add your ViewModel as a nested element in the setter for the DataContext property as shown in the following code.

      <UserControl.DataContext> 
         <viewModel:StudentViewModel/> 
      </UserControl.DataContext>

    11. Question 11. What Is The View First Construction In Code-behind?

      Answer :

      Another way is that you can do view first construction by simply constructing the view model yourself in the code behind of your View by setting the DataContext property there with the instance.

      Typically, the DataContext property is set in the constructor method of view, but you could also defer the construction until the Load event of the view fires.

      using System.Windows.Controls;
      namespace MVVMDemo.Views { 
         /// <summary> 
            /// Interaction logic for StudentView.xaml 
         /// </summary> 
         public partial class StudentView : UserControl { 
            public StudentView() { 
               InitializeComponent(); 
               this.DataContext = new MVVMDemo.ViewModel.StudentViewModel(); 
            } 
         } 
      }

    12. Question 12. What Is The Main Reason Of Constructing Viewmodel In Code-behind?

      Answer :

      The main reason of constructing ViewModel in code-behind instead of XAML is that the view model constructor takes parameters, but XAML parsing can only construct elements if defined in default constructor.

    13. Question 13. What Is The Key Feature That Differentiates Mvvm From Other Ui Separation Patterns Like Mvc And Mvp?

      Answer :

      Data binding is the key feature that differentiates MVVM from other UI separation patterns like MVC and MVP.

    14. Question 14. In How Many Ways Can You Bind Data?

      Answer :

      Data bindings can either be OneWay or TwoWay to flow data back and forth between the View and ViewModel.

    15. Question 15. How Viewmodel First Construction Approach Leverages The Capabilities Of Implicit Data Templates In Wpf?

      Answer :

      Implicit data templates can automatically select an appropriate template from the current resource dictionary for an element that uses data binding. They do this based on the type of the data object which is rendered by data binding. First you need to have some element that is binding to a data object.

    16. Question 16. What Are The Responsibilities Of Invoker And Receiver In Command Pattern?

      Answer :

      There are two main actors, the invoker and the receiver in Command pattern.

      Invoker : Invoker is a piece of code which can execute some imperative logic. Typically, it is a UI element that the user interacts with in the context of a UI framework. But it could just be another chunk of logic code somewhere else in the application.

      Receiver : Receiver is the logic that is intended for execution when the invoker fires. In the context of MVVM, the receiver is typically a method in your ViewModel that needs to be called.

    17. Question 17. What Is Delegate Command?

      Answer :

      In between the invoker and the receiver you have an obstruction layer that does not allow the invoker and the receiver to explicitly know about each other. This is typically represented as an interface abstraction exposed to the invoker and a concrete implementation of that interface is capable of calling the receiver.

    18. Question 18. Does Each And Every Piece Of Child Content That You Separate Into Its Own Xaml File Necessarily Needs To Be An Mvvm View?

      Answer :

      No, if the chunk of content just provides the structure to render something to the screen and does not support any input or manipulation by the user for that content. It may not need a separate ViewModel, but it could just be a chunk XAML that renders based on properties exposed by the parents ViewModel.

    19. Question 19. What Is Validation In Mvvm?

      Answer :

      When your application starts accepting data input from end users you need to consider validating that input. To make sure it conforms to your overall requirements.

    20. Question 20. In How Many Ways Can You Express Validation?

      Answer :

      You can use the following ways of expressing validation that are supported by WPF data binding:

      • Throwing exceptions on a property is set.
      • Implementing the IDataErrorInfo interface.
      • Implementing INotifyDataErrorInfo.
      • Use WPF validation rules.

    21. Question 21. What Is Dependency Injection / Ioc Containers?

      Answer :

      Inversion of Control (IoC) and dependency injection are two design patterns that are closely related and the container is basically a chunk of infrastructure code that does both of these patterns for you. IoC pattern is about delegating responsibility for construction and the dependency injection pattern is about providing dependencies to an object that's already been constructed.

    22. Question 22. What Is An Event?

      Answer :

      An event is a programming construct that reacts to a change in state, notifying any endpoints that have registered for notification. Primarily, events are used to inform a user input via the mouse and keyboard, but their usefulness is not limited to that. Whenever a state change is detected, perhaps when an object has been loaded or initialized, an event can be fired to alert any interested third parties.

    23. Question 23. What Is Icommand?

      Answer :

      ICommand defines a command The ICommand type exposes the following members.

      • CanExecute :Defines the method that determines whether the command can execute in its current state.
      • Execute :Defines the method to be called when the command is invoked.
      • CanExecutehanged :Occurs when changes occur that affect whether or not the command should execute

    24. Question 24. What Are Advantages Of Mvvm Over Mvc?

      Answer :

      • Increases the “Blendability” of your views (ability to use Expression Blend to design views) – This enables a separation of responsibilities on teams that are lucky enough to have a designer and a programmer… each can work independent of the other.
      • “Lookless” view logic – Views are agnostic from the code that runs behind them, enabling the same view logic to be reused across multiple views or have a view easily retooled or replaced. Seperates concerns between “behavior” and “style”.
      • No duplicated code to update views – In code-behind you will see a lot of calls to update view controls. With MVVM you can be assured the view is updated appropriately just by setting the underlying property and all view side-effects thereof.
      • Testability – Since your logic is completely agnostic of your view, unit testing is made easy. You can test the behavior of a ViewModel without involving its view. This also enabled test-driven development of view behavior, which is almost impossible using code-behind.
      • Designer-Developer Workflow – MVVM facilitates a separation of UI and presentation logic concerns from the business layer that makes it easy to streamline the development process by allowing design cycles to happen in parallel with development.

    25. Question 25. What Is Inotifypropertychanged?

      Answer :

      The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed.For example, consider a Stock object with a property called StockCount.
      To provide generic property-change notification, the Stock type implements the INotifyPropertyChanged interface and raises a PropertyChanged event when StockCount is changed.For change notification to occur in a binding between a bound client and a data source, your bound type should either:

      • Implement the INotifyPropertyChanged interface (preferred).
      • Provide a change event for each property of the bound type.

    26. Question 26. Why We Need Mmvm?

      Answer :

      MVVM facilitates a clear separation of the development of the UI from the development of the business logic or back end logic known as the model (also known as the data model to distinguish it from the view model). The view model of MVVM is a value converter. MVVM was designed to make use of data binding functions in WPF to better facilitate the separation of view layer development from the rest of the pattern by removing virtually all GUI code (“code-behind”) from the view layer.

Popular Interview Questions

All Interview Questions

All Practice Tests

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MVVM Tutorial