-
Notifications
You must be signed in to change notification settings - Fork 1
/
Interface.class.st
47 lines (35 loc) · 1.16 KB
/
Interface.class.st
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
43
44
45
46
47
"
I'm an interface declaring a set of messages to be understood by the objects implementing me.
I'm not intended to be used as some kind of static type check, but to document an expected protocol.
"
Class {
#name : #Interface,
#superclass : #Object,
#instVars : [
'name',
'messages'
],
#category : #'Buoy-Metaprogramming'
}
{ #category : #'instance creation' }
Interface class >> named: aName declaring: aSelectorCollection [
AssertionChecker refuse: [ aSelectorCollection isEmpty ] because: 'An interface must declare at least one message.' raising: InstanceCreationFailed.
^ self new initializeNamed: aName declaring: aSelectorCollection
]
{ #category : #initialization }
Interface >> initializeNamed: aName declaring: aSelectorCollection [
name := aName.
messages := aSelectorCollection
]
{ #category : #testing }
Interface >> isImplementedBy: anObject [
^ messages allSatisfy: [ :message | anObject respondsTo: message ]
]
{ #category : #testing }
Interface >> isImplementedByInstancesOf: aClass [
^ messages allSatisfy: [ :message | aClass canUnderstand: message ]
]
{ #category : #printing }
Interface >> printOn: aStream [
aStream nextPutAll: name
]