Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在查看 ROR 中的一些最佳实践,我注意到回调方法是在受保护部分而不是私有部分中声明的。在声明回调方法时,我总是使用 private,所以我想知道使用 protected 是否更好,为什么。这个实现有什么实质性的区别吗?
private- 只能在定义它们的类中访问。
private
protected- 在定义它们的类和从该类继承的其他类中可访问。
protected