Support the ongoing development of Laravel.io →
posted 10 years ago
Architecture

You hear about "single reason to change" when it comes to the scope of a class and how big to make it. However, my client repository I feel contains client-only methods that doesn't make sense for me to put elsewhere. Should I be creating many classes/repositories for the sake of thin classes?

Is my interface too big? Thanks!

interface ClientRepositoryInterface {

	public function find($client_id);
	public function update($client_id, $data);
	public function setPreferredWalker($client_id, $preferred_walker_id);
	public function setCashClient ($client_id, $is_cash_client);
	public function isCashClient ($client_id);
	public function setServicesRequested($client_id, $servicesRequested, $serviceRates, $serviceRateAdds);
	public function makePayment($client_id, $amount, $date, $paymentMethod, $invoice=Null);
	public function getBalance($client_id);
	public function newClient($data, $servicesRequested, $serviceRates, $serviceRateAdds, $serviceTypes);
	public function getPets($client_id);
	public function getName($client_id);
	public function getAddress($client_id);
	public function getDogWalkerName($client_id);
	public function getContacts($client_id);
	public function hasServicesToInvoice ($client_id);
	public function getServicesToInvoice($client_id);
	public function getAmountToInvoice( $client_id );
}
Last updated 3 years ago.
0

You could create 3 separate interfaces, which a single repository could use.

Split things into logical groups:

  • Client
  • Pet
  • Invoice

Or create separate repositories, each with it's own interface.

0

Thanks Jay.

My only question then becomes, are model relationships unnecessary? For example, my getPets() method simply creates a Client model and then uses the defined relationship to get the pets with $client->pets.

I figured a getPets() method in a PetsRepoInterface would return all pets, not client specific.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

unohuim unohuim Joined 1 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.