Skip to content

Instantly share code, notes, and snippets.

@derwolfe
Created December 29, 2014 16:56
Show Gist options
  • Save derwolfe/173d067fdfa772254760 to your computer and use it in GitHub Desktop.
Save derwolfe/173d067fdfa772254760 to your computer and use it in GitHub Desktop.
# File: data_handlers.py
from models import MyDataObject
class MyDataHandler:
""" responsible for working on the data only."""
def __init__(self, data_object):
self.data_object = data_object
def mult_data_by_two(self):
return self.data_object.numeric_data * 2
#File: models.py
class MyDataObject:
"""responsible for manipulating, transforming data"""
def __init__(self):
self.numeric_data = 0
# this isn't really necessary in python, as one normally just sets/gets python attributes.
# but, let's say that set does some crazy translation of the data,
# then it makes more sense to split into its own method
def set_data(self, new_data):
self.numeric_data = new_data
Display the source blob
Display the rendered blob
Raw
#'ipynb' extension is for IPython Notebooks
from data_handlers import MyDataHandler
from models import MyDataObject
data = MyDataObject()
dh = MyDataHandler(data)
dh.set_data(1)
print dh.mult_data_by_two()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment