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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:28:52+00:00 2026-05-18T23:28:52+00:00

I have a set of decorator-traits (for simplicity here only trait T ) mixing

  • 0

I have a set of decorator-traits (for simplicity here only trait T) mixing in classes (here subclasses of A).

trait T { def i: Int }
abstract class A
type AT = A with T
class B extends A
// class C extends A
// class D extends A
// ...


Now I have an instance a of e.g. class B which I handle as an instance of type AT (together with other A-subclass-AT-instances in a Seq[AT]).

val a: AT = new B with T { val i = 8 }


How can I generically decorate like this:

def toAT(a: A, i: Int): AT = {
 // how to ???
}


An obvious solution I thought about is:

trait T { def i: Int }
abstract class A {
  def asAT(i: Int): AT
}
class B extends A {
  def asAT(ii: Int): AT = new B with T { val i = ii }
}
type AT = A with T
def toAT(a: A, i: Int): AT = a.asAT(i)


But I don´t want to pollute my classes B, C, ..., Z with a new method and there are other decorations, so for every decoration-combo I need a new method for all subclasses!
Is there a more generic way?

EDIT:
An example why I need the toAT method, but still with the obvious solution approach from above in terms of a redecorated method:

trait T { def b: Boolean}
type AT = A with T
abstract class A(val i: Int) {
  def changedBy(x: Int): A
  def redecorated(oldAT: AT): AT
}
class B(x: Int) extends A(x) {
  def changedBy(x: Int): A = new B(i * x) 
  def redecorated(oldAT: AT): AT = new B(i) with T { val b = oldAT.b }
}
class C(x: Int) extends A(x) {
  def changedBy(x: Int): A = new C(i * x * x) 
  def redecorated(oldAT: AT): AT = new C(i) with T { val b = oldAT.b }
}
val b = new B(1) with T { val b = true  }
val c = new C(1) with T { val b = false }
val x = 8
val res: Seq[AT] = Seq(b,c) map { at => at.changedBy(x).redecorated(at) }

  • 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-18T23:28:53+00:00Added an answer on May 18, 2026 at 11:28 pm

    Basically, you can’t do it.

    One alternative is to use the auto proxy plugin, by Kevin Wright. See also here and here for more information about it.

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

Sidebar

Related Questions

I have a class holding complex scientific computations. It is set up to only
We have a set of about two dozen classes that inherit from a base
I have a decorator like this: def region_required(view_func): def new_view(request, ctx = {}, *args,
I have some questions regarding the following code: 1 class Test(object): 2 def __init__(self):
I have the following decorator inside a module: class CachedProperty(object): Decorator that lazy-loads the
I have a class, called Sprite: public abstract class Sprite { protected Texture2D Image
I have set the form decorators in this way: <?php $this->setElementDecorators(array( 'Label', array(array('labelTd' =>
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set a background on the data-role=page element like so <div data-role=page style=background:
I have set up Eclipse Indigo to do line debugging with CFEclipse over port

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.