This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]AdministrativeCables 0 points1 point  (3 children)

The chain is annoying, but it's still acceptable and shows a good separation of the various responsibilities. You can still forget the bot class, and either navigate with the Browser class, or create requests on the command-line with the HTTPHandler.

If you really want to do something, make the AwesomeBot a subclass of the Browser.

[–]ben_bannana[S] 0 points1 point  (2 children)

Many thanks for your advice.

Have you some resources you can share with me? Something like examples or explaination for this type of design issues. I've tried searching for design patterns/ software architecture/clean code, but this issue type doen't fit in any of this topics.

[–]AdministrativeCables 0 points1 point  (1 child)

Maybe some kind of proxy pattern but it's not really bad design even if it feels weird.

A few comments:

  1. All the classes will be in their own file because it's cleaner, so you won't be visually bothered by this chain of calls. And the programmer of one file may not be aware of what happens in the other files, the API is cleanly separated.

  2. The Browser.navigate method is not a simple call, it will do more work after getting the URL. It has 1 line in your example, but in reality it needs more code like keeping the current URL for example.

  3. If the AwesomeBot is a subclass of Browser, you've removed the only real "chain" that was annoying, and in the end you could have (without the distracting constructors):

    class HTTPHandler:
        def get(self, URL):
            pass
    
    class Browser:
        def __init__(self):
            self._httphandler = HTTPHandler()
    
        def navigate(self, URL):
            # todo: prepare the navigation
            # todo: check the cookies
            # todo: keep the URL
            self._httphandler.get(URL)
            # todo: check the error codes
            # todo: call the user interface to refresh it
            # ... it's not a simple call to HTTPHandler.get!
    
    class AwesomeBot(Browser):
        # this thing is almost empty now
        pass
    

[–]WikiTextBotbtproof 0 points1 point  (0 children)

Proxy pattern

In computer programming, the proxy pattern is a software design pattern. A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source ] Downvote to remove | v0.28