Click here to Skip to main content
15,886,689 members
Articles / Desktop Programming / WPF

MVVM for Multi Platforms

Rate me:
Please Sign up or sign in to vote.
4.13/5 (6 votes)
22 Mar 2010CPOL2 min read 26.4K   354   22  
How to implement MVVM when developing a view model whose view implementation language is not certain
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GeographicRepresentation.Interfaces;
using GeographicRepresentation.Lib.ViewModel;
using GeographicRepresentation.Lib.Model;

namespace GeographicRepresentation.Lib
{
    /// <summary>
    /// This class is used as a connector between the View and the view model. It offers creation of interfaces 
    /// For a specific data
    /// </summary>
    public class InterfacesFactory
    {
        #region Singleton

        static InterfacesFactory m_Instance = null;

        public static InterfacesFactory Instance
        {
            get
            {
                if (m_Instance == null)
                {
                    m_Instance = new InterfacesFactory();
                }
                return m_Instance;
            }
        }

        private InterfacesFactory()
        {
        }    

        #endregion

        public IEditableCityViewModel GetEditableCityViewModelForAdd(Guid countryId)
        {
            return new EditableCityViewModel(new City(),countryId);
        }

        public IEditableCityViewModel GetEditableCityViewModelForEdit(Guid cityId)
        {
            City city = DataManager.Instance.GetCity(cityId);
            return new EditableCityViewModel(city);
        }

        public IEditableCountryViewModel GetEditableCountryViewModelForAdd(Guid continentId)
        {
            return new EditableCountryViewModel(new Country(), continentId);
        }

        public IEditableCountryViewModel GetEditableCountryViewModelForEdit(Guid countryId)
        {
            Country country = DataManager.Instance.GetCountry(countryId);
            return new EditableCountryViewModel(country);
        }

        public IEditableContinentViewModel GetEditableContinentViewModelForAdd()
        {
            return new EditableContinentViewModel(new Continent(), false);
        }

        public IEditableContinentViewModel GetEditableContinentViewModelForEdit(Guid continentId)
        {
            Continent continent = DataManager.Instance.GetContinent(continentId);
            return new EditableContinentViewModel(continent, true);
        }

        public IContinentsListViewModel GetContinentsListViewModel()
        {
            return new ContinentsListViewModel();
        }            
    }

    /// <summary>
    /// The following class is used for setting the timeout interval for asynchronos operations in miliseconds
    /// </summary>
    public class WaitTimeManager
    {
        public static int Interval
        {
            get
            {
                return 5000;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Israel Israel
Software Developer in a promising Clean-Tech company

Comments and Discussions