通过开源项目SHARPDEVELOP项目的核心框架的学习分析说明基础管理框架的抽象设计。
先把这几天面向接口编程的学习小结一下,C#语言关于接口编成的内容:
1、接口允许多继承,类只能继承与一个基类,但是可以从一个基类、多个接口派生;
2、接口只是定义说明,并不具体实现,提供组件/模块之间的交互规范。
3、接口描述一个系统中相对稳定部分的结构,是系统的最高层抽象。
抛开菜单管理器具体的菜单项、工具条的功能按钮、面板内具体的内容、视图的具体内容,将所有具体
GUI内容的操作抽象成为一组抽象的内容接口(contentinterfaces),试图通过接口来定义基础管理框架管
理界面的GUI高层抽象。
每个视图或者面板包含的内容可能拥有的一组接口:
1,ICanBeDirty
     定义视图内容的变化标志IsDirty,和变化事件DirtyChanged。在工作台管理器的保存视图内容事件
中调用。
2,IClipboardHandler
     定义视图内容是否可以剪切、复制、粘贴、删除、全选状态剪切、复制、粘贴、删除、全选方法。
在文本编辑器的实现中会大量被调用。
3,IContextHelpProvider
     定义对内容提供帮助的方法。在按“F1”键时,会调用。
5,IMementoCapable
     定义创建新GUI对象记忆和恢复GUI对象记忆方法。
6,IPrintable
     定义打印文档属性,打印设置,打印调用方法。
7,IUndoHandler
     定义是否可以继续Undo,是否可以继续Redo属性,和Undo,Redo方法。
8,IViewContentMemento
     定义创建新视图内容对象记忆和恢复视图内容对象记忆方法。
 
下面介绍框架核心“视图”的理解:
在windows标准窗体中,视图是的工作是用来做具体事情,视图是可以作为一个文件进行保存,如果打开
多个 视图,那么在关闭工作台窗体之前,需要通知非活动的视图保存,而每个视图是否需要保存则由是
否修改标识来记录。
因此,视图接口在GUI的抽象是这样来定义的 :
1,IViewContent 继承IBaseViewContent,ICanBeDirty
 /// <summary>
  /// <summary> /// IViewContent is the base interface for all editable data
    /// IViewContent is the base interface for all editable data /// inside SharpDevelop.
    /// inside SharpDevelop. /// </summary>
    /// </summary> public interface IViewContent : IBaseViewContent, ICanBeDirty
    public interface IViewContent : IBaseViewContent, ICanBeDirty {
    { /// <summary>
        /// <summary> /// A generic name for the file, when it does have no file name
        /// A generic name for the file, when it does have no file name /// (e.g. newly created files)
        /// (e.g. newly created files) ///新建文件的默认名称
        ///新建文件的默认名称 /// </summary>
        /// </summary> string UntitledName
        string UntitledName {
        { get;
            get; set;
            set; }
        }
 /// <summary>
        /// <summary> /// This is the whole name of the content, e.g. the file name or
        /// This is the whole name of the content, e.g. the file name or /// the url depending on the type of the content.
        /// the url depending on the type of the content. ///文件名
        ///文件名 /// </summary>
        /// </summary> /// <returns>
        /// <returns> /// Title Name, if not set it returns UntitledName
        /// Title Name, if not set it returns UntitledName ///如果没有文件名,则返回默认文件名
        ///如果没有文件名,则返回默认文件名 /// </returns>
        /// </returns> string TitleName
        string TitleName {
        { get;
            get; set;
            set; }
        }
 /// <summary>
        /// <summary> /// Returns the file name (if any) assigned to this view.
        /// Returns the file name (if any) assigned to this view. /// </summary>
        /// </summary> string FileName
        string FileName {
        { get;
            get; set;
            set; }
        }
 /// <summary>
        /// <summary> /// If this property returns true the view is untitled.
        /// If this property returns true the view is untitled. /// </summary>
        /// </summary> /// <returns>
        /// <returns> /// True, if TitleName not set.
        /// True, if TitleName not set. /// </returns>
        /// </returns> //是否已经命名标题
        //是否已经命名标题 bool IsUntitled
        bool IsUntitled {
        { get;
            get; }
        }
 /// <summary>
        /// <summary> /// If this property returns true the content could not be altered.
        /// If this property returns true the content could not be altered. /// </summary>
        /// </summary> //是否视图修改
        //是否视图修改 bool IsReadOnly
        bool IsReadOnly {
        { get;
            get; }
        }
 /// <summary>
        /// <summary> /// If this property returns true the content can't be written.
        /// If this property returns true the content can't be written. /// </summary>
        /// </summary> 
          bool IsViewOnly
        bool IsViewOnly {
        { get;
            get; }
        }
 /// <summary>
        /// <summary> /// Gets the list of secondary view contents attached to this view content.
        /// Gets the list of secondary view contents attached to this view content. /// </summary>
        /// </summary> List<ISecondaryViewContent> SecondaryViewContents
        List<ISecondaryViewContent> SecondaryViewContents {
        { get;
            get; }
        }
 /// <summary>
        /// <summary> /// Saves this content to the last load/save location.
        /// Saves this content to the last load/save location. /// </summary>
        /// </summary> void Save();
        void Save();
 /// <summary>
        /// <summary> /// Saves the content to the location <code>fileName</code>
        /// Saves the content to the location <code>fileName</code> /// </summary>
        /// </summary> void Save(string fileName);
        void Save(string fileName);
 /// <summary>
        /// <summary> /// Loads the content from the location <code>fileName</code>
        /// Loads the content from the location <code>fileName</code> /// </summary>
        /// </summary> void Load(string fileName);
        void Load(string fileName);
 /// <summary>
        /// <summary> /// Is called each time the name for the content has changed.
        /// Is called each time the name for the content has changed. /// </summary>
        /// </summary> event EventHandler TitleNameChanged;
        event EventHandler TitleNameChanged;
 event EventHandler Saving;
        event EventHandler Saving; event EventHandler Saved;
        event EventHandler Saved; }
    }
2、IBaseViewContent
 
 public interface IBaseViewContent
  public interface IBaseViewContent2
 {
    {3
 /// <summary>
        /// <summary>4
 /// 返回视图包含的控件
        /// 返回视图包含的控件5
 /// </summary>
 /// </summary>6
 Control Control
        Control Control7
 {
        {8
 get;
            get;9
 }
        }10

11
 /// <summary>
        /// <summary>12
 /// 获取、设置工作台窗体接口
        /// 获取、设置工作台窗体接口13
 /// </summary>
        /// </summary>14
 IWorkbenchWindow WorkbenchWindow
        IWorkbenchWindow WorkbenchWindow15
 {
        {16
 get;
            get;17
 set;
            set;18
 }
        }19

20
 /// <summary>
        /// <summary>21
 /// 当一个或多个视图内容附着在单窗体window
        /// 当一个或多个视图内容附着在单窗体window22
 /// 程序时,获取tab页的标题,
        /// 程序时,获取tab页的标题,23
 /// </summary>
        /// </summary>24
 string TabPageText
        string TabPageText25
 {
        {26
 get;
            get;27
 }
        }28

29
 /// <summary>
        /// <summary>30
 /// 当视图在windows内切换时触发
        /// 当视图在windows内切换时触发31
 /// -> 发生在tab控件内(在选中事件前触发)
        /// -> 发生在tab控件内(在选中事件前触发)32
 /// -> 发生在工作台内.
        /// -> 发生在工作台内.33
 /// </summary>
        /// </summary>34
 void SwitchedTo();
        void SwitchedTo();35

36
 /// <summary>
        /// <summary>37
 /// 当tab分页被选中时触发,
        /// 当tab分页被选中时触发,38
 /// 不是windows窗体选中时触发
        /// 不是windows窗体选中时触发39
 /// </summary>
        /// </summary>40
 void Selected();
        void Selected();41

42
 /// <summary>
        /// <summary>43
 /// Is called just before the view content is deselected inside the window
        /// Is called just before the view content is deselected inside the window44
 /// tab before the other window is selected. NOT when the windows is deselected.
        /// tab before the other window is selected. NOT when the windows is deselected.45
 /// </summary>
        /// </summary>46
 void Deselecting();
        void Deselecting();47

48
 /// <summary>
        /// <summary>49
 /// Is called when the view content is deselected inside the window
        /// Is called when the view content is deselected inside the window50
 /// tab before the other window is selected. NOT when the windows is deselected.
        /// tab before the other window is selected. NOT when the windows is deselected.51
 /// </summary>
        /// </summary>52
 void Deselected();
        void Deselected();53

54
 /// <summary>
        /// <summary>55
 /// 重新初始化视图
        /// 重新初始化视图56
 /// 重新初始化视图包含的内容
        /// 重新初始化视图包含的内容57
 /// </summary>
        /// </summary>58
 void RedrawContent();
        void RedrawContent();59
 }
    }3、ICanBeDirty
 /// <summary>
      /// <summary>2
 /// Interface for classes that implement the IsDirty property and the DirtyChanged event.
        /// Interface for classes that implement the IsDirty property and the DirtyChanged event.3
 /// 定义类的修改属性,修改变化事件接口
        /// 定义类的修改属性,修改变化事件接口4
 /// </summary>
        /// </summary>5
 public interface ICanBeDirty
        public interface ICanBeDirty6
 {
        {7
 /// <summary>
            /// <summary>8
 /// If this property returns true the content has changed since
            /// If this property returns true the content has changed since9
 /// the last load/save operation.
            /// the last load/save operation.10
 /// 当视图内容改变时,返回true
            /// 当视图内容改变时,返回true11
 /// </summary>
            /// </summary>12
 bool IsDirty
            bool IsDirty13
 {
            {14
 get;
                get;15
 set;
                set;16
 }
            }17

18
 /// <summary>
            /// <summary>19
 /// Is called when the content is changed after a save/load operation
            /// Is called when the content is changed after a save/load operation20
 /// and this signals that changes could be saved.
            /// and this signals that changes could be saved.21
 /// </summary>
            /// </summary>22
 event EventHandler DirtyChanged;
            event EventHandler DirtyChanged;23
 }
        }
4,ISecondaryViewContent
 /// <summary>
   /// <summary> /// The base interface for secondary view contents
    /// The base interface for secondary view contents /// (designer, doc viewer etc.)
    /// (designer, doc viewer etc.) /// </summary>
    /// </summary> public interface ISecondaryViewContent : IBaseViewContent
    public interface ISecondaryViewContent : IBaseViewContent {
    { /// <summary>
        /// <summary> /// Is called before the save operation of the main IViewContent
        /// Is called before the save operation of the main IViewContent /// 在保存主视图内容之前触发
        /// 在保存主视图内容之前触发 /// </summary>
        /// </summary> void NotifyBeforeSave();
        void NotifyBeforeSave();
 //在保存主视图内容成功之后触发,参数:是否保存成功
        //在保存主视图内容成功之后触发,参数:是否保存成功 void NotifyAfterSave(bool successful);
        void NotifyAfterSave(bool successful); }
    }
请园子里的各位大哥,给小弟一些指点。我这样理解
 
 
 
                    
                 


 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号