跳到主要內容

[筆記] Head First Design Patterns

Chapter 1 Welcome to Design Patterns: an introduction

OO Basics:
  • Abstraction
  • Encapsulation
  • Polymorphism
  • Inheritance
OO Principles:
  • Encapsulate what varies.
  • Favor composition over inheritence.
  • Program to interfaces, not implementations.
OO Patterns:
  • Strategy - defined a family of algorithms, encapsulates each once, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Chapter 2 Keeping your Objects in the know: the Observer Pattern

OO Principles:
  • Strive for loosely coupled designs between objects that interact.
OO Patterns:
  • Observer - defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.

Chapter 3 Decorating Objects: the Decorator Pattern

OO Principles:
  • Classes should be open for extension but closed for modification.
OO Patterns:
  • Decorator - Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

Chapter 4 Baking with OO Goodness: the factory Pattern

OO Principles:
  • Depend on abstractions. Do not depend on concrete classes.
OO Patterns:
  • Abstract Factory - Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
  • Factory Method - Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to the subclasses.

Chapter 5 One of a Kind Objects: the Singleton Pattern

OO Patterns:
  • Singleton - Ensure a class only has one instance and provide a global point of access to it.

Chapter 6 Encapsulating Invocation: the Command Pattern

OO Patterns:
  • Command - Encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.
When you need to decouple an object making requests from the objects that know how to perform the requests, use the Command Pattern.

Chapter 7 Being Adaptive: the Adapter and Facade Patterns

OO Principles:
  • Only talk to your fiends
OO Patterns:
  • Adapter - Converts the interface of a class into another interface clients expect. Lets classes work together that couldn't otherwise because of incompatible interfaces.
  • Facade - Provides a unified interface to a set of interfaces in a subsystem. Facade defined a higher-level interface that makes the subsystem easier to use.

Chapter 8 Encapsulating Alogrithms: the Template Method Pattern

OO Principles:
  • Don't call us, we'll call you.
OO Patterns:
  • Template Method - Defined the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

Chapter 9 Well-Managed Collections: the Iterator and Composite Patterns

OO Patterns:
  • Iterator - Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
  • Composite - Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

Chapter 10 The State of Things: the State Pattern

OO Pattern:
  • State - Allows an object to alter its behavior when its internal state changes. The object will appear to change it class.

Chapter 11 Controlling Object Access: the Proxy Pattern

OO Pattern:

  • Proxy - Provide a surrogate or placeholder for another object to control access to it.

Chapter 12 Patterns of Patterns: Compound Patterns

OO Pattern:

  • Compound Patterns - A Compound Pattern combines two or more patterns into a solution that solves a recurring or general problem.

Chapter 13 Patterns in the Real World: Better Living with Patterns


Chapter 14 Appendix: Leftover Patterns

OO Patterns:
  • Bridge - Use the Bridge Pattern to vary not only your implementations, but also your abstractions.
  • Builder - Use the Builder Pattern to encapsulate the construction of a product and allow it to be constructed in steps.
  • Chain of Responsibility - Use the Chain of Responsibility Pattern when you want to give more than one object a chance to handle a request.
  • Flyweight - Use the Flyweight Pattern when one instance of a class can be used to provide many "virtual instances."
  • Interpreter - Use the Interpreter Pattern to build an interpreter for a language.
  • Mediator - Use the Mediator Pattern to centralize complex communications and control between related objects.
  • Memento - Use the Memento Pattern when you need to be able to return an object to one of its previous states; for instance, if your use requests an "undo."
  • Prototype - Use the Prototype Pattern when creating an instance of a given class is either expensive or complicated.
  • Visitor - Use the Visitor Pattern when you want to add capabilities to a composite of objects and encapsulation is not important.

留言

這個網誌中的熱門文章

用 C# 批次控制 Word 合併列印

前由 我有全區的電話資料,問題在於我要依不同里別來製作出電話簿。結果如下圖: 單純採用合併列印無法達成我的需求。解決方法係用「功能變數」儲存上一個里別,與現在里別進行比較:若不同,則換頁。不過,這樣功能變數還蠻長的。最後,我還是採用 C# 來解決。 解決方案 用 C# 控制 WORD 中合併列印的「資料來源 Data Source」,給予不同里別的「sqlstatement」。迴圈處理不同的里別即可。但可預見其處理過程會很慢,不過還好,我可以不用在意它,有跑出結果即可。 程式碼 IList<string> areas = new List<string>() { "後壁", "侯伯", "嘉苳", "土溝", "嘉田", "嘉民", "菁豊", "崁頂", "後廍", "墨林", "菁寮", "新嘉", "頂長", "平安", "仕安", "竹新", "新東", "長安", "頂安", "福安", "烏樹" }; string root = @"D:\"; // 根目錄 string data = root + @"\data.docm"; // 資料檔(即資料來源) string template = root + @"\template.docx"; // 已設定好格式與合併欄位的 Word 檔 string output = @"d:\Final"; // 輸出之資料夾 object oMissing = System.Reflection.Missing.Va...

VLC c# 順利編譯

原文網址: http://www.cnblogs.com/haibindev/archive/2011/12/21/2296173.html 原文作者: haibindev 原文標題:c#万能视频播放器 本文的重點在於修正 class VlcPlayer,使其能順利在 VC# Express 2010 .Net Framework 4 下順利編譯。 修正重點在於 CallingConvention = CallingConvention. StdCall 改成 CallingConvention = CallingConvention. Cdecl using System; using System.Runtime.InteropServices; using System.Security; using System.Text; namespace VlcDotNet { class VlcPlayer { private IntPtr libvlc_instance_; private IntPtr libvlc_media_player_; private double duration_; public VlcPlayer(string pluginPath) { string plugin_arg = "--plugin-path=" + pluginPath; string[] arguments = { "-I", "dummy", "--ignore-config", "--no-video-title", plugin_arg }; libvlc_instance_ = LibVlcAPI.libvlc_new(arguments); libvlc_media_player_ = LibVlcAPI.libvlc_media_player_new(libvlc_instance_); } public ...

[轉貼]MySQL 交易功能 Transaction 整理 (XYZ的筆記本)

全文轉貼自: http://xyz.cinc.biz/2013/05/mysql-transaction.html   (XYZ的筆記本) ---------------------------------------------------------------------------------------------------------- 資料庫的交易(Transaction)功能,能確保多個 SQL 指令,全部執行成功,或全部不執行,不會因為一些意外狀況,而只執行一部份指令,造成資料異常。 MySQL 常用的兩個資料表類型:MyISAM、InnoDB, MyISAM  不支援交易功能,所以以下的整理,均是針對 InnoDB  而言。 交易功能4個特性 (ACID)  Atomicity (原子性、不可分割):交易內的 SQL 指令,不管在任何情況,都只能是全部執行完成,或全部不執行。若是發生無法全部執行完成的狀況,則會回滾(rollback)到完全沒執行時的狀態。 Consistency (一致性):交易完成後,必須維持資料的完整性。所有資料必須符合預設的驗證規則、外鍵限制...等。 Isolation (隔離性):多個交易可以獨立、同時執行,不會互相干擾。這一點跟後面會提到的「隔離層級」有關。 Durability (持久性):交易完成後,異動結果須完整的保留。 開始進入交易模式 SQL 指令: START TRANSACTION  或  BEGIN 結束交易模式 交易完成:使用  COMMIT  儲存所有變動,並結束交易。 交易過程異常:使用  ROLLBACK  回滾,取消交易,還原到未進行交易的狀態。(若交易過程連線中斷,沒 COMMIT 提交的變更,亦會如同執行 ROLLBACK 取消交易) 儲存點 (SAVEPOINT) 交易過程中,可標示多個不同的儲存點,有需要時可 ROLLBACK 到某個儲存點。 建立儲存點: SAVEPOINT 名稱 刪除儲存點: RELEASE SAVEPOINT 名稱 ROLLBACK 到某個儲存點: ROLLBACK TO SAVEPOINT 名稱 如...