Developing Application Frameworks in .Net ---- (Note1, Landscape)

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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值