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?
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] 삭제
몇 마디 만하겠습니다