Click here to Skip to main content
11,574,473 members (66,523 online)
Click here to Skip to main content
Add your own
alternative version

Modeling M-V-VM

, 5 Jun 2009 CPOL 16.6K 284 23
An article which tries to present an approach for decoupling M-V-VM View Model objects
TestTreeViewWithLeftBarView.zip
TestTreeViewWithLeftBarView
bin
Debug
TestTreeViewWithLeftBarView.exe
TestTreeViewWithLeftBarView.vshost.exe
TestTreeViewWithLeftBarView.vshost.exe.manifest
WorldDataLib.dll
Properties
Settings.settings
Resources
Service References
WorldServiceReference
configuration.svcinfo
configuration91.svcinfo
Reference.svcmap
service.wsdl
View
ViewModel
WorldDataLib
bin
Debug
WorldDataLib.dll
Model
Properties
WorldServiceApp
bin
Debug
WorldDataLib.dll
WorldServiceApp.exe
WorldServiceApp.vshost.exe
WorldServiceApp.vshost.exe.manifest
WorldServiceLib.dll
Properties
WorldServiceLib
bin
Debug
WorldDataLib.dll
WorldServiceLib.dll
Properties
WorldServiceLib.csproj.user
Modeled_ViewModel.suo
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)

Share

About the Author

Izhar Lotem
Software Developer
Israel Israel
Software Developer in a promising Clean-Tech company

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 5 Jun 2009
Article Copyright 2009 by Izhar Lotem
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid