[Tutor] Help on Software Design decisions

Juan C. juan0christian at gmail.com
Mon Nov 28 21:02:58 EST 2016


On Mon, Nov 28, 2016 at 11:33 PM, Alan Gauld via Tutor <tutor at python.org>
wrote:
>
> On 28/11/16 21:53, Juan C. wrote:
> > I'm a student and my university uses Moodle as their learning management
> > system (LMS).
>
> Never heard of it but hopefully that doesn't matter :-)
>
> > 1. Bachelor's Degree in Computer Science (duration: 8 semesters)
> >
> > 1.1. Unit 01: Mathematics Fundamental (duration: 1 semester)
> > 1.1.1. Algebra I (first 3 months)
> > 1.2. Unit 02: Programming (duration: 1 semester)
> > 1.2.1. Programming Logic (first 3 months)
> >
> > Each course/project have a bunch of assignments + one final assignment.
> > This goes on, totalizing 8 (eight) units, which will make up for a
4-year
> > program.
>
> > I have to build my own Moodle API to be consumed by my program,
>
> Do you have any requirements defined?
> APIs exist to do something, what operations does your API enable?
> Until you know that you can't design anything very useful.

Well, basically get program information like title, id and units, within
units get title, id and courses, within courses get title, id, assignments,
and within assignments get title, id, due date and grade. I'm working on a
program to automate the process of getting assignments data and putting
them on Trello and keep them up-to-date. (I'm using a Trello API from PyPi,
but that doesn't matter for my script)

>
> > - I was thinking about having the following classes: Program, Unit,
Course,
> > Assignment, User.
> > - User would handle auth + session, the rest is pretty straightforward,
> > program would handle programs, unit would handles units, and so on.
>
> OK, Have you heard of CRC cards? These might be helpful here in
> helping you understand and express what each of these classes does.
> "pretty straightforward" is not helpful in designing a program, you
> need to give more thought to what the program actually does.
> And that means what each class is responsible for.

No, never heard about it...

>
> > - Inside Program init there would be attributes title, id and units;
inside
> > Unit init there would be attributes title, id and courses; inside Course
> > init there would be attributes title, id, due_date, submitted, grade.
>
> The attributes are there to support the operations. What are the
> operations (ie the responsibilities) of the classes. That will
> tell you what attributes you need to store, which to derive
> and which are references to other (user defined) objects.
> And which turn out not to be needed at all...

Those classes won't have any methods right now, just atributes (title, id,
due date, etc), their job is mainly hold data from Moodle in a convenient
way, so I can use it whenever I like.

>
> > Should I call the site using requests and do all the parsing for
everything
> > using bs4 as soon as I create a new instance of User? For example:
>
> My personal opinion here is that objects should be
> constructed into discrete attributes as quickly as possible so
> I'd vote yes. Get the parsing done early. You can always define
> a method to reconstruct the string if that proves necessary.
>
> BTW you are talking about calling the site but your API (as I understand
> the assignment) is on the server side so have you
> thought about how those requests will be received and
> dispatched? Do you need more classes to deal with that?
> Or is that something Moodle can do for you?
>
> > user = User('john.smith', 'password')  # will get all data needed
> > user.program  # <Program 'Computer Science' (10260)>
>
> I'm not sure what you are trying to show us here.
> The first line is a valid assignment statement but you are passing
> in valid data, no parsing required. The second line does nothing
> useful.

Well, I'm trying to illustrate how the program would work. The parse would
occur inside User, there I would call the site using requests and scrap
data from it using bs4. I would get the username and password provided and
use requests + bs4 inside User to login and keep session. The second line,
and all of them for that matter, are just illustration. I already have a
working version of the script, I'm just fixing some bugs and I will post it
here.

>
> > Is this a good Pythonic design? If not, how could it be better?
>
> Mainly you are asking about general OOP/OOD rather than
> anything Pythonic. That is not a bad thing, just a different
> question.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list