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
5. Compoistion Approach
Inheritance approach need developer know well about the inner data and method of base class.
Pluggable Component <可插入组件>
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)
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();
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);
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)