According to this article here
You can think of them [Services] as "higher level Domain Objects", but instead of business logic, Services are responsible for interaction between Domain Objects and Mappers. These structures end up creating a "public" interface for interacting with the domain business logic. You can avoid them, but at the penalty of leaking some domain logic into Controllers.
I have been reading up on MVC, and ive split the M part into Services, Domain Objects and Data Mappers. Services and Data Mappers are easy to figure out, but I dont understand the reason for domain objects, can you please give me some examples? Here is my code:
MemberService
class MemberService extends Service
{
public function authenticate()
{
$domainObject = $this->domainObjectFactory->getDomainObject('Member');
$dataMapper = $this->databaseFactory->getMapper('Member');
$_temp_sess_id = 0;
$_temp_sess_password = "";
$member = $dataMapper->fetch( $_temp_sess_id );
$authenticationResult = $domainObject->checkPassword( $member['password'], $_temp_sess_password );
if (!$authenticationResult)
{
$member = ['user_id' => 0];
}
return $member;
}
}
MemberDomainObject
class MemberDomainObject extends DomainObject
{
public function checkPassword( $dataMapperPassword, $locallyStoredPassword )
{
if ( $dataMapperPassword !== $locallyStoredPassword )
return false;
return true;
}
}
UPDATE:
This question is regarding the method checkPassword and why its necessary to create a separate object just to use an IF statement that could be used inside the service instead, saving RAM from using additional resources for creating a new object.