ÖйúIT¶¯Á¦,×îÐÂ×îÈ«µÄIT¼¼Êõ½Ì³Ì
×îÐÂ100ƪ | ÍÆ¼ö100ƪ | רÌâ100ƪ | ÅÅÐаñ | ËÑË÷ | ÔÚÏßAPIÎĵµ
Ê× Ò³ | ³ÌÐò¿ª·¢ | ²Ù×÷ϵͳ | Èí¼þÓ¦Óà| Í¼ÐÎͼÏó | ÍøÂçÓ¦Óà| ¾«ÎÄÜöÝÍ | ½ÌÓýÈÏÖ¤ | Ó²¼þά»¤ | Î´ÕûÀíÆª | Õ¾³¤½Ì³Ì
ASP JS PHP¹¤³Ì ASP.NET ÍøÕ¾½¨Éè UML J2EESUN .NET VC VB VFP ÍøÂçά»¤ Êý¾Ý¿â DB2 SQL2000 Oracle Mysql
·þÎñÆ÷ Win2000 Office C DreamWeaver FireWorks Flash PhotoShop ÉÏÍø±¦µä CorelDraw ЭÒé´óÈ« ÍøÂ簲ȫ ΢ÈíÈÏÖ¤
Ó²¼þά»¤  CPU  Ö÷°å  Ó²ÅÌ  ÄÚ´æ  ÏÔ¿¨  ÏÔʾÆ÷  ¼üÅÌÊó±ê  Éù¿¨ÒôÏä  ´òÓ¡»ú  »úÏäµçÔ´  BIOS  Íø¿¨  C#  Java  Delphi  vs.net2005
  µ±Ç°Î»Öãº> ³ÌÐò¿ª·¢ > ±à³ÌÓïÑÔ > Visual C++ > Èí¼þ¹¤³Ì
Pattern Tips Ö®Ò»
×÷Õß:δ֪ ʱ¼ä:2005-07-20 14:22 ³ö´¦:VC֪ʶ¿â Ôð±à:chinaitpower
              ÕªÒª£ºPattern Tips Ö®Ò»

Pattern Tips Ö®Ò»
×÷ÕߣºÎÂêÅ

¸Ðл£º¡¶Éè¼ÆÄ£Ê½¡·Ò»ÊéµÄ×÷ÕßGamma£¬Helm£¬JohnsonºÍVilssides£¬ÒëÕßÀîÓ¢¾üµÈ

----------------------------------˵Ã÷----------------------------

Adapter£¬Bridge£¬Facade£¬Proxy¡£ËüÃǶ¼ÊÇStructural Patterns£¬ËüÃǵĹØÏµÈçÏÂͼËùʾ£º


----------------------------------Adapter----------------------------

¡ñTip 1£º¹Ø¼ü×Ö¡£existing£¬reuse¡£

¡ñTip 2£ºÍ¼¡£

¿ÉÒÔ¿´µ½£¬AdapterÊÇÔÚTargetºÍAdapteeÒѾ­existingµÄÇé¿öÏ£¬ÁÙΣÊÜÃüµÄ£¬ÊÇ¡°Êº󹤳̡±¡£

¡ñTip 3£ºÊµÏÖºÍʹÓᣵ½µ×ʹÓÃClass Adapter»¹ÊÇObject Adapter£¬ÒªÊÓ²»Í¬Çé¿ö¶ø¶¨¡£

Class AdapterÓŵ㣺Lets Adapter override some of Adaptee''s behavior, since Adapter is a subclass of Adaptee¡£ÁíÍ⣬²»±ØÒýÈë¶îÍâµÄʵÀý»¯ÎÊÌ⣬Introduces only one object, and no additional pointer indirection is needed to get to the adaptee¡£

Class Adapterȱµã£ºAdapts Adaptee to Target by committing to a concrete Adapter class. As a consequence, a class adapter won''t work when we want to adapt a class and all its subclasses.

Object AdapterÓŵ㣺Lets a single Adapter work with many Adaptees©¤that is, the Adaptee itself and all of its subclasses (if any). The Adapter can also add functionality to all Adaptees at once.

Object Adapterȱµã£ºMakes it harder to override Adaptee behavior.

MFC±¾Éí¾ÍÊÇAdapterµÄÀý×Ó£¬Win32 APIÊÇ»ùÓÚfuncµÄ£¬MFCÊÇ»ùÓÚclassµÄ¡£

¡ñTip 4£ºÓŵ㡣¿ÉÓÃÓÚÕûºÏÒÅÁôϵͳ¡£

¡ñTip 5£º¾ÖÏÞÐÔ¡£Èç¹ûÒÅÁôϵͳ»¹ÔÚ·¢Õ¹¡¢±ä»¯ºÍÔö³¤Ö®ÖУ¬ÕûºÏµÄ¿ªÏú»áºÜ´ó¡£

----------------------------------Bridge----------------------------

¡ñTip 1£º¹Ø¼ü×Ö¡£Abstraction and its Implementation¡£

¡ñTip 2£ºÍ¼¡£



¿ÉÒÔ¿´µ½£¬ÎÒ°Ñͼ·Ö³ÉÁË4¸öLayer£ºApplication£¬Abstraction£¬Logic£¬Implementor¡£

Application²ãµÄClientʹÓÃAbstraction²ãµÄ³éÏó¶ÔÏó£¬ÕâЩ³éÏó¶ÔÏóÊǺ;ßÌåÆ½Ì¨Î޹صģ»Abstraction²ãµÄ³éÏó¶ÔÏóÓÖÊÇÓÉImplementor²ãµÄ¶ÔÏóʵÏֵģ¬ºÍ¾ßÌåÆ½Ì¨ÓйصĶÔÏóÔÚImplementor²ã£»ÎªÁ˸ü¼ÓÇåÎúµØËµÃ÷ÎÊÌ⣬ÎÒÔÚAbstraction²ãºÍImplementor²ãÖ®¼äÔö¼ÓÁËLogic²ã£¬¸Ã²ãÊÇImplementorÈçºÎʵÏÖAbstractionµÄ³ÌÐòÂß¼­¡£

Æäʵ£¬BridgeģʽÊǷdz£µäÐ͵ÄLayer-likeģʽ¡£ÎªÁ˶Աȷ½±ã£¬ÎÒ·ÅÒ»ÕÅET++µÄLayerͼÔÚϱߡ£

¡ñTip 3£ºÊµÏÖºÍʹÓá£

Ôڴ˼¯ÖÐÌÖÂÛÒ»¸öÎÊÌ⣺RefinedImplementorµÄʵÀý»¯ÎÊÌâ¡£ÒòΪRefinedAbstraction¿Ï¶¨ÊÇÓÉClientʵÀý»¯µÄ£¬µ«RefinedImplementorµÄʵÀý»¯È´¿ÉÒÔ·ÖΪ2ÖÖÇé¿ö£º

µÚ1ÖÖÇé¿ö£¬ÓÉAbstraction»òRefinedAbstractionʵÀý»¯¡£ÕâÒªÇóAbstraction»òRefinedAbstractionÖªµÀËùÓеÄRefinedImplementor£¬¾ßÌåʵÀý»¯ÄÄÒ»¸ö£¬¿ÉÒÔͨ¹ýAbstraction::Abstraction(para)µÄ²ÎÊýÀ´È·¶¨¡£

µÚ2ÖÖÇé¿ö£¬Î¯Íиø±ðµÄ¶ÔÏóÀ´ÊµÀý»¯¡£µäÐ͵ģ¬¿ÉÒÔίÍиøÒ»¸öAbstract FactoryÀ´ÊµÀý»¯¡£ÕâÑù£¬AbstractionÖ»ÐèÒªÖªµÀImplementorÕâ¸öInterface£¬ÕâÊÇÒ»¸öÁ¼ÐÔÒÀÀµ£¬ÔÚͼÖб»ÎÒ»­³ÉÁËÂÌÉ«¡£

ET++ÖУ¬ºÍƽ̨Î޹صÄWindowÊÇÓÃºÍÆ½Ì¨Ïà¹ØµÄWindowPortʵÏֵ쬵«ºóÕßµÄʵÀý»¯ÊÇίÍÐ(delegate)WindowSystemÕâ¸öAbstract FactoryÀ´Íê³ÉµÄ£º

class Window {
...
protected:
  WindowImp* GetWindowImp(); ///////////////call Abstract Factory and return Implementor
private:
  WindowImp* _imp;  ////////////save GetWindowImp() ''s return value
...
};

WindowImp* Window::GetWindowImp () {
  if (_imp == 0) {
    _imp = WindowSystemFactory::Instance()->MakeWindowImp();////////////////////WindowSystemFactory is a Singleton
  }
  return _imp;
}

¡ñTip 4£ºÖ§³Ö±ä»¯¡£Putting the Window abstraction and its implementation in separate class hierarchies¡£You can extend the Abstraction and Implementor hierarchies independently¡£Í¼ÖеĻÆÉ«Class¾ÍÊǼÙÏëºóÀ´À©³äµÄ¡£

----------------------------------Proxy----------------------------

¡ñTip 1£º¹Ø¼ü×Ö¡£Placeholder£¬Control¡£

¡ñTip 2£ºÍ¼¡£


¿ÉÒÔ¿´µ½£¬ProxyºÍRealthingµÄ¶ÔÍâ½Ó¿ÚÊÇÏàͬµÄ¡£

¡ñTip 3£ºÊµÏÖºÍʹÓá£ÌÖÂÛÁ½¸ö¹Ø¼ü×Ö£º

Placeholder¡£¿ÉÒÔÊÇa direct reference to its real subject£¬±ÈÈçÔÚͬһ̨PCÉÏ(ÇÒÔÚͬһ¸öApplicationÄÚ)£¬DrawProxyÖ®¼äµ÷ÓÃDraw£»Ò²¿ÉÒÔÊÇonly an indirect reference£¬±ÈÈç¿çÍøÂçµÄÓ¦Ó㬿ÉÄÜÖ»ÖªµÀ¡°host ID and local address on host¡±£¬¹þ¹þ£¬¾ÍÊÇ¡°IPµØÖ·+¶Ë¿ÚºÅ¡±¡£

Control¡£Ö®ËùÒÔProxy£¬¾ÍÊÇΪÁËÄÜControl£¬»òÕß˵ΪÁËÖÇÄÜ£ºÖÇÄܱ£»¤£¬ÖÇÄܾܾø£¬ÖÇÄÜ»ØÊÕ£¬ÖÇÄܽµµÍ¿ªÏú¡£

ÔÚCOMÖУ¬ÓÐÖÇÄÜÖ¸ÕëSmartPointer¡£.NetÖеÄSmartClient˵²»¶¨Ò²ÊÇ¡£¡£¡£

----------------------------------Facade----------------------------

¡ñTip 1£º¹Ø¼ü×Ö¡£Subsystem£¬Higher-level Interface¡£

¡ñTip 2£ºÍ¼¡£


¿ÉÒÔ¿´µ½£¬Facade·â×°Á˶à¸öClass¡£

¡ñTip 3£ºÊµÏÖºÍʹÓá£

ÔÚFacade ClassÉÏ»¹¿ÉÒÔ×öЩÎÄÕ£¬ÒÔ½øÒ»²½½µµÍñîºÏ¶È£¬±ÈÈçFacade±¾Éí¿ÉÒÔÅÉÉúSubclass£¬»òÕßÓÃίÍÐ(delegate)À´ÅäÖÃFacade¡£The coupling between clients and the subsystem can be reduced even further by making Facade an abstract class with concrete subclasses for different implementations of a subsystem. Then clients can communicate with the subsystem through the interface of the abstract Facade class. This abstract coupling keeps clients from knowing which implementation of a subsystem is used. An alternative to subclassing is to configure a Facade object with different subsystem objects. To customize the facade, simply replace one or more of its subsystem objects.

ʹÓÃÃû×ֿռ䡣A class encapsulates state and operations, while a subsystem encapsulates classes. The C++ standardization committee added name spaces to the language [], which will let you expose just the public subsystem classes.

ÔÚET++ÖУ¬Óиö³ÆÎªbrowsing toolsµÄSubsystem£¬ÆäÖеÄProgrammingEnvironment¾ÍÊÇFacade¡£ET++ÖеÄÏà¹ØÑо¿£¬Çë²Î¿¼±¾Õ¾(lcspace.nease.net)µÄFrameworkÀ¸Ä¿¡£

¡ñTip 4£ºÖ§³Ö±ä»¯¡£Lets you vary the components of the subsystem without affecting its clients¡£

----------------------------------Proxy and Decorator----------------------------

¡ñTip 1£ºProxyÊÇDecoratorÌØÀý¡£

µ±Ò»¸öDecoratorģʽ£¬Decorator²»ÄܵݹéÐÞÊÎDecorator£¬¶øÇÒÒ²²»Òªbefore forwardingºÍafter forwardingµÄ²Ù×÷ÁË£¬½ö½ö¾ÍÊÇforward£¬DecoratorģʽҲ¾ÍÍË»¯³ÉProxyģʽÁË¡£

----------------------------------Adapter£¬Bridge£¬Facade and Proxy----------------------------

Adapter£¬Bridge£¬Facade and ProxyÕâ4ÖÖģʽ£¬Æäʵ¶¼¿ÉÒÔ¹éΪ¡°Layer-likeģʽ¡±¡£ÏëÏë¿´£¬ËüÃÇȷʵ¶¼ÊÇ¡°Layer¼äµ¥Ïòµ÷Ó÷þÎñ¡±µÄ¡£

µ±È»£¬´ÓÂß¼­ÉÏÀ´½²£¬Õâ4¸öģʽÓÖ·ÖΪ2×飺

Bridge and Facade©¤©¤Éæ¼°Âß¼­²ã´Î¡°²»Í¬¡±µÄ2¸öLayer¡£

Adapter and Proxy©¤©¤Éæ¼°Âß¼­²ã´Î¡°Ïàͬ¡±µÄ2¸öLayer¡£

ÏÂÃæÊǵäÐ͵ÄLayer-likeģʽµÄʾÒâͼ£º

¹Ø±Õ±¾Ò³
 
Ê×Ò³ | Ͷ×ÊÓëºÏ×÷ | ·þÎñÌõ¿î | Òþ˽Õþ²ß | Êղر¾Õ¾ | ÉèΪÊ×Ò³ | ÐÂÓû§×¢²á | ÃâÔðÉùÃ÷ | ʹÓðïÖú
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com °æÈ¨ËùÓÐ