[Tutor] Python OO

Juan C. juan0christian at gmail.com
Sat Mar 28 22:39:02 CET 2015


On Sat, Mar 28, 2015 at 5:23 PM Alan Gauld <alan.gauld at btinternet.com>
wrote:

> That looks like a data oriented class, which may not be a bad thing but
you should also be thinking about the methods. What will a series object
do in the context of your application? How will those data attributes help
the methods do their job?

My app doesn't do anything specific. It's just for the sake of doing
something. Maybe, I just create a serie instance and print all the info
about it like title, year of launch, numbers of seasons, go through each
season and post each episode info like title, air date, summary, things
like that.


> Also is date really an attribute of the series? Or is it a derived
feature based on the seasons? And maybe should be a range, or a
tuple of values?

The date thing is a little different in each case, Serie will have only the
year, let's say "Breaking Bad" would be 2008. Season would have year +
month. Episode would have full date, year + month + day.


> The "function" - do you mean method? - get_season() should probably
be a private method and maybe called by __init__()? (I'm assuming
this is the thing that talks to the MDB API?

Yes, I mean method. Yeah, forget about get_season(), I was thinking a
little "Java" there. The best thing to do would be having a self.seasons
just like every else (self.title, self.year and so on) list of 'Season'
instances and then I call it directly.


> Much as before. Is the year an attribute or derived from the
episodes? Can a series be shown more than once? Does it have
multiple dates in that case?

Year is an attribute of season. Not multiple dates, it will have the year +
month of the first episode of the season.

> This is the core data, most of the higher level stuff can be derived
from this. And it has two methods (not functions). Or are they also just
calls to the MDB DB? Or are they methods that your users will want to use?
Itsnot clear.

I don't want to create a bunch of "get" methods, I read in many places that
Python isn't Java, you don't need "getters/setters" you can pretty much
call the 'self.var' directly.

Again, I was thinking 'Java' there, I don't need a 'get_character' method,
I can have a list on my __init__ and call it directly, same goes for
crew_size, I just use len() on characters.


> I don't know the API so I can't answer that.

The API: http://docs.themoviedb.apiary.io/#reference/tv/tvid/get

It returns the data in JSON and I use requests 'json' method to read the
data.


> Do you have to? Why not fetch the seasons and episodes on demand?

Well, let's say I create a new instance, 'bb = Serie(1396)  # Breaking
Bad', won't I need to have my 'self.seasons' list ready, because I can call
it anytime? And the same logic applies to the 'Season' class, I need to
have the 'self.episodes' ready.

To call on demand I will need to change to code and indead create methods
like 'get_season' and 'get_episode'.

Maybe I'm a little confuse and can't really express my logic here.


More information about the Tutor mailing list