⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap4-0.htm

📁 设计模式英文版 作者:Erich Gamma、Richard Helm、Ralph Johnson和John Vlissides 四人帮的书。 学设计模式的必读的书籍!经典中的经典
💻 HTM
字号:
<HTML><HEAD>	<TITLE>Structural Patterns</TITLE></HEAD>

<BODY BGCOLOR	= #FFFFFF>

<A NAME="top"></A>

<P>Structural patterns are concerned with how classes and objects are
composed to form larger structures.
Structural <EM>class</EM> patterns use inheritance to compose interfaces
or implementations.  As a simple example, consider how multiple
inheritance mixes two or more classes into one.  The result is a class
that combines the properties of its parent classes.  This pattern is
particularly useful for making independently developed class libraries
work together.  Another example is the class form of the
<A HREF="pat4afs.htm" TARGET="_mainDisplayFrame">Adapter&nbsp;(139)</A> pattern.  In general, an adapter makes one
interface (the adaptee's) conform to another, thereby providing a
uniform abstraction of different interfaces.  A class adapter
accomplishes this by inheriting privately from an adaptee class.  The
adapter then expresses its interface in terms of the adaptee's.</P>

<P>Rather than composing interfaces or implementations, structural <EM>object</EM> patterns describe ways to compose objects to realize new
functionality.  The added flexibility of object composition comes from
the ability to change the composition at run-time, which is impossible
with static class composition.</P>

<P><A HREF="pat4cfs.htm" TARGET="_mainDisplayFrame">Composite&nbsp;(163)</A> is an example of a structural object
pattern.  It describes how to build a class hierarchy made up of
classes for two kinds of objects: primitive and composite. The
composite objects let you compose primitive and other composite
objects into arbitrarily complex structures.  In the
<A HREF="pat5gfs.htm" TARGET="_mainDisplayFrame">Proxy&nbsp;(207)</A> pattern, a proxy acts as a convenient
surrogate or placeholder for another object.  A proxy can be used in
many ways. It can act as a local representative for an object in a
remote address space.  It can represent a large object that should be
loaded on demand.  It might protect access to a sensitive object.
Proxies provide a level of indirection to specific properties of
objects.  Hence they can restrict, enhance, or alter these properties.</P>

<P>The <A HREF="pat4ffs.htm" TARGET="_mainDisplayFrame">Flyweight&nbsp;(195)</A> pattern defines a structure for
sharing objects.  Objects are shared for at least two reasons:
efficiency and consistency.  Flyweight focuses on sharing for space
efficiency.  Applications that use lots of objects must pay careful
attention to the cost of each object.  Substantial savings can be had
by sharing objects instead of replicating them.  But objects can be
shared only if they don't define context-dependent state.  Flyweight
objects have no such state.  Any additional information they need to
perform their task is passed to them when needed.  With no
context-dependent state, Flyweight objects may be shared freely.</P>

<P>Whereas Flyweight shows how to make lots of little objects,
<A HREF="pat4efs.htm" TARGET="_mainDisplayFrame">Facade&nbsp;(185)</A> shows how to make a single object represent
an entire subsystem.  A facade is a representative for a set of
objects.  The facade carries out its responsibilities by forwarding
messages to the objects it represents.  The <A HREF="pat4bfs.htm"
TARGET="_mainDisplayFrame">Bridge&nbsp;(151)</A>
pattern separates an object's abstraction from its implementation so
that you can vary them independently.</P>

<P><A HREF="pat4dfs.htm" TARGET="_mainDisplayFrame">Decorator&nbsp;(175)</A> describes how to add responsibilities
to objects dynamically.  Decorator is a structural pattern that
composes objects recursively to allow an open-ended number of
additional responsibilities.  For example, a Decorator object
containing a user interface component can add a decoration like a
border or shadow to the component, or it can add functionality like
scrolling and zooming.  We can add two decorations simply by nesting
one Decorator object within another, and so on for additional
decorations.  To accomplish this, each Decorator object must conform
to the interface of its component and must forward messages to it.
The Decorator can do its job (such as drawing a border around the
component) either before or after forwarding a message.</P>

<P>Many structural patterns are related to some degree.  We'll discuss
these relationships at the end of the chapter.</P>

<A NAME="last"></A>
<P><A HREF="#top"><IMG SRC="gifsb/up3.gif" BORDER=0></A><BR>
<A HREF="pat4afs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/rightar3.gif"
	ALIGN=TOP BORDER=0></A> <A HREF="pat4afs.htm"
	TARGET="_mainDisplayFrame">Adapter</A><BR>
<A HREF="disc3fs.htm" TARGET="_mainDisplayFrame"><IMG SRC="gifsb/leftarr3.gif"
	ALIGN=TOP BORDER=0></A> <A HREF="disc3fs.htm"
	TARGET="_mainDisplayFrame">Discussion of Creational Patterns</A>
</P>

</BODY>

</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -