[Tutor] Object oriented design
Danny Yoo
dyoo at hashcollision.org
Mon Dec 21 21:27:45 EST 2015
>
> Thanks Danny. I was confused about what to return and How? Should I return
> user objects for User.find_by_lastname() method and do I need to
> re-instantiate objects?
>
If we pull a value out of an in-memory container, we've got it already in hand.
For example, here's a little interaction:
#####################################
>>> class Person(object):
... def __init__(self, name):
... self.name = name
...
>>> people = [Person('jamie'), Person('alan')]
#####################################
'people' is a list of two people. We can get at the first, or the
second, and they are 'People'.
#####################################
>>> firstPerson = people[0]
>>> secondPerson = people[1]
>>> firstPerson
<__main__.Person object at 0x7fdf6d9e1fd0>
>>> secondPerson
<__main__.Person object at 0x7fdf6d9f1050>
#####################################
That's a main point of an in-memory collection: we have ready,
immediate access to values that we've constructed.
If we do need to put those values "on ice", into longer-term storage,
then we do need to start considering the issues of translating those
in-memory values into sequential byte streams, also known as
"serialization". The purpose of quite a few software libraries is to
manage the complexity of going from sequential byte streams back into
in-memory data structures.
More information about the Tutor
mailing list