0

I have 3 projects included in one project, let's call them project1, 2 and 3 and they are included in main project. The 1 one is a library, whereas the two others are console-executable projects.

For now I have 2 pretty much identical object Application in the projects 2 and 3:

package com.project1

abstract class Class123 extends Actor { ... }
abstract class Class456 { ... }

package com.project2

class Class123  extends package1.Class123 { ... }
class Class456  extends package1.Class456 { ... }

object Application extends App {
  val system = ActorSystem()
  val myActor = system.actorOf(Props[Class123])
  val b = new Class456               
  // some actions
}

package com.project3

class Class123  extends package1.Class123 { ... }
class Class456  extends package1.Class456 { ... }

object Application extends App {
  val system = ActorSystem()
  val myActor = system.actorOf(Props[Class123])
  val b = new Class456            
  // some actions
}

How do I reduce the amount of repetition? I can create object Application in package1, but it should be generic (which Scala doesn't allow to do) and I would have to inherit from it (it's not allowed by Scala either).

What do I do about it?

1
  • Already answered by your previous answerer stackoverflow.com/a/18773054/1296806 or, maybe you weren't aware that a class can extend App (DelayedInit) and your objects can extend that class. Commented Sep 13, 2013 at 6:09

1 Answer 1

1

Make it a class instead of object:

class MyApp[C123, C456] extends App {
  val system = ...
  val myActor = ...
  val b = ...            
}

package com.project1
object Application1 extends MyApp[com.project1.Class123, com.project1.Class456] { 
  ... 
}

package com.project2
object Application2 extends MyApp[com.project2.Class123, com.project2.Class456] { 
  ... 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.