I was reading Python's requests library's code to find out how it works. Since this library has a simple usage interface, it creates a more complex object beyond. For instance:requests.get(...)Is a shortcut to something like:s = Session()r = s.request(get, ...)return rI do like this approach but I'd like to know whether it is a well-known design pattern or not. It's important to say that we are able to use Session class (it isn't a private/internal class). We can see a similar (little bit different I guess) technique in Javascript. Date.now = function () { return new Date().getTime ....Is there a name to this approach? After spending some minutes looking for it, I wasn't able to find a suitable explanation. Should I consider it as a Proxy or a Facade?
Function acting as a shortcut to object's methods
javascript;python;interfaces;proxy
I think there is many way to classify the idiom.Wrapper of course, but it can lead to many patterns associate with it.book Implementation Patterns mentions some patterns:LIBRARY CLASS in Chapter 5:Where do you put functionality that doesnt fit into any object? One solution is to create static methods on an otherwise-empty class. No one is expected to ever create instances of this class. It is just there as a holder for the functions in the library.also METHOD OBJECT in Chapter 7:This is one of my favorite patterns, probably because I use it so infrequently but the results are spectacular when I do. Creating method object can help you turn a tangled mass of code packed into an impossible method into readable, clear code that gradually reveals details to readers. This is a pattern I apply after I have some code working, and the more complex the method the better.Also I think it is a simple Adapter/Facade pattern as @Joel Harmon already mention.I think The purpose of the idiom in your case:Requests library:reveals details to readers/userskeep api easy to useLayers Architecture, High Level Low Level divide, low level can change, high level api won'tDate.now:I look on https://developer.mozilla.orgDescriptionBecause now() is a static method of Date, you always use it as Date.now().PolyfillThis method was standardized in ECMA-262 5th edition. Engines which have not been updated to support this method can work around the absence of this method using the following shim:if (!Date.now) {  Date.now = function now() {    return new Date().getTime();  };}using the following shim so it is a adapterstatic method of Date, yes LIBRARY CLASS as the book Implementation Patterns said.