Việc thực hiện thứ hai của giao diện cầu trong ví dụ này cũng sẽ xảy ra là một Proxy để SpaceBook. Hầu hết các cơ chế Proxy đã được tách ra, và tất cả còn lại là các hoạt động proxy thông minh giữ một số nối tiếp của người sử dụng. Dưới đây là OpenBook trong hình thức thô sơ nhất của nó: | The second implementation of the Bridge interface in this example also happens to be a Proxy to SpaceBook. Most of the Proxy mechanisms have been stripped out and all that remains is the smart proxy operation of keeping a serial count of users. Here is OpenBook in its most rudimentary form public class MyOpenBook Bridge Combination of a virtual and authentication proxy SpaceBook mySpaceBook string name static int users public MyOpenBook string n name n users mySpaceBook new SpaceBook name - users public void Add string message message public void Add string friend string message friend name said message public void Poke string who who name _ Note that the Bridge defines the operations that will be supported by all Portal members. Now suppose OpenBook wanted to add some cool operations like SuperPoke public void SuperPoke string who string what who what you SuperPoke is implemented rather crudely on top of Add as this is a SpaceBook-supported feature. If we put SuperPoke in OpenBook the compiler will accept it but we won t be able to call it because in the main program tom is a reference to a Portal object and SuperPoke is not in the Portal. We can solve this problem in two ways Add the new operation to the Portal Abstraction but not to the Bridge so it does not affect other implementations. If we cannot alter the Portal we can create an extension method to extend it as follows static class OpenBookExtensions public static void SuperPoke this Portal me string who string what who what you _ 42 Chapter 2 Structural Patterns Decorator Proxy and Bridge and call it the same way we call the other methods Judith-1 hugged Extension methods are one of the new features in C . C Feature Extension Methods Extension methods allow developers to add new methods to an existing type without having to create an inherited class or to recompile the original. Thus you can add methods to classes .