Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7741401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:01:07+00:00 2026-06-01T09:01:07+00:00

I have a data model object User . My app also has some other

  • 0

I have a data model object User. My app also has some other data model objects, Fork and Options, for example. Users have forks and branches. My app has to run a lot of queries with some combination of User/Fork/Options etc. information. For example, you can see a page of User’s Forks. This would require a query that joins that User (e.g. the logged in user in the session) on Forks.

I don’t want to violate the Law of Demeter, and I am also typically against getters (and setters) in general, so I don’t want to implement User::getID() or User::getUsername().

However, the alternative does not seem much better to me. What has ended up happening is that I implement various methods in User to run these queries (e.g. User::getForks()). In general this works, but the User class has become monolithic which is bad in its own way.

What’s more is I’m not sure how I would resolve a query of two data model objects. For example, I could have a User with an id and a Fork with an id and want to check that the fork belongs to the user. This requires that either the Fork exposes its id to the user, the User exposes its id to the Fork, or both expose their ids to the controller (or whatever else). None of these seem desirable, and I’m not sure which to choose. Is there some other alternative that I’m missing?

In another similar step, I’m not sure of the best way to add information to the view. I have a view object, and typically I use a method like User::addForksToView(View $view), which will run a query or queries and do some processing, but this also increases the size and responsibility of User. I think this is a similar problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:01:08+00:00Added an answer on June 1, 2026 at 9:01 am

    Rather than a getForks method in the User object, use a ForksFactory or something like it. The factory can have methods like fromUser(User $user) and byId($id). That way the User object does not have a hidden dependency upon the Fork object, and probably a hidden dependency on database access. The ForksFactory has a dependency on database and contains the code needed only to get the data and create Forks, that’s all it knows how to do. Where as the Fork object would not have a dependancy on the database, and now the User object doesn’t need to know anything about Fork, indeed Fork could not exist at all and the User doesn’t care. This is the idea of a single-purpose object.

    As far as getters and setters, why not expose properties like id and name as public? Alternately, you can use the magic methods __get and __set to control which properties are treated as read-only, if that is your concern. Otherwise, you may as well expose the properties — that is perfectly acceptable.

    The other code you mention sounds like it suffers from the same problem — one object, one purpose. Every object should, in theory, stand in isolation or have any dependencies injected in the constructor. Your objects should not require that another object is defined or one of its methods will fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly involved managed data model which has a central object with
In my Core Data managed object model, I have an entity Foo with a
I have a model which gets its data from a parser object. I'm thinking
In my data model I have a fairly common division between my objects/tables/data: Transactional
I have set up a Core Data model where I have two objects, say
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
Im using a Core Data model for my iPhone app. I have been looking
I have seen a slick method for upgrading user data from one iOS app
I am building an iPhone app that has some default data inside it via
I have a rails app that is tracking social data. The users are going

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.