一句话:提出用笑脸/哭脸视觉助记法帮助学生记忆 LSP 的前置/后置条件强化与弱化规则。
该论文关注程序设计课程中 Liskov 替换原则(LSP)的教学难点:两门后续课程的学生都难以记住子类型操作的前置条件不能增强、后置条件不能削弱,尤其混淆前置与后置条件中哪一个可以增强或削弱。作者设计了一个简单的视觉助记法:可替换的方法呈“笑脸”,笑脸顶部较宽对应更弱/更宽的前置条件、底部较窄对应更强/更窄的后置条件;不可替换的方法呈“哭脸”,顶部较窄对应更强的前置条件、底部较宽对应更弱的后置条件。虽然该方法远非完美,但作者发现它能帮助学生跨过记忆障碍,进而讨论 LSP 周围更有趣的设计问题。
The Liskov Substitution Principle states, among other constraints, that a subtype is not substitutable for its super type if it strengthens its operations' preconditions, or weakens its operations' postconditions. We found that students in two subsequent courses had trouble remembering these rules. Their major stumbling block appeared to be recalling which condition (pre- or post-) could be strengthened and which could be weakened. We developed a simple visual reminder to help: A method is happy if it is substitutable---A smile is wider at the top than at the bottom, suggesting weaker/looser/wider preconditions, and stronger/tighter/narrower post conditions.; A method is sad if it isn't substitutable---a frown is narrower at the top, suggesting stronger/tighter/narrower preconditions, and wider at the bottom, suggesting weaker/looser/wider postconditions. Though the technique is far from perfect, we found that it allowed students to move on to the more interesting design questions around the LSP.
DOI 原文 ·
@inproceedings{paperbot4555,
title = {Making the liskov substitution principle happy and sad},
author = {Elisa Baniassad},
booktitle = {ICSE},
year = {2018},
doi = {10.1145/3183377.3183392}
}