Skip to main content


ArchitecturalDecouplingAbout 2 min

Also known as



To apply "Separation of Concernsopen in new window" to separate the logic from the UI components and allow developers to work on UI without affecting the logic and vice versa.


Wikipedia says

Model–view–viewmodel (MVVM) is a software architectural pattern that facilitates the separation of the development of the graphical user interface (the view) – be it via a markup language or GUI code – from the development of the business logic or back-end logic (the model) so that the view is not dependent on any specific model platform.

Programmatic Example

Zkoss implementation:

ViewModel will hold the business logic and expose the data from model to View

public class BookViewModel {
  private List<Book> bookList;
  private Book selectedBook;
  private BookService bookService = new BookServiceImpl();
  public Book getSelectedBook() {
    return selectedBook;

  public void setSelectedBook(Book selectedBook) {
    this.selectedBook = selectedBook;

  public List<Book> getBookList() {
    return bookService.load();
  /** Deleting a book.
  public void deleteBook() {
    if (selectedBook != null) {
      selectedBook = null;

View will have no logic, only UI elements

<window title="List of Books" border="normal" width="600px" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('com.iluwatar.model.view.viewmodel.BookViewModel')">
    <vbox hflex="true">
        <listbox model="@bind(vm.bookList)" selectedItem="@bind(vm.selectedBook)" height="400px" mold="paging">
                <listheader label="Book Name"/>
                <listheader label="Author"/>               
            <template name="model" var="book">
                <listitem >
                    <listcell label="@bind("/>
                    <listcell label="@bind("/>
        <button label="Delete" onClick="@command('deleteBook')" disabled="@load(empty vm.selectedBook)" />
    <hbox style="margin-top:20px" visible="@bind(not empty vm.selectedBook)">
				Book Name : <label value="@bind(" style="font-weight:bold"/>
				Book Author : <label value="@bind(" style="font-weight:bold"/>
				Book Description : <label value="@bind(vm.selectedBook.description)" style="font-weight:bold"/>

To deploy the example, go to model-view-viewmodel folder and run:

Class diagram

alt text
MVVM pattern class diagram


  • When looking for clean architecture, with better reusability, testability and maintainability.


Typical Use Case

  • Android apps
  • .NET framework applications
  • JavaScript applications

Real world examples


  • John Gossman has criticized the MVVM pattern and its application in specific uses, stating that MVVM can be "overkill" when creating simple user interfaces. For larger applications, he believes that generalizing the viewmodel upfront can be difficult, and that large-scale data binding can lead to lower performance - Ref: MVVM-Wikiopen in new window

  • Can be hard to design ViewModel for larger applications.

  • For complex databinding, debugging can be difficult.