上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 43 下一页
摘要: 外观(Facade)提供了一个统一的接口,用来访问子系统中的一群接口。外观定义了一个高层接口,让子系统更容易使用。外观(Facade)并没有“封装”子系统的类,外观只提供简化的接口。所以客户如果觉得有必要,仍然可以直接使用子系统的类。这是外观模式一个很好的特征:提供简化的接口的同时,仍然将系统完整的功能暴力出来,以供需要的人好似用。外观模式也允许你将客户实现从任何子系统中解耦。比方说,你若够想要升级你的家庭影院,采用全新的和以前不一样接口的组件。如果当初你的客户代码是针对外观而不是子系统编写,现在你就不需要改变客户代码,只需要修改外观代码。适配器的意图是将接口转换成不同的接口,而外观的意图是, 阅读全文
posted @ 2013-12-15 22:25 feiling 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 策略模式的类图和状态模式是一样的,但两个模式的区别在于他们的“意图”以策略模式而言,客户通常主动制定Context所要组合的策略对象是哪一个。现在,固然策略模式让我们更有弹性,能够在运行时改变策略,但对于某个context对象来说,通常都只有一个最适当的策略对象。一般来说,我们把策略模式想成是除了继承之外的一种弹性方案。如果你使用继承定义了一个类的行为,你将被这个行为困住,甚至要修改它都很难。有了策略模式,你可以通过组合不同的对象来改变行为。而状态模式,通过将一群行为封装在状态对象中,context的行为随时可委托到那些状态对象中的一个。随着时间的流逝,当前状态在状态对象集合中游走改变,以反映 阅读全文
posted @ 2013-12-14 21:27 feiling 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 1.找出应用中可能需要变化之处,把他们独立出来,不要和那些不需要变化的代码混在一起2.针对接口编程,而不是针对实现编程3.多用组合,少用继承4.最少知识原则(Law of Demeter):只和你的密友谈话,减少对象之间的交互。(外观模式) 该原则提供了一些方针:就任何对象而言,在该对象的方法内,我们只应该调用属于以下范围的方法: a.该对象本身 b.被当做方法的参数而传递进来的对象 c.此方法所创建或实例化的任何对象 d.对象的任何组件5.好莱坞原则:别调用我们,我们会调用你(模板方法模式) 该原则运行底层组件将自己挂钩到系统上,但是高层组件会决定什么时候和怎样使用这些底层组件。... 阅读全文
posted @ 2013-12-14 11:36 feiling 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 状态模式允许对象在内部状态改变时改变他的行为,对象看起来好像修改了它的类1.将每个状态的行为局部化到它自己的类中2.将容易产生问题的if语句删除,以方便日后的维护3.让每一个状态“对修改关闭”,让Context“对扩展开放”,因为可以加入新的状态类 阅读全文
posted @ 2013-12-14 11:25 feiling 阅读(140) 评论(0) 推荐(0) 编辑
摘要: NAME pipe, pipe2 - create pipeSYNOPSIS #include int pipe(int pipefd[2]); #define _GNU_SOURCE /* See feature_test_macros(7) */ #include /* Obtain O_* constant definitions */ #include int pipe2(int pipefd[2], int flags);DESCRIPTION ... 阅读全文
posted @ 2013-11-30 11:45 feiling 阅读(348) 评论(0) 推荐(0) 编辑
摘要: NAME fork - create a child processSYNOPSIS #include pid_t fork(void);RETURN VALUE On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is returned in the parent, no child process is created, and errn... 阅读全文
posted @ 2013-11-30 11:11 feiling 阅读(460) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort. 1 public ListNode insertionSortList(ListNode head) { 2 // IMPORTANT: Please reset any member data you declared, as 3 // the same Solution instance will be reused for each test case. 4 if(head == null){ 5 return head; 6 ... 阅读全文
posted @ 2013-11-16 22:10 feiling 阅读(1266) 评论(0) 推荐(0) 编辑
摘要: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations:getandset.get(key)- Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.set(key, value)- Set or insert the value if the key is not 阅读全文
posted @ 2013-11-16 17:10 feiling 阅读(1525) 评论(0) 推荐(1) 编辑
摘要: Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].Note:Recursive solution is trivial, could you do it iteratively?[解题思路]后序遍历的非递归相对来说比较难,根节点需要在其左右孩子都访问结束后才能被访问,因此对于任一节点,先将其入栈,如果p不存在左孩子和右孩子,则可以直接访问它;或者p存在... 阅读全文
posted @ 2013-11-16 10:53 feiling 阅读(371) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked listL:L0→L1→…→Ln-1→Ln,reorder it to:L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it to{1,4,2,3}.[解题思路]将队列从中间断开,分成两个队列p1,p2,p2反转,然后将p1,p2进行合并 1 public class Solution { 2 public void reorderList(ListNo 阅读全文
posted @ 2013-11-15 22:39 feiling 阅读(605) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 43 下一页