Ten most commonly used design patterns

1. The Facade Pattern
   Provide a unified interface to a set of interfaces in a subsystem. It defines a higher-level interface that makes the subsystem easier to use.

   Only works when:
   1.use a subset of the system's capabilities
   2.interact with it in a particular way

   Variations:
   1.reduce the number of objects a client must work with
   2.provide new functions
   3.hide the system

2. The Adapter Pattern
   Convert the interface of a class into another interface that the clients expect.It lets classes work together that could not otherwise because of incompatible interfaces.

   When to use:
   Create a new interface for an object that does the right stuff but has the wrong interface.

   How to use:
   1.define the interface and then implement in derived classes
   2.the derived class contains the existing class which to be used but has wrong interface, then passes request made to it on through to that class
  
   It frees you from worrying about existing interfaces.

   Two types:
   1.Object Adapter pattern - it relies on one object containing another.
   2.Class Adapter pattern - implement useing multiple inheritance

   Difference: A Facade simplifies an interface while an Adapter converts the interface into a preexisting interface.

3. The Bridge Pattern
   De-couple an abstraction from its implementation so that the two can vary independently.
   -- This pattern is a bit hard to understand at first! But it is a challenging pattern to learn cause it is so powerful.
 
   *** implementation here means the objects that the abstract class and its derivations use to implement themselves with, not the derivations of the abstract class,which are called concrete classes.

   You cant always see the variations at the beginning of the problem.
   Bottom line: During requirements definition, explore for variations early and often!

   It is more useful to focus on the context of the pattern - the problem it is trying to solve.This lets you know when and why to use it.
   You can identify when to apply a pattern before knowing exactly how to implement it.
  
   The bridge pattern is useful when:
     You have an abstraction that has different implementations. It allows the abstraction and the implementation to vary independently of each other.

   Commonality/Variability analysis:
   Commonality - the search for common elements that helps us understand how family members are the same.Thus, the process of finding out how things are common defines the family in which these elements belong(where things vary).
                 It seeks structure that is unlikely to change over time.
   Variability - reveals how family members vary.It only makes sense within a given commonality.
                 It captures structure that is likely to change.

   It is suggested that using commonality/variability analysis as a primary tool in creating objects is a better approach than looking at just nouns and verbs.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值