你怎么称呼这个设计?

时间:2014-11-25 19:32:07

标签: design-patterns

在过去的几个小时里,有一种常见的设计模式在我脑海中浮现,它一直困扰着我,因为我不记得它的名字。

我无法记住这个名字,但至少我可以形容它。

设计是在适当的时间加载库,以便于用户体验,因为他们不需要等待不必要的加载时间。 它是在启动程序时常用的。

下面是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.

如上所示,sys,thread,time和其他类似的库可以在main.py上导入以减小文件大小,但我们不想设计一个只需1分钟启动的软件告诉用户他的平台不受支持,因此我们将其移动到他们真正属于的位置。

有什么线索说明这个设计是什么?

1 个答案:

答案 0 :(得分:3)

延迟加载设计模式:简单而多产。

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