I have a service that uses repositories from multiple Git version control platforms as Gitlab, GitHub.. etc
I am using Jgit library in Java so I created a GitService which have the basic git commands
public class GITService {
public void cloneRepo(){}
public void push(){}
}
All platforms used this class, all worked good until pull request feature is added to my Github requests.
So I created a class to each platform, they all extend the GitService class
public class GitHubService extends GITService {
public void createPullRequest()
}
public class GitLabService extends GITService {
}
And I created a Factory to choose which class to be used based on the requests coming.
public class GitServiceFactory(){
public GitService getService(){}
}
There are two problems here in this design:
- I have a child which is Gitlab that doesn't have the feature of pullRequest. So I cannot put this method in the parent class because it could be uncommon for other platforms to have pull requests.
- My Factory returns GitService object, and thus I cannot use the method in child class. I saw that downcasting the object is a sign of bad design.
Any help would be appreciated to solve this. thanks.