[Tutor] Help on Software Design decisions

Alan Gauld alan.gauld at yahoo.co.uk
Mon Nov 28 20:33:24 EST 2016


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.

> - 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.

> - 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...

> 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.

> 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




More information about the Tutor mailing list