???????????????????????????????????????????????????????????????÷????????????????????????
???????????????????л??????????????????????????з????????????????????????????????????????????????

 

//???Spring??HibernateTemplate???????????
interface CallBack{
public void doCRUD();
}
public class HibernateTemplate {
public void execute(CallBack action){
getConnection();
action.doCRUD();
releaseConnection();
}
public void add(){
execute(new CallBack(){
public void doCRUD(){
System.out.println("???add????...");
}
});
}
public void getConnection(){
System.out.println("???????...");
}
public void releaseConnection(){
System.out.println("???????...");
}
}

??????????????????????????????????????????????????A?????????????????????????????????????????????????????£?

 

interface CallBack{   //??????InA
public void doCRUD();
}
public class A implements CallBack{//??????1??
private B b;//??????2??
public void doCRUD(){
System.out.println("???add????...");
}
public void add(){
b.execute(new A());//??you call me??
}
}
public class B{
public void execute(CallBack action){  //??????3??
getConnection();
action.doCRUD();  //??i call you back??
releaseConnection();
}
public void getConnection(){
System.out.println("???????...");
}
public void releaseConnection(){
System.out.println("???????...");
}
}

??????????????????????????????????????????????÷??????塣
??????????????????????????????????getConnection();??????????A?????B???????????????????????????????A?????????ν??i call you back??????????????????????
???????????????????????????ú??????????????£?
?????????????????????????????綽????????????????????????????????????Щ??????????????????綽???????????????綽??????????????????????綽?????????????????????????????????????
???????????????????????綽?????????you call me?????????????????綽???????i call you back????
??????????????????????
????---------------------------------?????????----------------------------------
??????????Щ?????????????????????£??о??????????????????????????
????????????????????????????£?????д?????????????л??
?????????????δ???????????????????????????????

 

public abstract class B{
public void execute(){
getConnection();
doCRUD();
releaseConnection();
}
public abstract void doCRUD();
public void getConnection(){
System.out.println("???????...");
}
public void releaseConnection(){
System.out.println("???????...");
}
}
public class A extends B{
public void doCRUD(){
System.out.println("???add????...");
}
public void add(){
doCRUD();
}
}
public class C extends B{
public void doCRUD(){
System.out.println("???delete????...");
}
public void delete(){
doCRUD();
}
}
?????????????????????
interface CallBack{
public void doCRUD();
}
public class HibernateTemplate {
public void execute(CallBack action){
getConnection();
action.doCRUD();
releaseConnection();
}
public void add(){
execute(new CallBack(){
public void doCRUD(){
System.out.println("???add????...");
}
});
}
public void delete(){
execute(new CallBack(){
public void doCRUD(){
System.out.println("???delete????...");
}
});
}
public void getConnection(){
System.out.println("???????...");
}
public void releaseConnection(){
System.out.println("???????...");
}
}

??????????????г????????????????????????????????????????????г?????????????????????????????????????????????????????????????????