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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:54:11+00:00 2026-05-24T11:54:11+00:00

I have an parent class, and several child classes. What I want is when

  • 0

I have an parent class, and several child classes. What I want is when specific setter methods are called on instances of the child classes, a boolean value for “is synchronized” in the parent class is set to false. It should be possible to create child classes in either a synchronized or an unsynchronized state.

This is what I came up with:

class A(protected var isSync: Boolean) {
}
class B(var value:String, isSync: Boolean) extends A(isSync) {
  override def value_=(value:String): Unit = {
    this.isSync = false
    this.value = value
  }
}

Now, this doesn’t compile for a number of reasons: the assignment of value to this.value is ambiguous; the var annotation already defines value_=; and this.isSync references the local constructor field isSync, instead of the (writable) parent field.

This question on Stack Overflow pointed out that I should use __value (or any name that isn’t value) as a private var in the constructor, and define the setter myself. After some more tinkering, I came up with the following code that compiles and works:

class A(protected var isSync: Boolean) {
}
class B(private var __value: String, private val __isSync: Boolean)
    extends A(__isSync) {
  def value = __value
  def value_=(value: String) = {
    this.isSync  = false
    this.__value = value
  }
}

However, this code feels so rancid that by now I suspect I’m making a (if not more) fundamental mistake. Could anyone please correct me?

Thus the concrete questions are:

  1. Are there (and if, which) fundamental flaws in what I’m trying to implement? For some context: the objects, when changed, can (and probably have to) be synchronized with a server.
  2. What is the right/best way to pass parameters to a class you extend?
  3. What is the right/best way to override the setter generated by var (or generally provide your own setter implementation)?
  • 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-24T11:54:12+00:00Added an answer on May 24, 2026 at 11:54 am

    About question 1: I guess that you want to track whether the object has been changed since last time it was copied to the server, don’t you? That’s sensible, as long as the copy on the server cannot be modified: otherwise ensuring consistency of the replica is more complex (replica consistency is the keyword for googling, but I wouldn’t recommend it).
    For clarity, I would talking about being clean or dirty – synchronized reminds me too closely of the synchronized Java statement.

    About question 2, you don’t need to make __isSync a private val (which will be stored in the class), you can leave it as a constructor parameter. As long as it is not used (other than in the invocation of A’s constructor) __isSync should not take additional space in instances of B. I removed the private val annotation there, obtaining this code which compiles correctly as expected.

    class A(protected var isSync: Boolean) {
    }
    class B(private var __value: String, __isSync: Boolean)
        extends A(__isSync) {
      def value = __value
      def value_=(value: String) = {
        this.isSync  = false
        this.__value = value
      }
    }
    

    About aesthetics and question 3: I would simply avoid the double underscore. Similar examples from Programming in Scala (Sec 18.2) simply use shorter names. They also use private[this] to prevent access to the member from other instances of the same class. Finally, you can remove {} after the class decl. in this example (even if maybe not in your code).

    Thus we’d get code like this, which is close to the examples I already mentioned:

    class A(protected var isSync: Boolean)
    class B(private[this] var v: String, sync: Boolean)
        extends A(sync) {
      def value = v
      def value_=(value: String) = {
        isSync  = false
        v = value
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Django, when you have a parent class and multiple child classes that inherit
I have a MustInherit Parent class with two Child classes which Inherit from the
Background: I have enclosed (parent) class E with nested class N with several instances
I have a parent class which contains a child object. I am using set
I have a parent class and child class (inherited from parent). In the child
I have a Parent/Child object/mapping as follows: class Parent { int Id; string name;
New to FluentNHibernate =D I have a parent/children classes as follows: public class Parent
I have a parent and child class that both need to implement IDisposable .
I have a Ruby class called LibraryItem . I want to associate with every
I have a parent class with several children. One of the children, has one

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.