禾青谷

Practice ,Imitate and Insistance makes perfect

用户操作
[即时聊天] [发私信] [加为好友]
CrystalHareHusID:CrystalHareHus
10613次访问,排名10514(-1)好友0人,关注者1
CrystalHareHus的文章
原创 19 篇
翻译 0 篇
转载 1 篇
评论 24 篇
最近评论
文章分类
收藏
    相册
    友情链接
    Computer Graphics Changes Your Life
    ljgame
    寒星轩
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 Developing Application Frameworks in .Net ---- (Note1, Landscape)收藏

    新一篇: English Practice ___ New Concept English 3(11-20) | 旧一篇: Code Complete ---- (Note 7 Code Improvements)

    1. modularity <模块化> --- reuseability ---- extensibility --- simplicity ---- maintainability

    2.  Operating system <windows, Linux> ---> Fundation Framework <.Net, Java> ---->Application Framework<Domain-Specific Framework ---->Cross-Domain Framework> ----> Business Application

    3.  Common Spots      Hot Spots<扩展点>    Black-box framework     White-box framework    Gray-box framework

    4.  Inheritance Approach
            ---- hook method , abstract method, hot spots, it is just a placeholder

            [Abstract class in C#]
        An abstract class cannot be instantiated, while an abstract function does not have an implementation, and must be overridden in any nonabstract derived class. Obviously, an abstract function is automatically virtual (although you don’t need
    to supply the virtual keyword; doing so results in a syntax error). If any class contains any abstract functions, then that class is also abstract and must be declared as such.

            Hook methods are called by template method.

            ---- template method
                [design pattern]
                Define 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.


                AbstractClass  { TemplateMethod() ; HookMethod1() ;  HookMethod2(); .....}    --- Base
                ConcreteClass {  <override> HookMethod1(); override HookMethod2(); ....   }    --- Derived

                Hook operation      ---- Maybe overriden, can afford default implementation, always are empty.
                Abstract operation  ---  Must be overriden
    public abstract class BasicBusiness{
        
    protected float income;

        
    // The template method
        public void ReportTax(){
            
    float sTax   = CalculateStateTax();
            
    float fTax    = CalculateFedTax();

            
    //  Some rules
            
    // .....
        }


        
    // Hook methods, abstract methods
        protected abstract float CalculateStateTax();
        
    protected abstract float CalculateFedTax();
    }


    public class NewYorkBusiness : BasicBusiness {
        
    protected override float CalculateStateTax() {
            
    return income * 0.1F;
        }


        
    protected override float CalculateFedTax() {
            
    return income * 0.2F;
        }

    }


    // To apply
    BasicBusiness nyBusiness = new NewYorkBusiness();
    nyBusiness.ReportTax();

    BasicBusiness caBusiness 
    = new CaliforniaBusiness();
    caBusiness.ReportTax();

    5. Compoistion Approach
        Inheritance approach need developer know well about the inner data and method of base class.

        Pluggable Component <可插入组件>
       
    public interface ICalculateTax {
        
    float CalculateStateTax();
        
    float CalculateFedTax();
        
    float Income {
            
    get;
            
    set;
        }

    }


    public class NewYokBusiness : ICalculateTax{
        
    private float income;
        
    public float Income {
            
    get return income;   }
            
    set { income = value; }
        }


        
    public float CalculateStateTax () {
            
    return income * 0.1F;
        }


        
    public float CalculateFedTax () {
            
    return income * 0.2F;
        }

    }


    public class BasicBusiness {
        
    public void ReportTax(ICalculateTax calculator) {
            
    float sTax = calculator.CalculateStateTax();
            
    float fTax =  calculator.CalculateFedTax();

            
    //
            
    //.....
        }

    }


    //  To apply
    // 为了让框架组件使用可插入对象,
    // 你要么使用显式创建然后作为参数传递的方法,
    // 要么把应用组件的类型信息(type information)保存到配置文件中,
    // 然后通过反射机制(reflection)创建适当组件,并动态插入到框架组件中。
    ICalculateTax nyBusiness = new NewYorkBusiness();
    ICalculateTax caBusiness 
    = new CaliforniaBusiness();

    BasicBusiness basic 
    = new BasicBusiness();
    basic.ReportTax(nyBusiness);
    basic.ReportTax(caBusiness);


        White-box Framework --- all abstract classes, and inheritance mechanism
        Black-box  Framework  ---  all concrete classes and composite mechanism
        Gray-box Framework --- White + Black (concrete class with virtual methods)

    发表于 @ 2007年01月08日 13:37:00|评论(loading...)|编辑

    新一篇: English Practice ___ New Concept English 3(11-20) | 旧一篇: Code Complete ---- (Note 7 Code Improvements)

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © CrystalHareHus