Aşağıdaki örnekte, grails mail eklentisi tarafından sağlanan sendMail yönteminin kullanılması this book'da görünür.groovy closure parameters
sendMail {
to "[email protected]"
subject "Registration Complete"
body view:"/foo/bar", model:[user:new User()]
}
{} içindeki kodun, sendMail'e bir parametre olarak iletilen bir kapatma olduğunu anlıyorum. Ayrıca, to
, subject
ve body
'un yöntem çağrıları olduğunu anlıyorum.
Sendmaili yöntemini uygulayan kod nasıl görüneceğini anlamaya çalışıyorum ve en iyi tahmin böyle bir şeydir:
MailService {
String subject
String recipient
String view
def model
sendMail(closure) {
closure.call()
// Code to send the mail now that all the
// various properties have been set
}
to(recipient) {
this.recipient = recipient
}
subject(subject) {
this.subject = subject;
}
body(view, model) {
this.view = view
this.model = model
}
}
bu makul mi, yoksa bir şey eksik? Özel olarak, kapıda (to
, subject
, body
) başvurulan yöntemler, zorunlu olarak aynı sınıfın üyeleri olan sendMail
?
sayesinde Don