D Paste by naryl
Description: Transitivity is bad sometimes
Hide line numbers

Create new paste
Post a reply
View replies

Paste:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  

module main;

class SystemShutdownNotifier {

    Subscriber[] subscribers;

    void addSubscriber(Subscriber subscriber) {
        subscribers ~= subscriber;
    }
}

interface Message {
}

class MsgShutdownNotifierStarted: Message {
    public:
        this(SystemShutdownNotifier notifier) {
            this.notifier = notifier;
        }

        SystemShutdownNotifier notifier;
        invariant int type = 1;
}

class Subscriber {
    public:
        void onShutdownNotifierStarted(const (MsgShutdownNotifierStarted) cmd) {
            cmd.notifier.addSubscriber(this);
        }
}

void main() {
    auto subscriber = new Subscriber();

    auto notifier = new SystemShutdownNotifier();

    invariant message = cast(invariant) (new MsgShutdownNotifierStarted(notifier));

    subscriber.onShutdownNotifierStarted(message);
}

Replies:
No replies posted yet