Event driven architecture refactored.
1. Renamed Message to Event and Event to AbstractEvent 2. Generified Event and Handler 3. Updated EventDispatcher to make unsafe configuration impossible 4. Updated UML diagram accordingly
This commit is contained in:
@@ -23,10 +23,10 @@
|
||||
package com.iluwatar.eda.event;
|
||||
|
||||
import com.iluwatar.eda.framework.EventDispatcher;
|
||||
import com.iluwatar.eda.framework.Message;
|
||||
import com.iluwatar.eda.framework.Event;
|
||||
|
||||
/**
|
||||
* The {@link Event} class serves as a base class for defining custom events happening with your
|
||||
* The {@link AbstractEvent} class serves as a base class for defining custom events happening with your
|
||||
* system. In this example we have two types of events defined.
|
||||
* <ul>
|
||||
* <li>{@link UserCreatedEvent} - used when a user is created</li>
|
||||
@@ -34,16 +34,16 @@ import com.iluwatar.eda.framework.Message;
|
||||
* </ul>
|
||||
* Events can be distinguished using the {@link #getType() getType} method.
|
||||
*/
|
||||
public class Event implements Message {
|
||||
public abstract class AbstractEvent implements Event {
|
||||
|
||||
/**
|
||||
* Returns the event type as a {@link Class} object
|
||||
* In this example, this method is used by the {@link EventDispatcher} to
|
||||
* dispatch events depending on their type.
|
||||
*
|
||||
* @return the Event type as a {@link Class}.
|
||||
* @return the AbstractEvent type as a {@link Class}.
|
||||
*/
|
||||
public Class<? extends Message> getType() {
|
||||
public Class<? extends Event> getType() {
|
||||
return getClass();
|
||||
}
|
||||
}
|
@@ -29,7 +29,7 @@ import com.iluwatar.eda.model.User;
|
||||
* This class can be extended to contain details about the user has been created. In this example,
|
||||
* the entire {@link User} object is passed on as data with the event.
|
||||
*/
|
||||
public class UserCreatedEvent extends Event {
|
||||
public class UserCreatedEvent extends AbstractEvent {
|
||||
|
||||
private User user;
|
||||
|
||||
|
@@ -29,7 +29,7 @@ import com.iluwatar.eda.model.User;
|
||||
* This class can be extended to contain details about the user has been updated. In this example,
|
||||
* the entire {@link User} object is passed on as data with the event.
|
||||
*/
|
||||
public class UserUpdatedEvent extends Event {
|
||||
public class UserUpdatedEvent extends AbstractEvent {
|
||||
|
||||
private User user;
|
||||
|
||||
|
Reference in New Issue
Block a user