title: Can I define a class with no public constructor and place a factory method for this class objects in a different class in Scala?
body: <p>For example (maybe a bit clumsy from a real life view, but just to illustrate):</p>
  
  <p>"User" is a <s>case</s> class containing user name and id. Id can be never set manually, and a User class instance with no id set has no sense.</p>
  
  <p>A UserBase class maintains users base and has a "getUser (name : String) : User" method returning a consistent User instance.</p>
  
  <p>No one other than a UserBase object can know (well, someone can, but really shouldn't rely on this knowledge) a user's id, so constructing a User instance manually makes no sense (and can cause errors in future if someone accidentally hardcodes this and forgets). Moreover, having an orphan User instance not tracked by a UserBase is also undesired.</p>
  
  <p>So the task is to make calling UserBase.getUser the only way to get a User instance.</p>
  
  <p>Can this be implemented in Scala?</p>