3, hands on the abstract class in Scala
The definition of an abstract class requires the use of the abstract keyword:
The above code defines and implements the abstract method, it is important to note that we put the direct running code in the trait subclass of the app, about the inside of the app helps us implement the Main method and manages the code written by the engineer;
Here's a look at the use of uninitialized variables in an abstract class:
4, hands-on trait in Scala
Trait is similar to the interface in Java 8 that can have the default method.
trait can be implemented in a method, or with an abstract method, using trait is mixed with the class.
let's look at an example of trait:
Note that we use the use of trait here is extends, because Concretelogger does not inherit other classes or trait's sake;
the child trait can override the method that implements the parent trait:
If the trait is used, the override keyword is required if the method already implemented in the parent trait is overwrite:
Here's a look at mixing trait in the object:
Spark Asia-Pacific Research series, spark Combat Master Road-2nd Chapter hands-on Scala 2nd bar: Hands on Scala object-oriented programming (2)