I have several classes that share common logic. For example, class AddEmployee is responsible for adding an employee to the api. AddLocation is responsible for adding location of a person. Classes are following :
class AddEmployee { public function Add() { $apiUrl = "https://api.abc.com/Employees";; $authParameters = array( 'oauth_consumer_key' => $this->CONSUMER_KEY, ); $xml .= <<<EOM <SuperFund> <ABN>$obj->abn</ABN> <Type>REGULATED</Type> </SuperFund> EOM; $queryParameters = array( 'xml' => $xml ); $response = $this->ProcesssRequestAndGetResponse('POST',$apiUrl,$authParameters,$queryParameters,$oauth_secret); return $response; } } class AddLocation { public function Add() { $apiUrl = "https://api.abc.com/Locations";; $authParameters = array( 'oauth_consumer_key' => $this->CONSUMER_KEY, ); $xml .= <<<EOM <Location> <Address1>$obj->abn</Address1> <City>Dhaka</Citry> </Location> EOM; $queryParameters = array( 'xml' => $xml ); $response = $this->ProcesssRequestAndGetResponse('POST',$apiUrl,$authParameters,$queryParameters,$oauth_secret); return $response; } } In the above two classes, only xml part is different and others are same. In future other new classes will be added where only xml will be different.
My question is how can I refactor to remove duplicate from each of the classes ?
Which design pattern to remove duplicate code ?