I want to develop a process() method. The method takes some data in the form of a data class, and processes it. The data classes are similar, but slightly different.
For example we have the following classes of data processDataObject_A, processDataObject_B and processDataObject_C.
Is it better to overload the method:
void process(processDataObject_A data) { //Process processDataObject_A here } void process(processDataObject_B data) { //Process processDataObject_B here } void process(processDataObject_C data) { //Process processDataObject_C here }
OR have the concrete data classes extend some Abstract Data Class, and pass that to the process method and then have the method check the type and act accordingly:
void process(AbstractProcessDataObject data) { //Check for type here and do something }
OR is there some better way to address it? Would the approach change if this were to be a Web Method?
Thanks in advance
I would go with: