DataManager用于处理聊天室的关联数据。MetadataListener接口被定义成任意类型的Map对像,这非常有利于扩展:
public interface MetadataListener {
void metadataAssociatedWithRoom(ChatRoom room, Map<?, ?> metadata);
}
该类只有3个方法,非常简洁
public void addMetadataListener(MetadataListener listener) { metadataListeners.add(listener); } public void removeMetadataListener(MetadataListener listener) { metadataListeners.remove(listener); } public void setMetadataForRoom(ChatRoom room, Map<?, ?> map) { for (MetadataListener listener : metadataListeners) { listener.metadataAssociatedWithRoom(room, map);