Click here to Skip to main content
15,896,726 members
Articles / Desktop Programming / WPF

Modeling M-V-VM

Rate me:
Please Sign up or sign in to vote.
3.71/5 (8 votes)
5 Jun 2009CPOL2 min read 26.9K   312   23  
An article which tries to present an approach for decoupling M-V-VM View Model objects
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using WorldDataLib.Model;

namespace WorldServiceLib
{
    public class StabWorldDataManager
    {
        #region Members

        Dictionary<string, Continent> m_Continents;
        Dictionary<string, Country> m_Countries;
        Dictionary<string, City> m_Cities;

        #endregion

        #region Properties

        #endregion

        #region Methods

        #region Ctor

        public StabWorldDataManager()
        {
            m_Continents = new Dictionary<string, Continent>();
            m_Countries = new Dictionary<string, Country>();
            m_Cities = new Dictionary<string, City>();

            Continent continent = new Continent();
            continent.Name = "North America";
            continent.SizeInSquareMiles = 9449460;
            m_Continents.Add(continent.Name, continent);
            continent = new Continent();
            continent.Name = "Europe";
            continent.SizeInSquareMiles = 3837000;
            m_Continents.Add(continent.Name, continent);
            continent = new Continent();
            continent.Name = "Asia";
            continent.SizeInSquareMiles = 17212000;
            m_Continents.Add(continent.Name, continent);

            Country country = new Country();
            country.Name = "United States";
            country.Currency = CurrenciesEnum.Dollar;
            m_Countries.Add(country.Name, country);

            country = new Country();
            country.Name = "United Kingdom";
            country.Currency = CurrenciesEnum.Sterling;
            m_Countries.Add(country.Name, country);

            country = new Country();
            country.Name = "France";
            country.Currency = CurrenciesEnum.Euro;
            m_Countries.Add(country.Name, country);

            country = new Country();
            country.Name = "Japan";
            country.Currency = CurrenciesEnum.Yen;
            m_Countries.Add(country.Name, country);

            City city = new City();
            city.Name = "New York";
            city.CurrentTemprature = 100;
            m_Cities.Add(city.Name, city);

            city = new City();
            city.Name = "Chicago";
            city.CurrentTemprature = 85;
            m_Cities.Add(city.Name, city);

            city = new City();
            city.Name = "London";
            city.CurrentTemprature = 70;
            m_Cities.Add(city.Name, city);

            city = new City();
            city.Name = "Paris";
            city.CurrentTemprature = 80;
            m_Cities.Add(city.Name, city);

            city = new City();
            city.Name = "Tokyo";
            city.CurrentTemprature = 95;
            m_Cities.Add(city.Name, city);
        }

        #endregion

        public double GetContinentSizeInSquareMiles(string strContinent)
        {
            double result = -1;
            Continent continent;
            if (m_Continents.TryGetValue(strContinent, out continent))
            {
                result = continent.SizeInSquareMiles;
            }

            return result;
        }

        public CurrenciesEnum GetCountryCurrency(string strCountry)
        {
            CurrenciesEnum currency = CurrenciesEnum.Dollar;
            Country county;
            if (m_Countries.TryGetValue(strCountry, out county))
            {
                currency = county.Currency;
            }

            return currency;
        }

        public double GetCityCurrentTemprature(string strCity)
        {
            double result = -1;
            City city;
            if (m_Cities.TryGetValue(strCity, out city))
            {
                result = city.CurrentTemprature;
            }

            return result;
        }

        #endregion
    }
}

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