---
# System prepended metadata

title: ddd

---

# ddd

```plantuml
@startuml
class Member {
    - String name
    + String getName()
}

class ChatRoomName {
    - String name
    + String getName()
}

class ChatRoom {
    - ChatRoomName name
    - List<Member> members
    - List<SentMessage> messages
    + ChatRoomName getName()
    + List<Member> getMembers()
    + List<SentMessage> getMessages()
    + ChatRoom(ChatRoomName name)
    + void addMember(Member member)
    + void removeMember(Member member)
    + void addSentMessage(SentMessage sentMessage)
}

ChatRoom "one" *-- "one" ChatRoomName
ChatRoom "one" *-- "many" Member
ChatRoom "one" *-- "many" SentMessage


class SentMessage {
    - MessageSentTime sentTime
    + MessageSentTime getSentTime()
    + {static} SentMessage fromMessage(Message message)
}
@endumlg
```


```plantuml
@startuml





class ScheduledMessage {
    - MessageScheduledTime scheduledTime
    + MessageScheduledTime getScheduledTime()

    + void setContent(MessageContent newContent)
    + void setScheduledTime(MessageScheduledTime time)
}

interface SendService {
    + void sendNow(SendNowMessage message)
    + void sendLater(ScheduledMessage message)
}

abstract class SendableMessage {
    + SendResult {abstract} send(SendService scheduler)
}

class SendResult {
    - List<SendResultHandler> handlers
    + void addHandler(SendResultHandler handler)
    + void removeHandler(SendResultHandler handler)
}

interface SendResultHandler {
    + void onSendSuccess(SentMessage sentMessage)
    + void onSendFailure()
}

class SendNowMessage {

}

class SentMessage {
    - MessageSentTime sentTime
    + MessageSentTime getSentTime()
    + {static} SentMessage fromMessage(Message message)
}


ScheduledMessage --|> SendableMessage

SendNowMessage --|> SendableMessage


SendableMessage -- SendResult
SendResult .. SendResultHandler
SendResultHandler .. SentMessage

SendableMessage -- SendService

@endumlg
```

```plantuml
@startuml
class MessageScheduledTime {
    - LocalDateTime scheduledTime
    + LocalDateTime getScheduledTime()
    + MessageScheduledTime(LocalDateTime scheduledTime)
}


class ScheduledMessage {
    - MessageScheduledTime scheduledTime
    + MessageScheduledTime getScheduledTime()

    + void setContent(MessageContent newContent)
    + void setScheduledTime(MessageScheduledTime newScheduledTime)
}
ScheduledMessage *-- MessageScheduledTime



class Scheduler {
    - List<ScheduledMessage> scheduledMessages
    + List<ScheduledMessage> getScheduledMessages()

    + void deleteScheduledMessage(ScheduledMessage message)
    + void setScheduleTime(ScheduledMessage message, MessageScheduledTime newTime)

    + void scheduleMessage(ScheduledMessage message)
}

Scheduler "one" *-- "many" ScheduledMessage
@endumlg
```

↓ドメインモデルズ

```plantuml
@startuml

package "ChatRoom aggregation" {
    object ChatRoom {
        name
        members
        messages
    }
    
    object ChatRoomName {
        name
    }
    
    ChatRoom "1" - "1" ChatRoomName
}

object Member {
    name
}

ChatRoom "0..n" --- "1" Member

package "SentMessage aggregation" {
    object SentMessage {
        content
        sender
        chat room
        sent time
    }
    
    object MessageSentTime {
        time
    }
    
    SentMessage "1" - "1" MessageSentTime
}

package "SendNowMessage aggregation" {
    object SendNowMessage {
        content
        sender
        chat room
    }
}

package "ScheduledMessage aggregation" {
    object ScheduledMessage {
        content
        sender
        chat room
        scheduled time
    }
    
    object MessageScheduledTime {
        time
    }
    
    ScheduledMessage "1" - "1" MessageScheduledTime
}

ChatRoom "0..n" -- "1" SentMessage
ChatRoom "0..n" --- "1" SendNowMessage
ChatRoom "0..n" --- "1" ScheduledMessage

SentMessage "1" --- "1" Member
ScheduledMessage "1" --- "1" Member
SendNowMessage "1" --- "1" Member

object Scheduler {
    scheduled messages
}

Scheduler "0..n" --up- "1" ScheduledMessage
@endumlg
```

ここからFine↓

```plantuml
@startuml
class MessageScheduledTime {
    + LocalDateTime getScheduledTime()
    + MessageScheduledTime(LocalDateTime scheduledTime)
}

class MessageSentTime {
    + LocalDateTime getSentTime()
    + MessageSentTime(LocalDateTime sentTime)
    + {static} MessageSentTime now()
}

class Member {
    + String getName()
}

class ChatRoomName {
    + String getName()
}

class ChatRoom {
    + ChatRoomName getName()
    + List<Member> getMembers()
    + List<SentMessage> getMessages()
    + ChatRoom(ChatRoomName name)
    + void addMember(Member member)
    + void removeMember(Member member)
    ' '+ void addSentMessage(SentMessage sentMessage)
    + SentMessage createSentMessage(Member sender, MessageContent content, MessageSentTime sentTime)
}

ChatRoom "one" *-up- "one" ChatRoomName
ChatRoom "one" *-ri- "many" Member
ChatRoom "one" *-- "many" SentMessage

abstract class Message {
    + MessageContent getContent()
    + Member getSender()
    + ChatRoom getChatRoom()
}

class MessageContent {
    + String getText()
}

class ScheduledMessage {
    + MessageScheduledTime getScheduledTime()

    + void setContent(MessageContent newContent)
    + void setScheduledTime(MessageScheduledTime newScheduledTime)
}

interface SendService {
    + void sendNow(SendNowMessage message)
    + void sendLater(ScheduledMessage message)
}

abstract class SendableMessage {
    + SendResult {abstract} send(SendService scheduler)
}

class SendResult {
    + void addHandler(SendResultHandler handler)
    + void removeHandler(SendResultHandler handler)
}

interface SendResultHandler {
    + void onSendSuccess(SentMessage sentMessage)
    + void onSendFailure()
}

class SendNowMessage {

}

class SentMessage {
    + MessageSentTime getSentTime()
    + {static} SentMessage fromMessage(Message message, MessageSentTime sentTime)
}

Message *- MessageContent
ScheduledMessage -le-|> SendableMessage
SentMessage -d-|> Message
SendableMessage -up-|> Message
SendNowMessage -ri-|> SendableMessage
ScheduledMessage *-d- MessageScheduledTime
SentMessage *- MessageSentTime

SendableMessage ...le. SendResult
SendResult . SendResultHandler
SendResultHandler .. SentMessage

SendableMessage .d. SendService

class Scheduler {
    + List<ScheduledMessage> getScheduledMessages()

    + void deleteScheduledMessage(ScheduledMessage message)
    + void setScheduleTime(ScheduledMessage message, MessageScheduledTime newTime)

    + void scheduleMessage(ScheduledMessage message)
}

Scheduler "one" *-- "many" ScheduledMessage
@endumlg
```

質問ポイント
* Message の種類を細分化しているが、これについてどう思うか
* Chatroomが消えた場合の取り扱い
* リアルタイムに制約
    * 1秒後に設定したときに，実際に送信するときに・・・