I am writing a URL router in Python 3.1 and wondering if it is more than a taste to use one of the following options:
Tuples as constructor parameters:
router = Router( (r"/item/{id}", ItemResource()), (r"/article/{title}", ArticleResource()) )
Method call
router = Router() router.connect(r"/item/{id}", ItemResource()) router.connect(r"/article/{title}", ArticleResource())
Do you see any advantages or disadvantages here?
I prefer passing tuples to the constructor for two reasons that Alex did not mention (at least not explicitly).
readability. If accessible to any code reader, that Router instance requires a route list to be accessible.
Lose traction. Client code should not bother initializing router instances. This is the responsibility of the Router class.
, Router Router.__init__. , RoutesList:
Router.__init__
RoutesList
routes = RoutesList((r"/item/{id}", ItemResource()), (r"/article/{title}", ArticleResource())) router = Router(routes)
, , . , , , routes , ( ). : , Router : RoutesList (, , undefined ).
routes
, ;)
, , , , , , , (, disconnect connect , ?), "" , .
disconnect
connect
, " " ( , connect;-), - , , (, , ).
, , , ..., , , & . , " " .
, , , .
, , .
- , . URL- .
Source: https://habr.com/ru/post/1764558/More articles:The fastest way to extract color bits in a .pgm image? - javaConstructively control any value / object in a JSON tree of unknown depth - jsonWPF Изменение отображения меток на основе изменения содержимого связанного текстового поля - wpfJQuery: verify that the jquery plugin has already been called - jqueryDynamicObject and Jint - javascriptHow do you enable short functions in Awk One-Liners / Single Commands? - functionPHP profanity filter implementation - phpSQL Server 2005 - finding a value in an XML field - xmlSelf restart program on segfault under Linux - cCookies and javascript (tabs) - javascriptAll Articles