Using Scala to implement a domain level spanning a range of Java services

We have a java system that is implemented in several layers. At the lowest level, there are services that abstract a number of infrastructure components, such as a database, blob-storage, processing queues, etc. In addition, we have a domain level that implements workflows that use one or more of these services (using command and compound command templates). Finally, there is a layer based on jax-rs (jersey) that provides a REST interface / protocol implemented in terms of workflows from the domain level.

My experience with Scala is limited, but I suspect it might be a good tool for writing a more expressive version of our domain, because Java code is pretty verbose and difficult to debug from time to time. Partly because the management of composition and execution of commands is handled by base classes that are extended by specific commands. Looking back, this may not have been an ideal design choice.

I hope this very high level description serves to illustrate what I am trying to achieve. Let me know if I need to clarify. What interests me most is how to build a domain level using Scala, while maintaining the level of service based on Java. In addition, suggestions on how to implement the http / REST protocol over a domain so that it can be deployed in a java web application container are very interesting.

+5
source share
1 answer

A tactically obvious starting point is to use Scala's structural typing and view your team's views as signs:

trait CommandType1 { def operation() }

Then you can create your own team compositions from these attributes:

case class CompositeCommand(commandOperand: CommandType1*) extends CommandType1 {
  def operation() = commandOperand foreach { _.operation() }
}

Scala , Java - , . , , / .

Scala , . , , - Scala Cake Pattern, DI - .

+1

All Articles