已经安装了 Python 仍然报错 no suitable Python interpreter found 如何解决?

雪峰
业界专家认证
2007-08-14 03:41:01
我最近刚刚接触 Linux,练习从源文件安装程序,可能这是太基础的东西,所以在网上搜索很久也没找到答案,所以才来麻烦各位高手给详细解释一下。
红旗 Linux Desktop 5.0 下安装 Scribes-0.3.2.8 或者 gEdit 2.18.0,执行 ./configure 编译总不能通过,最后报错:
Python >= 2.4
no suitable Python interpreter found
实际上已经安装了 Python 2.5.1,但仍然报上面的错。请问是什么原因,怎么解决?
详细的配置日志 config.log 文件的内容如下:
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by scribes configure 0.3.2.8, which was
generated by GNU Autoconf 2.61. Invocation command line was

$ ./configure --with-python-dir=/usr/python --prefix=/usr/local/

## --------- ##
## Platform. ##
## --------- ##

hostname = localhost
uname -m = i686
uname -r = 2.6.9-5.34DT
uname -s = Linux
uname -v = #1 Mon Jan 23 16:32:34 CST 2006

/usr/bin/uname -p = unknown
/bin/uname -X = unknown

/bin/arch = i686
/usr/bin/arch -k = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo = unknown
/bin/machine = unknown
/usr/bin/oslevel = unknown
/bin/universe = unknown

PATH: /usr/kerberos/sbin
PATH: /usr/kerberos/bin
PATH: /usr/local/sbin
PATH: /sbin
PATH: /usr/sbin
PATH: /bin
PATH: /usr/bin
PATH: /usr/X11R6/bin
PATH: /usr/local/bin
PATH: /usr/share/jre/bin
PATH: /root/bin


## ----------- ##
## Core tests. ##
## ----------- ##

configure:1883: checking for a BSD-compatible install
configure:1939: result: /usr/bin/install -c
configure:1950: checking whether build environment is sane
configure:1993: result: yes
configure:2058: checking for gawk
configure:2074: found /bin/gawk
configure:2085: result: gawk
configure:2096: checking whether make sets $(MAKE)
configure:2117: result: yes
configure:2301: checking whether to enable maintainer-specific portions of Makefiles
configure:2310: result: no
configure:2341: checking for style of include used by make
configure:2369: result: GNU
configure:2442: checking for gcc
configure:2458: found /usr/bin/gcc
configure:2469: result: gcc
configure:2707: checking for C compiler version
configure:2714: gcc --version >&5
gcc (GCC) 3.4.3 20041212 (Asianux 2.0 3.4.3-9.EL4.2)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

configure:2717: $? = 0
configure:2724: gcc -v >&5
Reading specs from /usr/lib/gcc/i386-redflag-linux/3.4.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,java,f77 --disable-libgcj --host=i386-redflag-linux
Thread model: posix
gcc version 3.4.3 20041212 (Asianux 2.0 3.4.3-9.EL4.2)
configure:2727: $? = 0
configure:2734: gcc -V >&5
gcc: `-V' option must have argument
configure:2737: $? = 1
configure:2760: checking for C compiler default output file name
configure:2787: gcc conftest.c >&5
configure:2790: $? = 0
configure:2828: result: a.out
configure:2845: checking whether the C compiler works
configure:2855: ./a.out
configure:2858: $? = 0
configure:2875: result: yes
configure:2882: checking whether we are cross compiling
configure:2884: result: no
configure:2887: checking for suffix of executables
configure:2894: gcc -o conftest conftest.c >&5
configure:2897: $? = 0
configure:2921: result:
configure:2927: checking for suffix of object files
configure:2953: gcc -c conftest.c >&5
configure:2956: $? = 0
configure:2979: result: o
configure:2983: checking whether we are using the GNU C compiler
configure:3012: gcc -c conftest.c >&5
configure:3018: $? = 0
...全文
3595 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
雪峰 2007-08-14
  • 打赏
  • 举报
回复
## ---------------- ##
## Cache variables. ##
## ---------------- ##

ac_cv_build=i686-pc-linux-gnu
ac_cv_c_compiler_gnu=yes
ac_cv_env_CC_set=
ac_cv_env_CC_value=
ac_cv_env_CFLAGS_set=
ac_cv_env_CFLAGS_value=
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=
ac_cv_env_CPP_set=
ac_cv_env_CPP_value=
ac_cv_env_LDFLAGS_set=
ac_cv_env_LDFLAGS_value=
ac_cv_env_LIBS_set=
ac_cv_env_LIBS_value=
ac_cv_env_PKG_CONFIG_set=
ac_cv_env_PKG_CONFIG_value=
ac_cv_env_build_alias_set=
ac_cv_env_build_alias_value=
ac_cv_env_host_alias_set=
ac_cv_env_host_alias_value=
ac_cv_env_target_alias_set=
ac_cv_env_target_alias_value=
ac_cv_func_bind_textdomain_codeset=yes
ac_cv_func_dcgettext=yes
ac_cv_header_inttypes_h=yes
ac_cv_header_libintl_h=yes
ac_cv_header_locale_h=yes
ac_cv_header_memory_h=yes
ac_cv_header_stdc=yes
ac_cv_header_stdint_h=yes
ac_cv_header_stdlib_h=yes
ac_cv_header_string_h=yes
ac_cv_header_strings_h=yes
ac_cv_header_sys_stat_h=yes
ac_cv_header_sys_types_h=yes
ac_cv_header_unistd_h=yes
ac_cv_host=i686-pc-linux-gnu
ac_cv_objext=o
ac_cv_path_EGREP='/bin/grep -E'
ac_cv_path_GCONFTOOL=/usr/bin/gconftool-2
ac_cv_path_GMSGFMT=/usr/bin/msgfmt
ac_cv_path_GREP=/bin/grep
ac_cv_path_INTLTOOL_ICONV=/usr/bin/iconv
ac_cv_path_INTLTOOL_MSGFMT=/usr/bin/msgfmt
ac_cv_path_INTLTOOL_MSGMERGE=/usr/bin/msgmerge
ac_cv_path_INTLTOOL_PERL=/usr/bin/perl
ac_cv_path_INTLTOOL_XGETTEXT=/usr/bin/xgettext
ac_cv_path_MSGFMT=/usr/bin/msgfmt
ac_cv_path_SED=/bin/sed
ac_cv_path_XGETTEXT=/usr/bin/xgettext
ac_cv_path_YELP=/usr/bin/yelp
ac_cv_path_ac_pt_PKG_CONFIG=/usr/bin/pkg-config
ac_cv_path_install='/usr/bin/install -c'
ac_cv_prog_AWK=gawk
ac_cv_prog_CPP='gcc -E'
ac_cv_prog_ac_ct_CC=gcc
ac_cv_prog_cc_c89=
ac_cv_prog_cc_g=yes
ac_cv_prog_make_make_set=yes
am_cv_CC_dependencies_compiler_type=none
am_cv_pathless_PYTHON=none
am_cv_val_LC_MESSAGES=yes
gdu_cv_have_gdu=yes
gdu_cv_version_required=0.3.2
gt_cv_func_dgettext_libc=yes
gt_cv_func_dgettext_libintl=no
gt_cv_func_ngettext_libc=yes
gt_cv_have_gettext=yes
雪峰 2007-08-14
  • 打赏
  • 举报
回复
configure:4468: checking for strings.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
configure:4468: checking for inttypes.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
configure:4468: checking for stdint.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
configure:4468: checking for unistd.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
configure:4529: checking build system type
configure:4547: result: i686-pc-linux-gnu
configure:4569: checking host system type
configure:4584: result: i686-pc-linux-gnu
configure:4622: checking locale.h usability
configure:4639: gcc -c -g -O2 conftest.c >&5
configure:4645: $? = 0
configure:4659: result: yes
configure:4663: checking locale.h presence
configure:4678: gcc -E conftest.c
configure:4684: $? = 0
configure:4698: result: yes
configure:4731: checking for locale.h
configure:4739: result: yes
configure:4753: checking for LC_MESSAGES
configure:4779: gcc -o conftest -g -O2 conftest.c >&5
configure:4785: $? = 0
configure:4802: result: yes
configure:4831: checking libintl.h usability
configure:4848: gcc -c -g -O2 conftest.c >&5
configure:4854: $? = 0
configure:4868: result: yes
configure:4872: checking libintl.h presence
configure:4887: gcc -E conftest.c
configure:4893: $? = 0
configure:4907: result: yes
configure:4940: checking for libintl.h
configure:4947: result: yes
configure:4958: checking for ngettext in libc
configure:4986: gcc -o conftest -g -O2 conftest.c >&5
configure:4992: $? = 0
configure:5010: result: yes
configure:5014: checking for dgettext in libc
configure:5042: gcc -o conftest -g -O2 conftest.c >&5
configure:5048: $? = 0
configure:5066: result: yes
configure:5075: checking for bind_textdomain_codeset
configure:5131: gcc -o conftest -g -O2 conftest.c >&5
configure:5137: $? = 0
configure:5155: result: yes
configure:5642: checking for msgfmt
configure:5669: result: /usr/bin/msgfmt
configure:5682: checking for dcgettext
configure:5738: gcc -o conftest -g -O2 conftest.c >&5
conftest.c:48: warning: conflicting types for built-in function 'dcgettext'
configure:5744: $? = 0
configure:5762: result: yes
configure:5773: checking if msgfmt accepts -c
configure:5788: msgfmt -c -o /dev/null conftest.foo
configure:5791: $? = 0
configure:5793: result: yes
configure:5803: checking for gmsgfmt
configure:5834: result: /usr/bin/msgfmt
configure:5844: checking for xgettext
configure:5871: result: /usr/bin/xgettext
configure:5900: gcc -o conftest -g -O2 conftest.c >&5
configure:5906: $? = 0
configure:6075: checking for catalogs to be installed
configure:6100: result: de fr nl it pt_BR sv
configure:6136: checking for sed
configure:6154: found /bin/sed
configure:6166: result: /bin/sed
configure:6176: checking for gconftool-2
configure:6194: found /usr/bin/gconftool-2
configure:6206: result: /usr/bin/gconftool-2
configure:6216: checking for yelp
configure:6234: found /usr/bin/yelp
configure:6246: result: /usr/bin/yelp
configure:6303: checking for pkg-config
configure:6321: found /usr/bin/pkg-config
configure:6333: result: /usr/bin/pkg-config
configure:6362: checking pkg-config is at least version 0.9.0
configure:6365: result: yes
configure:6378: $PKG_CONFIG --exists --print-errors "gnome-doc-utils >= $gdu_cv_version_required"
configure:6381: $? = 0
configure:6475: result: Using config source xml::/etc/gconf/gconf.xml.defaults for schema installation
configure:6490: result: Using $(sysconfdir)/gconf/schemas as install directory for schema files
configure:6547: checking for a Python interpreter with version >= 2.4
configure:6562: python -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
configure:6565: $? = 1
configure:6562: python2 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
configure:6565: $? = 1
configure:6562: python2.5 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
./configure: line 6563: python2.5: command not found
configure:6565: $? = 127
configure:6562: python2.4 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
./configure: line 6563: python2.4: command not found
configure:6565: $? = 127
configure:6562: python2.3 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
configure:6565: $? = 1
configure:6562: python2.2 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
./configure: line 6563: python2.2: command not found
configure:6565: $? = 127
configure:6562: python2.1 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
./configure: line 6563: python2.1: command not found
configure:6565: $? = 127
configure:6562: python2.0 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
./configure: line 6563: python2.0: command not found
configure:6565: $? = 127
configure:6562: python1.6 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
./configure: line 6563: python1.6: command not found
configure:6565: $? = 127
configure:6562: python1.5 -c import sys, string # split strings by '.' and convert to numeric. Append some zeros # because we need at least 4 digits for the hex conversion. minver = map(int, string.split('2.4', '.')) + [0, 0, 0] minverhex = 0 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[i] sys.exit(sys.hexversion < minverhex)
./configure: line 6563: python1.5: command not found
configure:6565: $? = 127
configure:6572: result: none
configure:6624: error: no suitable Python interpreter found
雪峰 2007-08-14
  • 打赏
  • 举报
回复
configure:3035: result: yes
configure:3040: checking whether gcc accepts -g
configure:3070: gcc -c -g conftest.c >&5
configure:3076: $? = 0
configure:3175: result: yes
configure:3192: checking for gcc option to accept ISO C89
configure:3266: gcc -c -g -O2 conftest.c >&5
configure:3272: $? = 0
configure:3295: result: none needed
configure:3315: checking dependency style of gcc
configure:3405: result: none
configure:3435: checking for intltool >= 0.35.0
configure:3442: result: 0.35.5 found
configure:3498: checking for perl
configure:3516: found /usr/bin/perl
configure:3528: result: /usr/bin/perl
configure:3547: checking for XML::Parser
configure:3550: result: ok
configure:3561: checking for iconv
configure:3579: found /usr/bin/iconv
configure:3592: result: /usr/bin/iconv
configure:3602: checking for msgfmt
configure:3620: found /usr/bin/msgfmt
configure:3633: result: /usr/bin/msgfmt
configure:3643: checking for msgmerge
configure:3661: found /usr/bin/msgmerge
configure:3674: result: /usr/bin/msgmerge
configure:3684: checking for xgettext
configure:3702: found /usr/bin/xgettext
configure:3715: result: /usr/bin/xgettext
configure:3752: gcc -o conftest -g -O2 conftest.c >&5
configure:3758: $? = 0
configure:3892: checking how to run the C preprocessor
configure:3932: gcc -E conftest.c
configure:3938: $? = 0
configure:3969: gcc -E conftest.c
conftest.c:11:28: ac_nonexistent.h: No such file or directory
configure:3975: $? = 1
configure: failed program was:
| /* confdefs.h. */
| #define PACKAGE_NAME "scribes"
| #define PACKAGE_TARNAME "scribes"
| #define PACKAGE_VERSION "0.3.2.8"
| #define PACKAGE_STRING "scribes 0.3.2.8"
| #define PACKAGE_BUGREPORT "<mystilleef@gmail.com>"
| #define PACKAGE "scribes"
| #define VERSION "0.3.2.8"
| #define GETTEXT_PACKAGE "scribes"
| /* end confdefs.h. */
| #include <ac_nonexistent.h>
configure:4008: result: gcc -E
configure:4037: gcc -E conftest.c
configure:4043: $? = 0
configure:4074: gcc -E conftest.c
conftest.c:11:28: ac_nonexistent.h: No such file or directory
configure:4080: $? = 1
configure: failed program was:
| /* confdefs.h. */
| #define PACKAGE_NAME "scribes"
| #define PACKAGE_TARNAME "scribes"
| #define PACKAGE_VERSION "0.3.2.8"
| #define PACKAGE_STRING "scribes 0.3.2.8"
| #define PACKAGE_BUGREPORT "<mystilleef@gmail.com>"
| #define PACKAGE "scribes"
| #define VERSION "0.3.2.8"
| #define GETTEXT_PACKAGE "scribes"
| /* end confdefs.h. */
| #include <ac_nonexistent.h>
configure:4118: checking for grep that handles long lines and -e
configure:4192: result: /bin/grep
configure:4197: checking for egrep
configure:4275: result: /bin/grep -E
configure:4280: checking for ANSI C header files
configure:4310: gcc -c -g -O2 conftest.c >&5
configure:4316: $? = 0
configure:4415: gcc -o conftest -g -O2 conftest.c >&5
configure:4418: $? = 0
configure:4424: ./conftest
configure:4427: $? = 0
configure:4444: result: yes
configure:4468: checking for sys/types.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
configure:4468: checking for sys/stat.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
configure:4468: checking for stdlib.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
configure:4468: checking for string.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
configure:4468: checking for memory.h
configure:4489: gcc -c -g -O2 conftest.c >&5
configure:4495: $? = 0
configure:4511: result: yes
 面试的时候,设计模式会经常被问到。其实我们在写代码中或多或少会用到一些模式,面试官问你设计模式的问题,更多是看你有没有总结过。如果一直都是在那垒代码,你当然会认为这是个很难的问题。所以我们需要总结一下设计模式。   1. SINGLETON 单例模式   单例模式:单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例单例模式。单例模式只应在有真正的“单一实例”的需求时才可使用。     俺有6个漂亮的老婆,她们的老公都是我,我就是我们家里的老公Sigleton,她们只要说道“老公”,都是指的同一个人,那就是我(刚才做了个梦啦,哪有这么好的事)。   2. FACTORY METHOD 工厂方法模式   工厂方法模式:核心工厂类不再负责所有产品的创建,而是将具体创建的工作交给子类去做,成为一个抽象工厂角色,仅负责给出具体工厂类必须实现的接口,而不接触哪一个产品类应当被实例化这种细节。     请MM去麦当劳吃汉堡,不同的MM有不同的口味,要每个都记住是一件烦人的事情,我一般采用Factory Method模式,带着MM到服务员那儿,说“要一个汉堡”,具体要什么样的汉堡呢,让MM直接跟服务员说就行了。   3. FACTORY 工厂模式   工厂模式:客户类和工厂类分开。消费者任何时候需要某种产品,只需向工厂请求即可。消费者无须修改就可以接纳新产品。缺点是当产品修改时,工厂类也要做相应的修改。如:如何创建及如何向客户端提供。     追MM少不了请吃饭了,麦当劳的ji翅和肯德基的ji翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个ji翅”就行了。麦当劳和肯德基就是生产ji翅的Factory。   4. BUILDER 建造模式   建造模式:将产品的内部表象和产品的生成过程分割开来,从而使一个建造过程生成具有不同的内部表象的产品对象。建造模式使得产品内部表象可以独立的变化,客户不必知道产品内部组成的细节。建造模式可以强制实行一种分步骤进行的建造过程。     MM超级爱听的就是“我爱你”这句话了,见到不同地方的MM,要能够用她们的方言跟她说这句话哦,我有一个多种语言翻译机,上面每种语言都有一个按键,见到MM我只要按对应的键,它就能够用相应的语言说出“我爱你”这句话了,国外的MM也可以轻松搞掂,这就是我的“我爱你”builder。(这一定比美军在伊拉克用的翻译机好卖)   5. PROTOTYPE 原型模式   原型模式允许动态的增加或减少产品类,产品类不需要非得有任何事先确定的等级结构,原始模型模式适用于任何的等级结构。缺点是每一个类都必须配备一个克隆方法。     跟MM用QQ聊天,一定要说些深情的话语了,我搜集了好多肉麻的情话,需要时只要copy出来放到QQ里面就行了,这就是我的情话prototype了。 原型模式:通过给出一个原型对象来指明所要创建的对象的类型,然后用复制这个原型对象的方法创建出更多同类型的对象。   6. ADAPTER 适配器模式   适配器(变压器)模式:把一个类的接口变换成客户端所期待的另一种接口,从而使原本因接口原因不匹配而无法一起工作的两个类能够一起工作。适配类可以根据参数返还一个合适的实例给客户端。     在朋友聚会上碰到了一个美女Sarah,从拉斯维加斯来的,可我不会说粤语,她不会说普通话,只好求助于我的朋友kent了,他作为我和Sarah之间的Adapter,让我和Sarah可以相互交谈了(也不知道他会不会耍我)。   7. BRIDGE 桥梁模式   桥梁模式:将抽象化与实现化脱耦,使得二者可以独立的变化,也就是说将他们之间的强关联变成弱关联,也就是指在一个软件系统的抽象化和实现化之间使用组合/聚合关系而不是继承关系,从而使两者可以独立的变化。     早上碰到MM,要说早上好,晚上碰到MM,要说晚上好;碰到MM穿了件新衣服,要说你的衣服好漂亮哦,碰到MM新做的发型,要说你的头发好漂亮哦。不要问我“早上碰到MM新做了个发型怎么说”这种问题,自己用BRIDGE组合一下不就行了。   8. COMPOSITE 合成模式   合成模式:合成模式将对象组织到树结构中,可以用来描述整体与部分的关系。合成模式就是一个处理对象的树结构的模式。合成模式把部分与整体的关系用树结构表示出来。合成模式使得客户端把一个个单独的成分对象和由他们复合而成的合成对象同等看待。     Mary今天过生日。“我过生日,你要送我一件礼物。”“嗯,好吧,去商店,你自己挑。”“这件T恤挺漂亮,买,这条裙子好看,买,这个包也不错,买。”“喂,买了三件了呀,我只答应送一件礼物的哦。”“什么呀,T恤加裙子加包包,正好配成一套呀,小姐,麻烦你包起来。”“……”,MM都会用Composite模式了,你会了没有?   9. DECORATOR 装饰模式   装饰模式:装饰模式以对客户端透明的方式扩展对象的功能,是继承关系的一个替代方案,提供比继承更多的灵活性。动态给一个对象增加功能,这些功能可以再动态的撤消。增加由一些基本功能的排列组合而产生的非常大量的功能。     Mary过完轮到Sarly过生日,还是不要叫她自己挑了,不然这个月伙食费肯定玩完,拿出我去年在华山顶上照的照片,在背面写上“较好的的礼物,就是爱你的Fita”,再到街上礼品店买了个像框(卖礼品的MM也很漂亮哦),再找隔壁搞美术设计的Mike设计了一个漂亮的盒子装起来……,我们都是Decorator,最终都在修饰我这个人呀,怎么样,看懂了吗?   10. FACADE 门面(外观)模式   门面模式:外部与一个子系统的通信必须通过一个统一的门面对象进行。门面模式提供一个高层次的接口,使得子系统更易于使用。每一个子系统只有一个门面类,而且此门面类只有一个实例,也就是说它是一个单例模式。但整个系统可以有多个门面类。     我有一个专业的Nikon相机,我就喜欢自己手动调光圈、快门,这样照出来的照片才专业,但MM可不懂这些,教了半天也不会。幸好相机有Facade设计模式,把相机调整到自动档,只要对准目标按快门就行了,一切由相机自动调整,这样MM也可以用这个相机给我拍张照片了。   11. FLYWEIGHT 享元模式   享元模式:FLYWEIGHT在拳击比赛中指最轻量级。享元模式以共享的方式高效的支持大量的细粒度对象。享元模式能做到共享的关键是区分内蕴状态和外蕴状态。内蕴状态存储在享元内部,不会随环境的改变而有所不同。外蕴状态是随环境的改变而改变的。外蕴状态不能影响内蕴状态,它们是相互独立的。将可以共享的状态和不可以共享的状态从常规类中区分开来,将不可以共享的状态从类里剔除出去。客户端不可以直接创建被共享的对象,而应当使用一个工厂对象负责创建被共享的对象。享元模式大幅度的降低内存中对象的数量。     每天跟MM发短信,手指都累死了,最近买了个新手机,可以把一些常用的句子存在手机里,要用的时候,直接拿出来,在前面加上MM的名字就可以发送了,再不用一个字一个字敲了。共享的句子就是Flyweight,MM的名字就是提取出来的外部特征,根据上下文情况使用。   12. PROXY 代理模式   代理模式:代理模式给某一个对象提供一个代理对象,并由代理对象控制对源对象的引用。代理就是一个人或一个机构代表另一个人或者一个机构采取行动。某些情况下,客户不想或者不能够直接引用一个对象,代理对象可以在客户和目标对象直接起到中介的作用。客户端分辨不出代理主题对象与真实主题对象。代理模式可以并不知道真正的被代理对象,而仅仅持有一个被代理对象的接口,这时候代理对象不能够创建被代理对象,被代理对象必须有系统的其他角色代为创建并传入。     跟MM在网上聊天,一开头总是“hi,你好”,“你从哪儿来呀?”“你多大了?”“身高多少呀?”这些话,真烦人,写个程序做为我的Proxy吧,凡是接收到这些话都设置好了自己的回答,接收到其他的话时再通知我回答,怎么样,酷吧。   13. CHAIN OF RESPONSIBLEITY 责任链模式   责任链模式:在责任链模式中,很多对象由每一个对象对其下家的引用而接起来形成一条链。请求在这个链上传递,直到链上的某一个对象决定处理此请求。客户并不知道链上的哪一个对象最终处理这个请求,系统可以在不影响客户端的情况下动态的重新组织链和分配责任。处理者有两个选择:承担责任或者把责任推给下家。一个请求可以最终不被任何接收端对象所接受。     晚上去上英语课,为了好开溜坐到了然后一排,哇,前面坐了好几个漂亮的MM哎,找张纸条,写上“Hi,可以做我的女朋友吗?如果不愿意请向前传”,纸条就一个接一个的传上去了,糟糕,传到第一排的MM把纸条传给老师了,听说是个老一手女呀,快跑!   14. COMMAND 命令模式   命令模式:命令模式把一个请求或者操作封装到一个对象中。命令模式把发出命令的责任和执行命令的责任分割开,委派给不同的对象。命令模式允许请求的一方和发送的一方独立开来,使得请求的一方不必知道接收请求的一方的接口,更不必知道请求是怎么被接收,以及操作是否执行,何时被执行以及是怎么被执行的。系统支持命令的撤消。     俺有一个MM家里管得特别严,没法见面,只好借助于她弟弟在我们俩之间传送信息,她对我有什么指示,就写一张纸条让她弟弟带给我。这不,她弟弟又传送过来一个COMMAND,为了感谢他,我请他吃了碗杂酱面,哪知道他说:“我同时给我姐姐三个男朋友送COMMAND,就数你最小气,才请我吃面。”   15. INTERPRETER 解释器模式   解释器模式:给定一个语言后,解释器模式可以定义出其文法的一种表示,并同时提供一个解释器。客户端可以使用这个解释器来解释这个语言中的句子。解释器模式将描述怎样在有了一个简单的文法后,使用模式设计解释这些语句。在解释器模式里面提到的语言是指任何解释器对象能够解释的任何组合。在解释器模式中需要定义一个代表文法的命令类的等级结构,也就是一系列的组合规则。每一个命令对象都有一个解释方法,代表对命令对象的解释。命令对象的等级结构中的对象的任何排列组合都是一个语言。     俺有一个《泡MM真经》,上面有各种泡MM的攻略,比如说去吃西餐的步骤、去看电影的方法等等,跟MM约会时,只要做一个Interpreter,照着上面的脚本执行就可以了。   16. ITERATOR 迭代子模式   迭代子模式:迭代子模式可以顺序访问一个聚集中的元素而不必暴露聚集的内部表象。多个对象聚在一起形成的总体称之为聚集,聚集对象是能够包容一组对象的容器对象。迭代子模式将迭代逻辑封装到一个独立的子对象中,从而与聚集本身隔开。迭代子模式简化了聚集的界面。每一个聚集对象都可以有一个或一个以上的迭代子对象,每一个迭代子的迭代状态可以是彼此独立的。迭代算法可以独立于聚集角色变化。     我爱上了Mary,不顾一切的向她求婚。Mary:“想要我跟你结婚,得答应我的条件” 我:“什么条件我都答应,你说吧” Mary:“我看上了那个一克拉的钻石” 我:“我买,我买,还有吗?” Mary:“我看上了湖边的那栋别墅” 我:“我买,我买,还有吗?” Mary:“我看上那辆法拉利跑车” 我脑袋嗡的一声,坐在椅子上,一咬牙:“我买,我买,还有吗?” ……   17. MEDIATOR 调停者模式   调停者模式:调停者模式包装了一系列对象相互作用的方式,使得这些对象不必相互明显作用。从而使他们可以松散偶合。当某些对象之间的作用发生改变时,不会立即影响其他的一些对象之间的作用。保证这些作用可以彼此独立的变化。调停者模式将多对多的相互作用转化为一对多的相互作用。调停者模式将对象的行为和协作抽象化,把对象在小尺度的行为上与其他对象的相互作用分开处理。     四个MM打麻将,相互之间谁应该给谁多少钱算不清楚了,幸亏当时我在旁边,按照各自的筹码数算钱,赚了钱的从我这里拿,赔了钱的也付给我,一切就OK啦,俺得到了四个MM的电话。   18. MEMENTO 备忘录模式   备忘录模式:备忘录对象是一个用来存储另外一个对象内部状态的快照的对象。备忘录模式的用意是在不破坏封装的条件下,将一个对象的状态捉住,并外部化,存储起来,从而可以在将来合适的时候把这个对象还原到存储起来的状态。     同时跟几个MM聊天时,一定要记清楚刚才跟MM说了些什么话,不然MM发现了会不高兴的哦,幸亏我有个备忘录,刚才与哪个MM说了什么话我都拷贝一份放到备忘录里面保存,这样可以随时察看以前的记录啦。   19. OBSERVER 观察者模式   观察者模式:观察者模式定义了一种一队多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态上发生变化时,会通知所有观察者对象,使他们能够自动更新自己。     想知道咱们公司**MM情报吗?加入公司的MM情报邮件组就行了,tom负责搜集情报,他发现的新情报不用一个一个通知我们,直接发布给邮件组,我们作为订阅者(观察者)就可以及时收到情报啦。   20. STATE 状态模式   状态模式:状态模式允许一个对象在其内部状态改变的时候改变行为。这个对象看上去象是改变了它的类一样。状态模式把所研究的对象的行为包装在不同的状态对象里,每一个状态对象都属于一个抽象状态类的一个子类。状态模式的意图是让一个对象在其内部状态改变的时候,其行为也随之改变。状态模式需要对每一个系统可能取得的状态创立一个状态类的子类。当系统的状态变化时,系统便改变所选的子类。     跟MM交往时,一定要注意她的状态哦,在不同的状态时她的行为会有不同,比如你约她今天晚上去看电影,对你没兴趣的MM就会说“有事情啦”,对你不讨厌但还没喜欢上的MM就会说“好啊,不过可以带上我同事么?”,已经喜欢上你的MM就会说“几点钟?看完电影再去泡吧怎么样?”,当然你看电影过程中表现良好的话,也可以把MM的状态从不讨厌不喜欢变成喜欢哦。   21. STRATEGY 策略模式   策略模式:策略模式针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换。策略模式使得算法可以在不影响到客户端的情况下发生变化。策略模把行为和环境分开。环境类负责维持和查询行为类,各种算法在具体的策略类中提供。由于算法和环境独立开来,算法的增减,修改都不会影响到环境和客户端。     跟不同类型的MM约会,要用不同的策略,有的请电影比较好,有的则去吃小吃效果不错,有的去海边浪漫最合适,单目的都是为了得到MM的芳心,我的追MM锦囊中有好多Strategy哦。   22. TEMPLATE METHOD 模板模式   模板方法模式:模板方法模式准备一个抽象类,将部分逻辑以具体方法以及具体构造子的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑。不同的子类可以以不同的方式实现这些抽象方法,从而对剩余的逻辑有不同的实现。先制定一个珠峰逻辑框架,而将逻辑的细节留给具体的子类去实现。     看过《如何说服女生上床》这部经典文章吗?女生从认识到上床的不变的步骤分为巧遇、打破僵局、展开追求、接吻、前戏、动手、爱抚、进去八大步骤(Template method),但每个步骤针对不同的情况,都有不一样的做法,这就要看你随机应变啦(具体实现)。   23. VISITOR 访问者模式   访问者模式:访问者模式的目的是封装一些施加于某种数据结构元素之上的操作。一旦这些操作需要修改的话,接受这个操作的数据结构可以保持不变。访问者模式适用于数据结构相对未定的系统,它把数据结构和作用于结构上的操作之间的耦合解脱开,使得操作集合可以相对自由的演化。访问者模式使得增加新的操作变的很容易,就是增加一个新的访问者类。访问者模式将有关的行为集中到一个访问者对象中,而不是分散到一个个的节点类中。当使用访问者模式时,要将尽可能多的对象浏览逻辑放在访问者类中,而不是放到它的子类中。访问者模式可以跨过几个类的等级结构访问属于不同的等级结构的成员类。     情人节到了,要给每个MM送一束鲜花和一张卡片,可是每个MM送的花都要针对她个人的特点,每张卡片也要根据个人的特点来挑,我一个人哪搞得清楚,还是找花店老板和礼品店老板做一下Visitor,让花店老板根据MM的特点选一束花,让礼品店老板也根据每个人特点选一张卡,这样就轻松多了。 

19,613

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧