Professional C# Design Pattern Applied potx

62 1K 6
Professional C# Design Pattern Applied potx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... represents a subtlety of the SaF pattern that is crucial if the pattern is to work properly – namely, that the Load method will be an asynchronous method call without a return value Class Diagrams With some solid use case, activity, and sequence analysis in hand, Jack was ready to design the class structure It also helped that he had envisioned the appropriate design patterns! Based on all analysis... validating an order The Strategy pattern had effectively transferred the "hard work" to the coding of the validation algorithms And that did not surprise Jack, given the Strategy pattern' s intent – Define a family of algorithms, encapsulate each one, and make them interchangeable… 126 Design Patterns in the Middle Tier The Final Class Diagram Here's how the Decorator and Strategy patterns combine to produce... ProcessDocument class) was an academic exercise Likewise, writing the Decorator pattern' s decorator class (the Processes class) proved an equally easy task since it just implemented all of the Document's public methods The Strategy Pattern Classes Compared to creating the Decorator, designing the validation processes via the Strategy pattern was straightforward Jack jumped straight to writing the interface... use either the Adapter or Façade patterns to protect the innocent from a legacy application In our case, our application is using a Façade to "wrap" a dangerous and scary VB6 component! To highlight an extra source of ambiguity, we should note here that the GoF also listed the term "wrapper" as an alternative name for a Decorator design pattern 131 Chapter 3 The Façade pattern provides us with more than... price for Product Id = " + productId; throw new Exception(msg); } 136 Design Patterns in the Middle Tier if( result > 0 ) return true; else return false; } In the code above, our reinterpretation of m_Inventory.PriceCheck() now begins to look a little bit like an Adapter pattern! We are definitely entering the territory of a Façade pattern; but whenever code makes incompatible classes hospitable to another... straightforward exercise After creating a new C# class library project, called LegacyWrapper, within our VS.NET solution, we just reference the COM component and write a class that accesses it Pattern alert! We're creating a reference to another class with the sole intention of merely calling its methods This is the first step towards implementation of a Façade pattern, as we'll see in this section Here's... where Jack focused his class design energies Some readers may consider this miserly approach to class diagrams to be rather cavalier We could certainly diagram every class in NOP However, would all these additional artifacts make us any smarter? Probably not So why bother generating many near-worthless diagrams? The Decorator Pattern Classes To implement the Decorator pattern, Jack needed to identify... call to the default constructor method with a custom method entitled GetInstance() The explanation is quite simple – ReceiveDocument.Receive implements the Singleton design pattern 141 Chapter 3 As we described in Chapter 1, the Singleton pattern allows only one instance of the subject class to be created It accomplishes this by modifying its default constructor from Public to Private In addition, with... gets the ball rolling as far as the presentation tier is concerned However, it operates in a slightly unusual fashion Clients cannot instantiate it directly, because Receive is designed as a Singleton class If you're new to design patterns then this paradigm may strike you as strange; however, it provides the application with some significant advantages: ❑ 146 First, clients will not most likely have to... That method will return a reference to the instantiated singleton object Design Patterns in the Middle Tier This arrangement also absolves the caller from worries relating to instantiation issues The singleton itself figures out the complexities of instantiation, before returning a reference to it In other words, the Singleton pattern even abstracts away any creation woes from the caller And it does . Introduction to Design Patterns 9 Chapter 2: Design Patterns in the Data Tier 67 Chapter 3: Design Patterns in the Middle Tier 117 Chapter 4: Design Patterns. Tiers: Design Patterns and .NET Remoting 257 Chapter 6: What Next? 299 Appendix A: UML Primer 309 Index 339 Design Patterns in the Middle Tier Design patterns

Ngày đăng: 14/03/2014, 21:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan