Home > Back-end >  Function encapsulation
Function encapsulation

Time:12-10

Note: the function function in each case are the same (vo object into entity object, according to the primary key to delete, and then insert the data), but at different operating table
q: this case how to package?


Packaging like this:
The switch (param) {
Case: XXX func (param1, param2); break;
Case yyy: func (param3 param4); break;
}

Please, answer!!!!!

CodePudding user response:

Small Java
refer to the original poster people reply:
note: the function function in each case are the same (vo object into entity object, according to the primary key to delete, and then insert the data), but at different operating table
q: this case how to package?


Packaging like this:
The switch (param) {
Case: XXX func (param1, param2); break;
Case yyy: func (param3 param4); break;
}

Please, answer!!!!!


The block write method, in the case to invoke this method directly,

CodePudding user response:

Their operation is a different table, just operating logic is the same, operation of the object is different, how to encapsulate?

CodePudding user response:

refer to the second floor small Java people reply:
their operation is a different table, just operating logic is the same, operation of the object is different, how to encapsulate?


The action object as a method of incoming parameters

CodePudding user response:

Parameter with the Object? Parameters after coming with the instance of one by one to determine what type? After a judge to operate?
Outside there is a switch inside to write their own functions and one by one to judge, the feeling is not so good

CodePudding user response:

Can put this a few objects associated with the table name and the object name in a map inside, inside the method with yao. Since you'll be encapsulating method, make a judgment before handed to participate in either way, either in judging method. Personally think inside the method to do better. Repeat this code can be reduced

CodePudding user response:

Case object transformations are different only in the two steps behind the same
 
Case "xx" : {
AsGx... AsGc=con... (vo);
DoSomething (asGc);
break;
}
Case "XXX" : {
AsGx... AsGc=con... (vo);
DoSomething (asGc);
break;
}
Case "XXXX" : {
AsGx... AsGc=con... (vo);
DoSomething (asGc);
break;
}

.

Public void doSomething (AsGc... AsGc) {
The delete... (asGc);
The result +=... Insert (asGc);
}

CodePudding user response:

4th floor small Java quoted response:
parameter with Object? Parameters after coming with the instance of one by one to determine what type? After a judge to operate?
Outside there is a switch inside to write their own functions and one by one to judge, the feeling is not so good


You want to encapsulate, before the transformation of the entity to generate generic interfaces, use interface to realize,
  • Related