Reputation: 1717
I'm designing an application using Selenium and their PageFactory.
Each of my page object classes inherits from a base class with the standard methods in, but I also have a few pages which require SlowLoadableComponent. As this is implemented as an abstract class I can't extend both that and my base page class.
Is there any downside to making my base page class extend SlowLoadableComponent? If so would you implement the base page class as an interface with default methods or something else?
Upvotes: 3
Views: 494
Reputation: 6202
If only you had multiple inheritance...
The workaround to multiple inheritance in Java is delegation.
So you could refactor your code to look like this:
public interface IBasePage {
//... unimplemented base page methods
}
public class BasePageImpl implements IBasePage {
public BasePageImpl(WebDriver webDriver) { //... }
//... implemented base page methods
}
public class FastPage implements IBasePage {
//... delegate all base page methods to the BasePageImpl
}
public class SlowPage extends SlowLoadableComponent implements IBasePage {
//... delegate all base page methods to the BasePageImpl
}
Upvotes: 1