Search code examples
wpfdesign-patternsmodel-view-controllermvvmmvp

can I use MVP with MVVM


I got a source-code and was trying to understand it using the documentation.

In the documentation, it says that the code has used both MVP and MVVM in combination to make the project.

can someone answer these following questions of mine:-

  1. What is point of using two design pattern in a single project(both MVP and MVVM) ?
  2. How can I simple know by looking at some source code if it is made using mvp,MVC or any other design pattern?
  3. can you tell me about ....what are layers in any design pattern? how many minimum layers are we gonna use to make a project in any design pattern? and what is the benefit of having as many layers as possible?
  4. what is the difference between java logic and android logic? coz we're simply separating apart java from android logic for the better testing environment by using any design pattern. Give example.

Solution

  • If the code is using MVC you will see the following:

    1. Models: Models contain data information. Does not call or use Controller and View. Contains the business logic and ways to represent data. Some of this data, in some form, may be displayed in the view. It can also contain logic to retrieve the data from some source.

    2. Controller: Acts as the connection between view and model. View calls Controller and Controller calls the model. It basically informs the model and/or the view to change as appropriate.

    3. View: Deals with UI part. Interacts with the user.

    For MVVM (Model View View Model):

    ViewModel:

    1. It is the representation of the state of the view.
    2. It holds the data that’s displayed in the view.
    3. Responds to view events, aka presentation logic.
    4. Calls other functionalities for business logic processing.
    5. Never directly asks the view to display anything.

    Now let's see MVP (Model View Presenter):

    Similar to traditional MVC but Controller is replaced by Presenter. But the Presenter, unlike Controller is responsible for changing the view as well. The view usually does not call the presenter.

    Now your questions:

    What is point of using two design pattern in a single project(both MVP and MVVM)?
    Ans: It may be the need. Also they both are very closely related and as I said it might be useful to mix the two to solve a particular type of problem.

    How can I simple know by looking at some source code if it is made using mvp,MVC or any other design pattern?

    Ans: Read the explanation I provided. Try to see which pattern closely matches the code. There might be multiple design patterns used.

    can you tell me about ....what are layers in any design pattern? how many minimum layers are we gonna use to make a project in any design pattern? and what is the benefit of having as many layers as possible?
    Ans: There are no such hard and fast rule on number of layers. To make your code reusable, maintainable, open for extension and follow the best practices of software engineering it is important that you follow the design patterns.

    what is the difference between java logic and android logic? coz we're simply separating apart java from android logic for the better testing environment by using any design pattern. Give example.

    Ans: There is no such thing called Java logic and Android logic.