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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:09:42+00:00 2026-05-29T04:09:42+00:00

Here is something that I have came across in Scala that did not cause

  • 0

Here is something that I have came across in Scala that did not cause any problems in Java. Now I just do not know what is the right way of doing this in Scala.

Problem description: I have a Scala Object which denotes an ‘abstract’ object. It is intended to have a singletonic profile but it is not intended for real use, it is just a bunch of definitions common to it’s children-singletons. So instead, I want to use it’s children. So there comes the question: since I cannot inherit objects, should the common singleton functionality be realized as a class? As an abstract class? Trait does not suit me because it can’t have constructors.
If an abstract parent class would do, then how should I access it’s singleton (or static) methods if I need them anythere?
I realize that there might be a flaw in my design, but since I have this question and can’t think of any definitive answer, it is interesting to hear what you say (including design alternatives).

  • 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-05-29T04:09:42+00:00Added an answer on May 29, 2026 at 4:09 am

    You really should be using a trait; there is no need for constructors (and, indeed, they make no sense because a scala object has no constructor):

    Here’s the shared trait; needA is the value you need to pass to your constructor. That is, it is required by the functionality of the trait.

    trait Common {
      def needA: A
    
      def sharedMethod { /* implement me*/ }
    }
    

    Then your modules look like this:

    object Mod1 extends Common {
      val needA = { /* implement me*/ }
    }     
    object Mod2 extends Common {
      val needA = { /* implement me*/ }
    }     
    

    Notice that they specify the required values for the common functionality by using a val to override a def

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

Sidebar

Related Questions

I just came across something that I have not seen before and I thought
Here's something I've been thinking about: suppose you have a number, x, that can
Basic question here - I have many lines of code that look something like:
i'm missing something fundamental here. i have a very simple custom class that draws
Here's the story... I have a jQuery function that does something, this function is
I came across a situation that I had in another project that I'm not
I recently came across a big problem, as I have a system that's paying
Came across something strange while migrating to my new server. I have a script
Here is something that I find disturbing. I created a small form, and I'm
Here's something that has been bugging me... I am currently creating an application for

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.