Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseJob: Use saved parameters instead of overriding apiPath(), query() and data() in each job class #43

Merged
merged 2 commits into from
Oct 16, 2016

Conversation

KitsuneRal
Copy link
Member

This is a rather wide-reaching change; it doesn't affect clients, and is rather easy to understand though. The rationale for it is that virtual functions normally should describe polymorphism in behaviour, not in data. Given that the passed parameters end up in a type-agnostic QNetworkRequest, there's not much use in have those chunks of data separately. So what I've done is simply saving the already type-erased components of QNetworkRequest right at the moment of BaseJob construction. This saves numerous descendants of BaseJob from having to override apiPath(), query() and/or data(), instead taking them to do all necessary conversions in their constructors. The simpler cases (LogoutJob for instance) become very trivial then; and the more complicated cases (see SyncJob) still have all request building complexity in a single method (the constructor, that is). And we're saving in runtime on virtual invocations, too.

Copy link
Contributor

@Fxrh Fxrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for that small issue, it looks good! I'm actually not quite sure why I moved these parts to abstract functions...

@@ -99,20 +99,14 @@ namespace QMatrixClient
class SyncJob: public BaseJob
{
public:
SyncJob(ConnectionData* connection, QString since=QString());
SyncJob(ConnectionData* connection, QString filter, int timeout,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have "since" before filter and timeout, as I think it is a more commonly used parameter. Also, I'd give filter and timeout a default value ({} and -1).

@KitsuneRal KitsuneRal merged commit b44ad35 into master Oct 16, 2016
@KitsuneRal KitsuneRal deleted the kitsune-request-params branch October 16, 2016 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants