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 8487799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:21:12+00:00 2026-06-10T21:21:12+00:00

I have a set of classes that manage db storage in a class hierarchy

  • 0

I have a set of classes that manage db storage in a class hierarchy as outlined below, and would like for the case class to be able to access the protected methods in the companion object’s parent class:

class TableBase[T] { 
  protected def insert(...):T {...}
  protected def update(...) {...}
  // Other "raw" CRUD-methods that I don't want the 
  // world to have access to
}

object User extends TableBase[User] { 
}

case class User(id:Int, email:String) { 
  // But here it would be really useful to access the "raw" CRUD methods:
  def changeEmail(newEmail:String) = User.update(...)
}

Only problem is that the call to User.update in User.changeEmail is illegal since User (class) is not in the inheritance chain from TableBase:

method update in class TableBase cannot be accessed in object models.User 
Access to protected method update not permitted because enclosing class 
class User in package models is not a subclass of class TableBase in package 
models where target is defined

Is there a (convenient) way to allow for this type of calling?

Right now I have to either move the changeEmail-type functions into the singleton, which makes the calling code rather verbose, or duplicate the method signatures.

  • 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-10T21:21:14+00:00Added an answer on June 10, 2026 at 9:21 pm

    I just realized that a possible solution is to switch the “is-a” to a “has-a” relationship between User and TableBase, like so:

    class TableBase[T] { 
      def insert(...):T {...}
      def update(...) {...}
    }
    
    object User { 
      private val db = new TableBase[User]
    }
    
    case class User(id:Int, email:String) { 
      def changeEmail(newEmail:String) = User.db.update(...)
    }
    

    I wanted to be able to customize some aspects of TableBase inside User, but that’s actually still possible and quite easy by doing:

    object User { 
      private val db = new TableBase[User] { 
        // Override stuff here
      }
    }
    

    Actually, that’s a much better solution than what I originally had and avoids naming conflicts on the methods (i.e. there’s reason to have a public “insert” on User and it’s nice to not have it result in partly protected overloading).

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

Sidebar

Related Questions

Present Scenario : I have a set of classes that all take a common
I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated
I have a project with a set of classes that are responsible for their
I have written a set of classes and interfaces that are implemented in Moose
I have two classes set up as follows: class Point { protected: double coords[3];
I have classes which have automatic properties only like public customerName {get; set;}. They
I have two classes: public class MultilingualString { public int Id { get; set;
I have set of classes which inherit from a single super class: Super |
I have an abstract class Employee and 2 other classes that extend it (Developer
I have a requirement where in i have a set of classes and they

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.