???????Java???????
???????????? ???????[ 2014/7/11 10:49:33 ] ??????????????? java
???????????????????????????????????????????????????????????????÷????????????????????????
???????????????????л??????????????????????????з????????????????????????????????????????????????
//???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("???????...");
}
}
|
??????????????г????????????????????????????????????????????г?????????????????????????????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11