Strategy pattern in Akka

后端 未结 2 1021
庸人自扰
庸人自扰 2021-01-05 14:57

This is an continuation of my previous question How do I get around type erasure on Akka receive method

I have 10 type of events which extends from Event that I need

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 15:32

    case class EventOperation[T <: Event](eventType: T)
    
    class OperationActor extends Actor {
    
      def receive = {
        case EventOperation(eventType) => eventType.execute
      }
    
    }
    
    trait Event {
     def execute //implement execute in specific event class
    }
    
    class Event1 extends Event {/*execute implemented with business logic*/}
    class Event2 extends Event {/*execute implemented with business logic*/}
    

    hope this is what you are looking for and helps, I have used this patternt to remove the redundant amount of actors wrapping all actions under a single actor executing different type of events.

提交回复
热议问题