Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do you call this design?

There is this one common design pattern that stuck in my head for the last couple hours, and it keeps bugging me because I don't remember the name of it.

I can't remember the name, but at the very least I could describe it.

The design is to load libraries at the appropriate time as to ease user experience in that they don't need to wait for unnecessary loading time. It's commonly used when starting up the program.

Below is a pseudo code in python

main.py

#main.py    
import platform


if platform.system() == "Darwin":
    from QwertyMac import QwertyMac as Application
elif platform.system() == "Windows":
    from QwertyWindows import QwertyWindows as Application
elif platform.system() == "Linux":
    from QwertyLinux import QwertyLinux as Application
else:
    print "platform is not supported"
    exit()

app = Application()
app.run()

QwertyMac.py

#QwertyMac.py
import sys, thread, time # and other 50++ libs.

QwertyWindows.py

#QwertyWindows.py
import sys, thread, time # and other 50++ libs.

QwertyLinux.py

#QwertyLinux.py
import sys, thread, time # and other 50++ libs.

As seen above, sys, thread, time and other similar libraries could just be imported on the main.py to reduce file size, but we don't want to design a software that takes 1 minute to start up just to tell the user that his platform is not supported, and thus we moved it to where they really belong to.

Any clues what this design is called?

like image 681
user3163916 Avatar asked Oct 20 '22 21:10

user3163916


1 Answers

Lazy loading design pattern: simple and prolific.

http://en.wikipedia.org/wiki/Lazy_loading

like image 177
Alex Weinstein Avatar answered Jan 04 '23 05:01

Alex Weinstein