I am making a small "search engine app". The app should get three pieces of input from the user:
- The name of the search engine as a string (e.g. "googe", "duckduckgo", etc)
- The search term
- The name of the website the user wants to search on if they want to search only webpages of a particular website (e.g. "reddit.com", "stackoverflow.com", etc)
I am having a SearchEngine
class for this which I am thinking it would initialize like so:
se = SearchEngine(url="https://google.com")
However, the user will be entering "google" as input, not the entire https://google.com URL.
Now, I plan to have both a command line and a web interface.
For example, in the CLI the engine name would come through an input functon:
engine_name = input("Search engine name: ")
In a web interface the engine name would come through an HTML input element.
So, the client is sending a name
while the SearchEngine
class is getting a url
. One way to solve that "incompatibility" would it be to initialize a SearchEngine object like below:
se = SearchEngine(name="google")
and convert the name
to a url
inside the SearchEngine
constructor. I am afraid that would be a bad design.
Would it be better to have another intermediate layer (class?) that converts name
to a url
? That way SearchEngine
would be independent from the user/client input format.
What design pattern am I using here? What design pattern should I use?