Point of view in the object model

We have two types of domain: users and locations.

We have a LocationRepository: GetUserLocations () method.

Existing implementation:

var user = UserRepository.GetUser(userId);
var locations = LocationRepository.GetUserLocations(userId);

For me, it makes sense to retrieve the locations associated with the user from the user type ie:

var user = UserRepository.GetUser(userId);
var locations = user.GetLocations();

I think the last implementation is read more cleanly and, as an API client, I have to deal with fewer types (i.e. LocationRepository is not required). On the other hand, there will be more code to support as I need to write a “facade” in the LocationRepository.

Should I work on my instinct and create a facade in the User type in the LocationRepository, or should I be satisfied with the status quo and live with a sequence diagram that "feels" me wrong (for example, finding location information feels that it is being extracted from the wrong "points of view" )?

+3
source share
2 answers

I would come closer to this in terms of maintainability. I agree that doing this using the facade on the LocationRepository “feels good” and is likely to make the code more readable.

, , . ? , ? , ? , , , . , , .

+1

, :

Universe.Instance.Galaxies["Milky Way"].SolarSystems["Sol"]
        .Planets["Earth"].Inhabitants.OfType<Human>().WorkingFor["Initech, USA"]
        .OfType<User>().CreateNew("John Doe");

, " " .

, Universe.Instance, " ", - .

UPDATE:

, , , " " , , , , "Bing Bang" " ;-)... , , , , , .....

, , - , :

LocationRepository.Instance.GetUserLocations(userId);

... User , :

var locations = myUser.Locations;

LocationRepository , . , , , . , LocationRepository.GetUserLocation(userId) . , .

. Silverlight et al , . , / , .

, , , , , UserRepository, , -, User , () . , myUser.Locations, myLocations.ByUser["John Doe"] . UserRepository , , , CompanyStaff. .; -)

+1

Source: https://habr.com/ru/post/1729480/


All Articles