In a desktop application, I am developing a model for let's say, cities.
class City(object):
def __init__(self, name, population):
self._name = name
self._population = population
and I want to implement a edit method to change its private properties. The idea is to open a window with text entry fields so that the user can write new values. In order to make it testable and decoupled, I have done like this:
# Within City class
def edit(self, get_properties_function=None):
"""
Edit properties. Don't pass get_properties_function except for testing
"""
if get_properties_function is None:
get_properties_function = self._get_city_properties
new_name, new_population = get_new_properties()
self._name = new_name
self._population = new_population
def _get_city_properties(self):
# launch GUI and get the new values
return new_name, new_population
Now the questions:
- The dialog that asks for information, is a view, right? which leads me to the next question
- If I have a view, I think I should go further and consider implementing a controller. So, How to implement MVC here?
My idea is to have three classes (M-V-C) and each time that I instance my "city concept", I instance the Model but the View and the Controller as well. And the Controller becomes the public interface of a "City" This sounds like overkill, over-complicated.
I feel I have misunderstood the real MVC pattern because of web programming.