- Scala multi-inheritance, constructor execution order, AOP implementation
- Trait implementations of multiple inheritance: Scala interfaces can inherit specific classes, trait interfaces can implement multiple inheritance, and a class can inherit a particular class, which can be mixed in after inheritance, the implementation of an interface
- Multi-inheritance constructor execution order: The execution order of the multi-inheritance constructor is performed sequentially from left to right, and if the preceding class and inherited implementations are implemented, the following classes do not need to be implemented, and the parent class simply executes the
Object Triatscala {def main (args:array[string]): Unit={val T1=Newpianoteacher T1.playpiano T1.teach}}//Public parent Classclasshuman{println ("Human")}//inherit the interface of the parent classTrait TteacherextendsHuman {println ("Tteacher") def teach}//inherits the interface of the parent class and has its own methodTrait PianoplayerextendsHuman {println ("Pianoplayer") def Playpiano= {println ("I ' m playing piano."))} } //inherits the class of the parent class and mixes in two interfaces implements the method implementation of the interface in the order that is left to rightclassPianoteacherextendsHuman with Tteacher with Pianoplayer {override def teach= {println ("I ' m training students."))} }
-
- AOP code implementation based on trait: the interface is inherited by another interface and also invokes the parent class abstract method when implementing the parent class method, in another class is the method of implementing the common interface, so that AOP can be implemented (aspect-oriented programming)
//AOP-oriented tangent programmingtrait Action {def doAction}trait tbeforeafterextendsAction {//using an abstract method to override the parent class's interface implementation requires a method of making the parent class, which is implemented in a specific class Abstractoverride def doAction {println ("Initialization") Super. DoAction println ("Destroyed") } }classWorkextendsaction{//Implement the parent class method specificallyOverride Def doAction = println ("Working ...")}object Triatscala {def main (args:array[string]): Unit={val work=NewWork with Tbeforeafter work.doaction}}
- package Definition and implicit reference implementation of package object, package reference, package
- about access permissions for packages, classes, objects, members, associated classes, and associated objects in Scala
- Read and write files in Scala, console input operations
- Read-write implementation of the file: Read the file with the FromFile method in the source object to read the text data can also be used fromurl follow the URL to read, and write with PrintWriter to achieve
- Console operation implementation: Console.ReadLine to implement console operation, console this in Scala's implicit package, you can directly use
Learning here today .....
Baidu Video Address: http://pan.baidu.com/s/1ntzOmDz
Big Data series cultivation-scala course