﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Dedian-随笔分类-Design Patterns</title><link>http://www.blogjava.net/dedian/category/11495.html</link><description>-- 关注搜索引擎的开发</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 07:45:37 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 07:45:37 GMT</pubDate><ttl>60</ttl><item><title>Design Patterns - 8 - Proxy</title><link>http://www.blogjava.net/dedian/archive/2006/05/12/45757.html</link><dc:creator>Dedian</dc:creator><author>Dedian</author><pubDate>Thu, 11 May 2006 20:10:00 GMT</pubDate><guid>http://www.blogjava.net/dedian/archive/2006/05/12/45757.html</guid><wfw:comment>http://www.blogjava.net/dedian/comments/45757.html</wfw:comment><comments>http://www.blogjava.net/dedian/archive/2006/05/12/45757.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dedian/comments/commentRss/45757.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dedian/services/trackbacks/45757.html</trackback:ping><description><![CDATA[Purpose:<br /><br />
To control access to an object, provide a surrogate or placeholder
(proxy) for it. As a mostly used strategy, Proxy can defer the creation
and initialization of the object until it is on demand.<br /><br />
Structure:<br /><br />
Similar to adapter, client includes an object of proxy to access, and proxy includes a real object that proxy represents.<br /><br />
Difference from Adapter:<br /><br />
Adapter provides a different interface to the object it adapts. In
contrast, Proxy provides the same interface as its subject. As a
protection of real object, Proxy can refuse to perform an operation
that the subject will perform.<br /><br />
Example:<br />
http://www.javaworld.com/javaworld/jw-02-2002/jw-0222-designpatterns.html<br /><br />
Reference:<br />
Book: (GoF)Design Patterns<br />
http://en.wikipedia.org/wiki/Proxy_design_pattern<br />
http://www.inf.bme.hu/ooret/1999osz/DesignPatterns/Proxy4/<br />
http://alumni.media.mit.edu/~tpminka/patterns/Proxy.html<br /><br /><br /><img src ="http://www.blogjava.net/dedian/aggbug/45757.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dedian/" target="_blank">Dedian</a> 2006-05-12 04:10 <a href="http://www.blogjava.net/dedian/archive/2006/05/12/45757.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Patterns - 7 - Mediator</title><link>http://www.blogjava.net/dedian/archive/2006/05/12/45756.html</link><dc:creator>Dedian</dc:creator><author>Dedian</author><pubDate>Thu, 11 May 2006 19:24:00 GMT</pubDate><guid>http://www.blogjava.net/dedian/archive/2006/05/12/45756.html</guid><wfw:comment>http://www.blogjava.net/dedian/comments/45756.html</wfw:comment><comments>http://www.blogjava.net/dedian/archive/2006/05/12/45756.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dedian/comments/commentRss/45756.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dedian/services/trackbacks/45756.html</trackback:ping><description><![CDATA[Purpose:<br /><br />
Encapsulate a set of objects which interact with each other. The
benefit to do this is keeping objects from communicating with each
other directly. All the messages between objects should be sent to
mediator at first and then mediator will control and coordinate those
interaction. Also, mediator can handle external interaction request and
decide which object to response the external request.<br /><br />
Structure:<br /><br />
star topology: Mediator class is as a hub which connects to a set of classes (colleague classes).<br /><br />
Difference from Facade Pattern:<br /><br />
Facade differs from Mediator in that it abstracts a subsystem of
objects to provide a more convenient interface. Its protocol is
unidirectional. That is, Facade objects make requests of the subsystem
classes but not vice versa. In contrast, Mediator enables cooperative
behavior that colleague objects don't or can't provide, and the
protocol is multidirectional.<br /><br />
reference:<br /><br />
Gamma, E., R. Helm, R. Johnson, J. Vlissides (1995).
Design Patterns. Addison Wesley. ISBN 0.201-63361-2<br />
http://sern.ucalgary.ca/courses/seng/443/W02/assignments/Mediator/<br />
http://my.execpc.com/~gopalan/design/behavioral/mediator/mediator.html<br /><img src ="http://www.blogjava.net/dedian/aggbug/45756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dedian/" target="_blank">Dedian</a> 2006-05-12 03:24 <a href="http://www.blogjava.net/dedian/archive/2006/05/12/45756.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Patterns - 6 - Facade</title><link>http://www.blogjava.net/dedian/archive/2006/04/20/42092.html</link><dc:creator>Dedian</dc:creator><author>Dedian</author><pubDate>Thu, 20 Apr 2006 02:04:00 GMT</pubDate><guid>http://www.blogjava.net/dedian/archive/2006/04/20/42092.html</guid><wfw:comment>http://www.blogjava.net/dedian/comments/42092.html</wfw:comment><comments>http://www.blogjava.net/dedian/archive/2006/04/20/42092.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dedian/comments/commentRss/42092.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dedian/services/trackbacks/42092.html</trackback:ping><description><![CDATA[			
			Purpose:<br />
Defines a higher-level interface to hide subsystem's complexities and provides an easy interface for client to use.<br /><br />
Case study:<br />
Compiler subsystem<br /><br />


Structure:<br />
-- The facade and backend classes(subsystem classes) are in a
separate
package from the client.<br />
-- The backend API is package-private<br />
-- The
facade API is public.<br /><br />


Implementation:<br />
consider following two issues when implementing a facade:<br />


-- Reducing client-subsystem coupling.<br />


-- Public versus private subsystem classes.<br /><br />
reference:<br />
http://www.allapplabs.com/java_design_patterns/facade_pattern.htm<br /><img src ="http://www.blogjava.net/dedian/aggbug/42092.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dedian/" target="_blank">Dedian</a> 2006-04-20 10:04 <a href="http://www.blogjava.net/dedian/archive/2006/04/20/42092.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Patterns - 5 - Decorator</title><link>http://www.blogjava.net/dedian/archive/2006/04/20/42066.html</link><dc:creator>Dedian</dc:creator><author>Dedian</author><pubDate>Thu, 20 Apr 2006 00:53:00 GMT</pubDate><guid>http://www.blogjava.net/dedian/archive/2006/04/20/42066.html</guid><wfw:comment>http://www.blogjava.net/dedian/comments/42066.html</wfw:comment><comments>http://www.blogjava.net/dedian/archive/2006/04/20/42066.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dedian/comments/commentRss/42066.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dedian/services/trackbacks/42066.html</trackback:ping><description><![CDATA[Purpose:<br />

Attach additional responsiblities to an object dynamically, which thus
provide a flexible alternative to subclassing for extending
functionality.<br /><br />

Structure:<br />

Typically, there will be a parameter to pass original object to
decorator object in its constructor, then decorator can implement
additional functions within its own interface and apply to original
object.<br /><br />

when to use:<br /><br />

-- when subclassing is not avaible<br />

-- when the responsibilities (for different functions) are required flexiable and dynamical<br />

-- can not predict combination of extending functionality. (We can not
design subclasses for all combination of potential additional
functionalities at compile time)<br /><br />

reference:<br />

Book: Design Pattern (GoF)<br />

http://en.wikipedia.org/wiki/Decorator_pattern<img src ="http://www.blogjava.net/dedian/aggbug/42066.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dedian/" target="_blank">Dedian</a> 2006-04-20 08:53 <a href="http://www.blogjava.net/dedian/archive/2006/04/20/42066.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Patterns - 4 - Composite</title><link>http://www.blogjava.net/dedian/archive/2006/04/20/42064.html</link><dc:creator>Dedian</dc:creator><author>Dedian</author><pubDate>Thu, 20 Apr 2006 00:52:00 GMT</pubDate><guid>http://www.blogjava.net/dedian/archive/2006/04/20/42064.html</guid><wfw:comment>http://www.blogjava.net/dedian/comments/42064.html</wfw:comment><comments>http://www.blogjava.net/dedian/archive/2006/04/20/42064.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dedian/comments/commentRss/42064.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dedian/services/trackbacks/42064.html</trackback:ping><description><![CDATA[Purpose:<br />

Compose objects into tree structures to represent part-whole
hierarchies. Composite lets clients treat individual objects and
compostions of objects uniformly.<br /><br />

Structure:<br />

The composite object contains other primitive objects(or say
Components), and has the same operation as in those primitive objects.
Thus we can operater the composite object with the same operations as a
whole. Or in other word, composite object is a container of primitive
ojects and itself is derived from same base (abstract) class as
primitives, so that it can have same operations as primitives.
Actually, we can say that the abstract class represents both primitives
and their containers<br /><br />

Implementation:<br />

-- Extend a base class that represents primitive objects. And the same
operation(override function) will be implemented by iterating over that
collection and invoking the appropriate method for each component in
the collection.<br />

-- Add &amp; Remove function (for component collection) will be defined
in base class, though it is meaninglessful for leaf classes.<br /><br />

reference:<br />

http://www.javaworld.com/javaworld/jw-09-2002/jw-0913-designpatterns.html<br />

http://www.codeproject.com/useritems/Composite.asp<br /><br />

example:<br />

http://java.sun.com/blueprints/patterns/CompositeView.html<img src ="http://www.blogjava.net/dedian/aggbug/42064.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dedian/" target="_blank">Dedian</a> 2006-04-20 08:52 <a href="http://www.blogjava.net/dedian/archive/2006/04/20/42064.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Patterns - 3 - Bridge</title><link>http://www.blogjava.net/dedian/archive/2006/04/19/42003.html</link><dc:creator>Dedian</dc:creator><author>Dedian</author><pubDate>Wed, 19 Apr 2006 12:52:00 GMT</pubDate><guid>http://www.blogjava.net/dedian/archive/2006/04/19/42003.html</guid><wfw:comment>http://www.blogjava.net/dedian/comments/42003.html</wfw:comment><comments>http://www.blogjava.net/dedian/archive/2006/04/19/42003.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dedian/comments/commentRss/42003.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dedian/services/trackbacks/42003.html</trackback:ping><description><![CDATA[Purpose:<br />Decouple an abstraction from its implementation so that the two can vary independently.<br /><br />To
think about this situation that an abstract class has two categories of
inheritance. Each category can be a seperate hierarchical
inheritance tree, if we derive all the subclasses from the
abstract class, it will make complex when we need to get some
sub-classes that contains facades from two categories. So we need
seperate those subclasses into differenct categories, typically one
into implementation hierarchy while another into abstraction hierarchy
which can employ subclasses of implementation hierarchy. No matter
how, the relationship between different hierarchies is a bridge. From
this point, the bridge pattern design lets different hierarchies can
evolve seperately.<br /><br />The structure of the Adapter Pattern (object
adapter) may look similar to the Bridge Pattern. However, the adapter
is meant to change the interface of an existing object and is mainly
intended to make unrelated classes work together.<br /><br />reference:<br />book:<span style="font-size: 10pt; font-family: Verdana;">"<span>Design Patterns” Gamma et al.</span></span><br />http://en.wikipedia.org/wiki/Bridge_pattern<br />http://www.c-sharpcorner.com/Language/BridgePatternsinCSRVS.asp<br />http://www.codeproject.com/gen/design/bridge.asp<br /><img src ="http://www.blogjava.net/dedian/aggbug/42003.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dedian/" target="_blank">Dedian</a> 2006-04-19 20:52 <a href="http://www.blogjava.net/dedian/archive/2006/04/19/42003.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Patterns - 2 - Adapter</title><link>http://www.blogjava.net/dedian/archive/2006/04/19/42000.html</link><dc:creator>Dedian</dc:creator><author>Dedian</author><pubDate>Wed, 19 Apr 2006 12:37:00 GMT</pubDate><guid>http://www.blogjava.net/dedian/archive/2006/04/19/42000.html</guid><wfw:comment>http://www.blogjava.net/dedian/comments/42000.html</wfw:comment><comments>http://www.blogjava.net/dedian/archive/2006/04/19/42000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dedian/comments/commentRss/42000.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dedian/services/trackbacks/42000.html</trackback:ping><description><![CDATA[Purpose: Adapters are used to enable objects with different interfaces
to communicate with each other which convert the interface of a class
into another interface clients expect thus let classes work together
without imcompatible interfaces problem.<br /><br />Object Adapter:<br /><br />-- use compositional technique<br />--
by composing interface B's instance within interface A (target
interface, adapter) and implement interface A in terms of B's
interface(adaptee). Interface A is Object Adapter which enables the
client (the class or object to use Interface A) and the
adaptee(Interface B) to be completely decoupled from each other.<br /><br />Class Adapter:<br /><br />-- use multiple inheritance<br />--
Notice that Java is not supporting true multiple inheritance, there
must be one inheritance is from Java Interface(implementation) not Java
class. So take above Object Adapter as example, if client want to
access Interface B, the adpater Interface A will inherit from
class(Class Adapter) which Client can access, and inherit the
implementation of Interface B(Adaptee). So Interface A can have a
funtion to call functions in Interface B, and so that Interface will
not have an object of Interface B, that is the difference from Object
Adapter method.<br /><br />reference:<br />http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/adapter.htm <br /><br /><img src ="http://www.blogjava.net/dedian/aggbug/42000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dedian/" target="_blank">Dedian</a> 2006-04-19 20:37 <a href="http://www.blogjava.net/dedian/archive/2006/04/19/42000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Design Patterns - 1 - Abstract Factory (Creatioanl)</title><link>http://www.blogjava.net/dedian/archive/2006/04/19/41999.html</link><dc:creator>Dedian</dc:creator><author>Dedian</author><pubDate>Wed, 19 Apr 2006 12:33:00 GMT</pubDate><guid>http://www.blogjava.net/dedian/archive/2006/04/19/41999.html</guid><wfw:comment>http://www.blogjava.net/dedian/comments/41999.html</wfw:comment><comments>http://www.blogjava.net/dedian/archive/2006/04/19/41999.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dedian/comments/commentRss/41999.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dedian/services/trackbacks/41999.html</trackback:ping><description><![CDATA[The main purpose of Factory method is to create objects. There will be
one product instant creation function (Factory Method) in the abstract
class(Creator), which can be overrided by its subclasses(Concrete
Creator) and thus products can be specified in subclasses.<br /><br />reference:<br /><br />http://gsraj.tripod.com/design/creational/factory/factory.html<br />http://en.wikipedia.org/wiki/Factory_method_pattern<br />http://www.developer.com/java/other/article.php/626001<br />http://www.javacamp.org/designPattern/factory.html<br /><img src ="http://www.blogjava.net/dedian/aggbug/41999.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dedian/" target="_blank">Dedian</a> 2006-04-19 20:33 <a href="http://www.blogjava.net/dedian/archive/2006/04/19/41999.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>