0

My problem is that I want to process a bigger HTML page from web, with Jsoup. Once I have the HTML file, I want to write the content to a file, so I don't have to make the internet connection every time (for developing and testing this static HTML is enough for me).

From that class, which contains this JSoup document I want to have a singleton instance.

My idea was to make a base class, Page and two derived class from that (PageFromFile, PageWithHttp). In that case, Page should not be instantiated, but it should contain one abstract method, the getInstance. This seems to be a contradiction.

Of course, there is the trivial way to do that: I have only the Page class, it has a field whether it was readed from file or from the web, and handle things accordingly, but this doesn't seem to be an elegant way. (There would be an if statement in the most of the functions).

I have two questions:

  1. How would you implement my problem?
  2. How is it possible to make it work in the way I mentioned before? So for example there is abstract Animal class, Dog and Cat extends that. How can I instantiate only one Animal, either Dog or Cat?
tusker
  • 57
  • 5

0 Answers0