Inheritance from object Application, how do I make something similar to that?

Alan Coromano

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?

Alexey Romanov

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] { 
  ... 
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do i make my jar file execute like a regular application from Terminal

분류에서Dev

How can I do an array of object of my class (with inheritance of another custom class)?

분류에서Dev

How to make a function do something when the enter key is pressed

분류에서Dev

How do I make Chromium use Flash from Google Chrome?

분류에서Dev

How would I make a value in a mysql table echo as something else?

분류에서Dev

How do I return an object from another model in a scope?

분류에서Dev

how do I make an android service that runs when the application doesn't?

분류에서Dev

How do I make my iOS application resize correctly to all iphone devices?

분류에서Dev

How do I get this result with excel, notepad++ or something else?

분류에서Dev

How do I use sections with three levels of inheritance

분류에서Dev

How do I get MultiAutoCompleteTextView tokenizer similar to Facebook app?

분류에서Dev

How do I edit an xmlTV file using sed (or a similar tool)?

분류에서Dev

How do i make an array which is a class object and has a compile time size?

분류에서Dev

How can I remove something from the middle of a string with regex?

분류에서Dev

How do I access an object's keys' values? Looking to populate a table from object data

분류에서Dev

How can i make shared pointer from a class object with move semantics

분류에서Dev

How do I make a dictionary of OD pairs from a distance Matrix using python?

분류에서Dev

How do I make files copied over the network from my Windows computer be owned by me?

분류에서Dev

.NET C# Console Application How do I get more detailed exception information from a production environment

분류에서Dev

How do I make variable in for loop bigger that in was

분류에서Dev

How do I make a "for" loop for this sequence of arrays?

분류에서Dev

How do I make a decorator typesafe in TypeScript?

분류에서Dev

How do I make a Range reverse on condition?

분류에서Dev

How do I make a border padding for a UITextField?

분류에서Dev

How do I make use of rotation matrices?

분류에서Dev

How do I make a table of indexes

분류에서Dev

How Do I Make A Rectangle in GEOS?

분류에서Dev

How do I make stdin a tty?

분류에서Dev

how do i make my code shorter

Related 관련 기사

  1. 1

    How do i make my jar file execute like a regular application from Terminal

  2. 2

    How can I do an array of object of my class (with inheritance of another custom class)?

  3. 3

    How to make a function do something when the enter key is pressed

  4. 4

    How do I make Chromium use Flash from Google Chrome?

  5. 5

    How would I make a value in a mysql table echo as something else?

  6. 6

    How do I return an object from another model in a scope?

  7. 7

    how do I make an android service that runs when the application doesn't?

  8. 8

    How do I make my iOS application resize correctly to all iphone devices?

  9. 9

    How do I get this result with excel, notepad++ or something else?

  10. 10

    How do I use sections with three levels of inheritance

  11. 11

    How do I get MultiAutoCompleteTextView tokenizer similar to Facebook app?

  12. 12

    How do I edit an xmlTV file using sed (or a similar tool)?

  13. 13

    How do i make an array which is a class object and has a compile time size?

  14. 14

    How can I remove something from the middle of a string with regex?

  15. 15

    How do I access an object's keys' values? Looking to populate a table from object data

  16. 16

    How can i make shared pointer from a class object with move semantics

  17. 17

    How do I make a dictionary of OD pairs from a distance Matrix using python?

  18. 18

    How do I make files copied over the network from my Windows computer be owned by me?

  19. 19

    .NET C# Console Application How do I get more detailed exception information from a production environment

  20. 20

    How do I make variable in for loop bigger that in was

  21. 21

    How do I make a "for" loop for this sequence of arrays?

  22. 22

    How do I make a decorator typesafe in TypeScript?

  23. 23

    How do I make a Range reverse on condition?

  24. 24

    How do I make a border padding for a UITextField?

  25. 25

    How do I make use of rotation matrices?

  26. 26

    How do I make a table of indexes

  27. 27

    How Do I Make A Rectangle in GEOS?

  28. 28

    How do I make stdin a tty?

  29. 29

    how do i make my code shorter

뜨겁다태그

보관