如果这些类中的任何一个的子类需要覆盖默认行为,那么可以通过覆盖这个方法实现。
If a subclass of one of these classes needed to override the default behavior, it could do so by overriding the method.
实现层次结构在Scala中的效果是相同的:我们可以向方法应用final来防止子类覆盖它,也可应用于类声明本身来防止继承。
Implementation hierarchy works the same way in Scala: We can apply final to the method to prevent a child class from overriding it or to the class declaration itself to prevent derivatives.
TemplateMethod模式定义了基类算法的骨架,使用了抽象方法和覆盖将具体细节放到子类中。
The Template Method pattern defines the skeleton of an algorithm in a base class, using abstract methods and overriding to defer individual details to child classes.
此类的子类将覆盖load方法把数据添加到items表中。
Descendants of this class override the load method to add data to the items table.
假设你要调用洗牌的方法shuffle,你可能用的是deck类当中的,不过如果子类当中有覆盖的该方法,你运行的就是子类中的方法了。
If you invoke a method like shuffle, you might get the one defined in Deck, but if any of the subclasses override this method, you'll get that version instead.
你还可以覆盖一个方法,在这个方法中返回原始方法所声明的返回对象的子类。
You can also override a method with the same signature that returns a subclass of the object returned by the original method.
你还可以覆盖一个方法,在这个方法中返回原始方法所声明的返回对象的子类。
You can also override a method with the same signature that returns a subclass of the object returned by the original method.
应用推荐