質問編集履歴

14

2020/10/06 10:28

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -162,7 +162,7 @@
162
162
 
163
163
  確かに下記のようにClientクラスを書き換えると、
164
164
 
165
- ada.set_contact_point(bob.get_secretary())実行前にNoneだったcontact_pointはbob.get_secretary=Secretaryに置き換わっていることを確認しました。
165
+ adam .set_contact_point(bob.get_secretary())実行前にNoneだったcontact_pointはbob.get_secretary=Secretaryに置き換わっていることを確認しました。
166
166
 
167
167
 
168
168
 
@@ -214,6 +214,8 @@
214
214
 
215
215
  #<__main__.Secretary object at 0x007E7030>
216
216
 
217
+
218
+
217
219
  ```
218
220
 
219
221
 

13

2020/10/06 10:28

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -214,12 +214,6 @@
214
214
 
215
215
  #<__main__.Secretary object at 0x007E7030>
216
216
 
217
-
218
-
219
- adam.make_appointment('10:30')
220
-
221
- #adam could book? : True
222
-
223
217
  ```
224
218
 
225
219
 

12

2020/10/06 10:25

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -190,8 +190,6 @@
190
190
 
191
191
  if (self.contact_point):
192
192
 
193
-
194
-
195
193
  is_success = self.contact_point.request_appointment(when, self.name)
196
194
 
197
195
  print(self.name + " could book? : " + str(is_success))
@@ -204,15 +202,15 @@
204
202
 
205
203
  bob = Manager()
206
204
 
207
- ada = Client('ada')
205
+ adam = Client('ada')
208
-
206
+
209
- ada.make_appointment('10:30')
207
+ adam.make_appointment('10:30')
210
208
 
211
209
  #None
212
210
 
213
211
 
214
212
 
215
- ada.set_contact_point(bob.get_secretary())
213
+ adam.set_contact_point(bob.get_secretary())
216
214
 
217
215
  #<__main__.Secretary object at 0x007E7030>
218
216
 

11

2020/10/06 10:23

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -184,7 +184,7 @@
184
184
 
185
185
  self.contact_point = contact_point
186
186
 
187
- print(self.contact_point)
187
+ print(self.contact_point) #追記
188
188
 
189
189
  def make_appointment(self, when):
190
190
 
@@ -198,7 +198,7 @@
198
198
 
199
199
  else:
200
200
 
201
- print(self.contact_point)
201
+ print(self.contact_point) #追記
202
202
 
203
203
 
204
204
 

10

2020/10/06 10:20

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -138,7 +138,7 @@
138
138
 
139
139
 
140
140
 
141
- 「is_success = self.contact_point.request_appointment(when, self.name)」という機能によってでインスタンス作成時のnameを「who」として橋渡ししているのかな、と考えてます。そしてそれを実装するために、「self.contact_point」という受け皿を作り、「set_contact_point」という関数まで作っているのかと考えています。しかしこの「set_contact_point」関数に至っては、「オレの物はオレの物」と言っているようにしか聞こえず、何の意味があるのかわかりません。一体この随所に出てくる「contact_point」はどのような機能をはたしているのでしょう。
141
+ 「is_success = self.contact_point.request_appointment(when, self.name)」という機能によってでインスタンス作成時のnameを「who」として橋渡ししているのかな、と考えてます。そしてそれを実装するために、「self.contact_point」という受け皿を作り、「set_contact_point」というメソッドまで作っているのかと考えています。しかしこの「set_contact_point」メソッドに至っては、「オレの物はオレの物」と言っているようにしか聞こえず、何の意味があるのかわかりません。一体この随所に出てくる「contact_point」はどのような機能をはたしているのでしょう。
142
142
 
143
143
 
144
144
 

9

2020/10/06 10:16

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
File without changes

8

2020/10/06 10:14

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -216,9 +216,11 @@
216
216
 
217
217
  #<__main__.Secretary object at 0x007E7030>
218
218
 
219
+
220
+
221
+ adam.make_appointment('10:30')
222
+
219
- ada could book? : False
223
+ #adam could book? : True
220
-
221
-
222
224
 
223
225
  ```
224
226
 

7

2020/10/06 10:14

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -160,9 +160,9 @@
160
160
 
161
161
  toast-uzさんの返答により、ほぼ理解して自分で書けるようになりました。
162
162
 
163
- 確かに下記のように書き換えると、
163
+ 確かに下記のようにClientクラスを書き換えると、
164
-
164
+
165
- ada.set_contact_point(bob.get_secretary())実行前にNoneだったものが、実行後、contact_pointはbob.get_secretary=Secretaryに置き換わっていることを確認しました。
165
+ ada.set_contact_point(bob.get_secretary())実行前にNoneだったcontact_pointはbob.get_secretary=Secretaryに置き換わっていることを確認しました。
166
166
 
167
167
 
168
168
 
@@ -224,7 +224,7 @@
224
224
 
225
225
 
226
226
 
227
- しかしすみません、あと1点だけ不明点残りました。
227
+ しかしすみません、あと1点だけ理解届きせんでした。
228
228
 
229
229
 
230
230
 

6

2020/10/06 10:11

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
File without changes

5

2020/10/06 10:05

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -156,9 +156,13 @@
156
156
 
157
157
  ### 追記
158
158
 
159
+
160
+
161
+ toast-uzさんの返答により、ほぼ理解して自分で書けるようになりました。
162
+
159
- ###
163
+ 確かに下記のように書き換えると、
164
+
160
-
165
+ ada.set_contact_point(bob.get_secretary())実行前にNoneだったものが、実行後、contact_pointはbob.get_secretary=Secretaryに置き換わっていることを確認しました。
161
-
162
166
 
163
167
 
164
168
 
@@ -217,3 +221,27 @@
217
221
 
218
222
 
219
223
  ```
224
+
225
+
226
+
227
+ しかしすみません、あと1点だけ不明点が残りました。
228
+
229
+
230
+
231
+ is_success = self.contact_point.request_appointment(when, self.name)
232
+
233
+
234
+
235
+ 部分なのですが、これはis_successという変数を作成してここに秘書のメソッドを代入しているだけのように思えます。
236
+
237
+
238
+
239
+ ところがこの文章だけで
240
+
241
+ self.contact_point.request_appointment(when, self.name)の実行まで行われています。
242
+
243
+ is_success = self.contact_point.request_appointment(when, self.name)
244
+
245
+ is_success
246
+
247
+ というように実行文が必要のように思うのですが、これはどういった機能で実現できているのでしょうか?

4

2020/10/06 10:05

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -154,6 +154,66 @@
154
154
 
155
155
  ###
156
156
 
157
+ ### 追記
158
+
157
159
  ###
158
160
 
161
+
162
+
163
+
164
+
165
+ ```Python
166
+
167
+
168
+
169
+
170
+
171
+ class Client:
172
+
173
+ def __init__(self, name):
174
+
175
+ self.name = name
176
+
177
+ self.contact_point = None
178
+
179
+ def set_contact_point(self, contact_point):
180
+
181
+ self.contact_point = contact_point
182
+
183
+ print(self.contact_point)
184
+
185
+ def make_appointment(self, when):
186
+
187
+ if (self.contact_point):
188
+
189
+
190
+
191
+ is_success = self.contact_point.request_appointment(when, self.name)
192
+
193
+ print(self.name + " could book? : " + str(is_success))
194
+
195
+ else:
196
+
197
+ print(self.contact_point)
198
+
199
+
200
+
201
+ bob = Manager()
202
+
203
+ ada = Client('ada')
204
+
205
+ ada.make_appointment('10:30')
206
+
207
+ #None
208
+
209
+
210
+
211
+ ada.set_contact_point(bob.get_secretary())
212
+
213
+ #<__main__.Secretary object at 0x007E7030>
214
+
215
+ ada could book? : False
216
+
217
+
218
+
159
- 追記
219
+ ```

3

2020/10/06 09:47

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
File without changes

2

2020/10/06 09:40

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -149,3 +149,11 @@
149
149
 
150
150
 
151
151
  以上、2点についてご教授お願いできますでしょうか。
152
+
153
+
154
+
155
+ ###
156
+
157
+ ###
158
+
159
+ 追記

1

2020/10/06 09:40

投稿

happyriver
happyriver

スコア5

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- ### **クラス間でのメソッド引数の受渡し**
1
+ ### **前提**
2
2
 
3
3
 
4
4
 
@@ -11,46 +11,6 @@
11
11
  また、ManagerクラスにはSecretaryクラスを利用して、何時に誰の予約か入っているかを一覧で出す機能もあります。
12
12
 
13
13
  これをそのまま実行するとちゃんと動作します。しかしなぜ、どのような仕組みで動作しているのかがわからないため、質問させていただきました。
14
-
15
-
16
-
17
- ### 質問①
18
-
19
- 不明点① まず、Clientの中の動作についてです。
20
-
21
- ・「Secretary」クラスの「request_appointment」メソツドでは、whenとwhoの2つの引数を指定しています。
22
-
23
- ・一方「Client」クラスの「make_appointment」メソッドでは、引数に「when」しか指定しておらず、「who」部分は指定されていません。
24
-
25
-
26
-
27
- にも関わらず、実行結果を見てみると、adam.make_appointment('10:30')と、「when」情報のみで予約が取れています。
28
-
29
- なぜこのようなことが(adamという名前を与えずに)予約が取れるのかが知りたいです。
30
-
31
-
32
-
33
- ### **考察**
34
-
35
- 恐らく、これを実現させているのが「contact_point」にあるのかと推察しています。
36
-
37
-
38
-
39
- 「is_success = self.contact_point.request_appointment(when, self.name)」という機能によってでインスタンス作成時のnameを「who」として橋渡ししているのかな、と考えてます。そしてそれを実装するために、「self.contact_point」という受け皿を作り、「set_contact_point」という関数まで作っているのかと考えています。しかしこの「set_contact_point」関数に至っては、「オレの物はオレの物」と言っているようにしか聞こえず、何の意味があるのかわかりません。一体この随所に出てくる「contact_point」はどのような機能をはたしているのでしょう。
40
-
41
-
42
-
43
- ### 質問②
44
-
45
- 不明点② 次に、contact_pointが何なのかがわからないため、インスタンス作成後の「ada.set_contact_point(bob.get_secretary())」で何をしているのか、不明です。また、Managerクラスにある「get_secretary」も何の役割があるのかがわかりません。
46
-
47
-
48
-
49
- 以上、2点についてご教授お願いできますでしょうか。
50
-
51
-
52
-
53
-
54
14
 
55
15
 
56
16
 
@@ -153,3 +113,39 @@
153
113
 
154
114
 
155
115
  ```
116
+
117
+
118
+
119
+ ### 質問①
120
+
121
+ 不明点① まず、Clientの中の動作についてです。
122
+
123
+ ・「Secretary」クラスの「request_appointment」メソツドでは、whenとwhoの2つの引数を指定しています。
124
+
125
+ ・一方「Client」クラスの「make_appointment」メソッドでは、引数に「when」しか指定しておらず、「who」部分は指定されていません。
126
+
127
+
128
+
129
+ にも関わらず、実行結果を見てみると、adam.make_appointment('10:30')と、「when」情報のみで予約が取れています。
130
+
131
+ なぜこのようなことが(adamという名前を与えずに)予約が取れるのかが知りたいです。
132
+
133
+
134
+
135
+ ### **考察**
136
+
137
+ 恐らく、これを実現させているのが「contact_point」にあるのかと推察しています。
138
+
139
+
140
+
141
+ 「is_success = self.contact_point.request_appointment(when, self.name)」という機能によってでインスタンス作成時のnameを「who」として橋渡ししているのかな、と考えてます。そしてそれを実装するために、「self.contact_point」という受け皿を作り、「set_contact_point」という関数まで作っているのかと考えています。しかしこの「set_contact_point」関数に至っては、「オレの物はオレの物」と言っているようにしか聞こえず、何の意味があるのかわかりません。一体この随所に出てくる「contact_point」はどのような機能をはたしているのでしょう。
142
+
143
+
144
+
145
+ ### 質問②
146
+
147
+ 不明点② 次に、contact_pointが何なのかがわからないため、インスタンス作成後の「ada.set_contact_point(bob.get_secretary())」で何をしているのか、不明です。また、Managerクラスにある「get_secretary」も何の役割があるのかがわかりません。
148
+
149
+
150
+
151
+ 以上、2点についてご教授お願いできますでしょうか。